68 #define DEBUG_TYPE "twoaddressinstruction" 70 STATISTIC(NumTwoAddressInstrs,
"Number of two-address instructions");
71 STATISTIC(NumCommuted ,
"Number of instructions commuted to coalesce");
72 STATISTIC(NumAggrCommuted ,
"Number of instructions aggressively commuted");
73 STATISTIC(NumConvertedTo3Addr,
"Number of instructions promoted to 3-address");
74 STATISTIC(Num3AddrSunk,
"Number of 3-address instructions sunk");
75 STATISTIC(NumReSchedUps,
"Number of instructions re-scheduled up");
76 STATISTIC(NumReSchedDowns,
"Number of instructions re-scheduled down");
81 cl::desc(
"Coalesce copies by rescheduling (default=true)"),
88 cl::desc(
"Maximum number of dataflow edges to traverse when evaluating " 89 "the benefit of commuting operands"));
130 bool isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
int Maxlen);
132 bool noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
unsigned &LastDef);
134 bool isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
138 unsigned RegBIdx,
unsigned RegCIdx,
unsigned Dist);
140 bool isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB);
144 unsigned RegA,
unsigned RegB,
unsigned Dist);
157 unsigned SrcIdx,
unsigned DstIdx,
158 unsigned Dist,
bool shouldOnlyCommute);
165 void scanUses(
unsigned DstReg);
173 void processTiedPairs(
MachineInstr *
MI, TiedPairList&,
unsigned &Dist);
206 "Two-Address instruction pass",
false,
false)
216 bool TwoAddressInstructionPass::
217 sink3AddrInstruction(
MachineInstr *MI,
unsigned SavedReg,
224 bool SeenStore =
true;
225 if (!MI->isSafeToMove(AA, SeenStore))
234 unsigned MOReg = MO.getReg();
237 if (MO.isUse() && MOReg != SavedReg)
238 UseRegs.
insert(MO.getReg());
247 DefReg = MO.getReg();
255 "Reg should not have empty live interval.");
259 if (I != LI.
end() && I->start < MBBEndIdx)
263 KillMI = LIS->getInstructionFromIndex(I->end);
277 if (!KillMI || KillMI->
getParent() != MBB || KillMI == MI ||
291 unsigned NumVisited = 0;
294 if (OtherMI.isDebugInstr())
299 for (
unsigned i = 0, e = OtherMI.getNumOperands(); i != e; ++i) {
303 unsigned MOReg = MO.
getReg();
310 if (&OtherMI == KillMI && MOReg == SavedReg)
314 else if (UseRegs.
count(MOReg))
320 assert(KillMO &&
"Didn't find kill");
325 KillMO = MI->findRegisterUseOperand(SavedReg,
false, TRI);
337 LIS->handleMove(*MI);
348 if (
DefMI.getParent() != BB ||
DefMI.isDebugValue())
352 else if (Ret != &
DefMI)
365 bool TwoAddressInstructionPass::isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
367 unsigned TmpReg = FromReg;
368 for (
int i = 0; i < Maxlen; i++) {
370 if (!Def || !Def->
isCopy())
385 bool TwoAddressInstructionPass::noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
388 unsigned LastUse = Dist;
394 if (DI == DistanceMap.
end())
396 if (MO.isUse() && DI->second < LastUse)
397 LastUse = DI->second;
398 if (MO.isDef() && DI->second > LastDef)
399 LastDef = DI->second;
402 return !(LastUse > LastDef && LastUse < Dist);
409 unsigned &SrcReg,
unsigned &DstReg,
410 bool &IsSrcPhys,
bool &IsDstPhys) {
447 assert(I != LI.
end() &&
"Reg must be live-in to use.");
475 bool allowFalsePositives) {
480 (allowFalsePositives || MRI->
hasOneUse(Reg)))
489 if (std::next(Begin) != MRI->
def_end())
492 bool IsSrcPhys, IsDstPhys;
493 unsigned SrcReg, DstReg;
496 if (!
isCopyToReg(*DefMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys))
505 for (
unsigned i = 0, NumOps = MI.
getNumOperands(); i != NumOps; ++i) {
525 unsigned &DstReg,
bool &IsDstPhys) {
534 if (
isCopyToReg(UseMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) {
552 if (SI == RegMap.
end())
574 for (
unsigned R : Set)
584 TwoAddressInstructionPass::
585 isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
632 if ((!FromRegB && CompC) || (FromRegB && !CompB && (!FromRegC || CompC)))
638 if ((!FromRegC && CompB) || (FromRegC && !CompC && (!FromRegB || CompB)))
644 unsigned LastDefC = 0;
645 if (!noUseAfterLastDef(regC, Dist, LastDefC))
650 unsigned LastDefB = 0;
651 if (!noUseAfterLastDef(regB, Dist, LastDefB))
677 return LastDefB && LastDefC && LastDefC > LastDefB;
682 bool TwoAddressInstructionPass::commuteInstruction(
MachineInstr *MI,
691 if (NewMI ==
nullptr) {
698 "TargetInstrInfo::commuteInstruction() should not return a new " 699 "instruction unless it was requested.");
705 SrcRegMap[RegA] = FromRegC;
714 TwoAddressInstructionPass::isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB){
733 unsigned RegA,
unsigned RegB,
739 "convertToThreeAddress changed iterator reference");
754 Sunk = sink3AddrInstruction(NewMI, RegB, mi);
759 DistanceMap.
insert(std::make_pair(NewMI, Dist));
767 SrcRegMap.
erase(RegA);
768 DstRegMap.
erase(RegB);
775 TwoAddressInstructionPass::scanUses(
unsigned DstReg) {
780 unsigned Reg = DstReg;
782 NewReg, IsDstPhys)) {
787 if (DI != DistanceMap.
end())
795 bool isNew = SrcRegMap.
insert(std::make_pair(NewReg, Reg)).second;
797 assert(SrcRegMap[NewReg] == Reg &&
"Can't map to two src registers!");
802 if (!VirtRegPairs.
empty()) {
803 unsigned ToReg = VirtRegPairs.
back();
805 while (!VirtRegPairs.
empty()) {
806 unsigned FromReg = VirtRegPairs.
back();
808 bool isNew = DstRegMap.
insert(std::make_pair(FromReg, ToReg)).second;
810 assert(DstRegMap[FromReg] == ToReg &&
"Can't map to two dst registers!");
813 bool isNew = DstRegMap.
insert(std::make_pair(DstReg, ToReg)).second;
815 assert(DstRegMap[DstReg] == ToReg &&
"Can't map to two dst registers!");
831 void TwoAddressInstructionPass::processCopy(
MachineInstr *MI) {
832 if (Processed.
count(MI))
835 bool IsSrcPhys, IsDstPhys;
836 unsigned SrcReg, DstReg;
837 if (!
isCopyToReg(*MI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys))
840 if (IsDstPhys && !IsSrcPhys)
841 DstRegMap.
insert(std::make_pair(SrcReg, DstReg));
842 else if (!IsDstPhys && IsSrcPhys) {
843 bool isNew = SrcRegMap.
insert(std::make_pair(DstReg, SrcReg)).second;
845 assert(SrcRegMap[DstReg] == SrcReg &&
846 "Can't map to two src physical registers!");
857 bool TwoAddressInstructionPass::
868 if (DI == DistanceMap.
end())
876 "Reg should not have empty live interval.");
880 if (I != LI.
end() && I->start < MBBEndIdx)
901 bool SeenStore =
true;
915 unsigned MOReg = MO.getReg();
922 if (MOReg != Reg && (MO.isKill() ||
932 while (End != MBB->
end()) {
935 Defs.
push_back(End->getOperand(0).getReg());
942 unsigned NumVisited = 0;
947 if (OtherMI.isDebugInstr())
952 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
953 OtherMI.isBranch() || OtherMI.isTerminator())
959 unsigned MOReg = MO.getReg();
976 if (MOReg != Reg && ((isKill &&
regOverlapsSet(Uses, MOReg, TRI)) ||
980 if (MOReg == Reg && !isKill)
984 assert((MOReg != Reg || &OtherMI == KillMI) &&
985 "Found multiple kills of a register in a basic block");
991 while (Begin != MBB->
begin() && std::prev(Begin)->isDebugInstr())
1000 auto CopyMI = MBBI++;
1001 MBB->
splice(InsertPos, MBB, CopyMI);
1009 MBB->
splice(InsertPos, MBB, Begin, End);
1010 DistanceMap.
erase(DI);
1026 bool TwoAddressInstructionPass::isDefTooClose(
unsigned Reg,
unsigned Dist,
1034 if (DDI == DistanceMap.
end())
1036 unsigned DefDist = DDI->second;
1037 assert(Dist > DefDist &&
"Visited def already?");
1047 bool TwoAddressInstructionPass::
1058 if (DI == DistanceMap.
end())
1066 "Reg should not have empty live interval.");
1070 if (I != LI.
end() && I->start < MBBEndIdx)
1086 bool SeenStore =
true;
1097 unsigned MOReg = MO.getReg();
1101 if (isDefTooClose(MOReg, DI->second, MI))
1103 bool isKill = MO.isKill() || (LIS &&
isPlainlyKilled(KillMI, MOReg, LIS));
1104 if (MOReg == Reg && !isKill)
1107 if (isKill && MOReg != Reg)
1117 unsigned NumVisited = 0;
1121 if (OtherMI.isDebugInstr())
1123 if (NumVisited > 10)
1126 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
1127 OtherMI.isBranch() || OtherMI.isTerminator())
1134 unsigned MOReg = MO.getReg();
1138 if (Defs.
count(MOReg))
1142 if (Kills.
count(MOReg))
1145 if (&OtherMI != MI && MOReg == Reg &&
1154 for (
unsigned i = 0, e = OtherDefs.
size(); i != e; ++i) {
1155 unsigned MOReg = OtherDefs[i];
1156 if (Uses.
count(MOReg))
1159 LiveDefs.
count(MOReg))
1168 while (InsertPos != MBB->
begin() && std::prev(InsertPos)->isDebugInstr())
1172 while (std::prev(From)->isDebugInstr())
1174 MBB->
splice(InsertPos, MBB, From, To);
1176 nmi = std::prev(InsertPos);
1177 DistanceMap.
erase(DI);
1203 bool TwoAddressInstructionPass::tryInstructionCommute(
MachineInstr *MI,
1211 bool MadeChange =
false;
1216 for (; OtherOpIdx < OpsNum; OtherOpIdx++) {
1226 bool AggressiveCommute =
false;
1230 bool OtherOpKilled =
isKilled(*MI, OtherOpReg, MRI, TII, LIS,
false);
1231 bool DoCommute = !BaseOpKilled && OtherOpKilled;
1234 isProfitableToCommute(DstOpReg, BaseOpReg, OtherOpReg, MI, Dist)) {
1236 AggressiveCommute =
true;
1240 if (DoCommute && commuteInstruction(MI, DstOpIdx, BaseOpIdx, OtherOpIdx,
1244 if (AggressiveCommute) {
1248 BaseOpReg = OtherOpReg;
1249 BaseOpKilled = OtherOpKilled;
1266 bool TwoAddressInstructionPass::
1269 unsigned SrcIdx,
unsigned DstIdx,
1270 unsigned Dist,
bool shouldOnlyCommute) {
1279 "cannot make instruction into two-address form");
1280 bool regBKilled =
isKilled(MI, regB, MRI, TII, LIS,
true);
1285 bool Commuted = tryInstructionCommute(&MI, DstIdx, SrcIdx, regBKilled, Dist);
1298 if (shouldOnlyCommute)
1312 regBKilled =
isKilled(MI, regB, MRI, TII, LIS,
true);
1318 if (!regBKilled || isProfitableToConv3Addr(regA, regB)) {
1320 if (convertInstTo3Addr(mi, nmi, regA, regB, Dist)) {
1321 ++NumConvertedTo3Addr;
1346 if (MI.
mayLoad() && !regBKilled) {
1348 unsigned LoadRegIndex;
1361 TII->
getRegClass(UnfoldMCID, LoadRegIndex, TRI, *MF));
1371 "Unfolded a load into multiple instructions!");
1373 NewMIs[1]->addRegisterKilled(Reg, TRI);
1377 MBB->
insert(mi, NewMIs[0]);
1378 MBB->
insert(mi, NewMIs[1]);
1381 <<
"2addr: NEW INST: " << *NewMIs[1]);
1384 unsigned NewDstIdx = NewMIs[1]->findRegisterDefOperandIdx(regA);
1385 unsigned NewSrcIdx = NewMIs[1]->findRegisterUseOperandIdx(regB);
1387 bool TransformResult =
1388 tryInstructionTransform(NewMI, mi, NewSrcIdx, NewDstIdx, Dist,
true);
1389 (void)TransformResult;
1390 assert(!TransformResult &&
1391 "tryInstructionTransform() should return false.");
1392 if (NewMIs[1]->getOperand(NewSrcIdx).isKill()) {
1402 if (NewMIs[0]->killsRegister(MO.
getReg()))
1406 "Kill missing after load unfold!");
1411 if (NewMIs[1]->registerDefIsDead(MO.
getReg()))
1415 "Dead flag missing after load unfold!");
1447 NewMIs[0]->eraseFromParent();
1448 NewMIs[1]->eraseFromParent();
1460 bool TwoAddressInstructionPass::
1461 collectTiedOperands(
MachineInstr *MI, TiedOperandMap &TiedOperands) {
1463 bool AnyOps =
false;
1466 for (
unsigned SrcIdx = 0; SrcIdx < NumOps; ++SrcIdx) {
1467 unsigned DstIdx = 0;
1473 unsigned SrcReg = SrcMO.
getReg();
1474 unsigned DstReg = DstMO.
getReg();
1476 if (SrcReg == DstReg)
1479 assert(SrcReg && SrcMO.
isUse() &&
"two address instruction invalid");
1493 TiedOperands[SrcReg].push_back(std::make_pair(SrcIdx, DstIdx));
1501 TwoAddressInstructionPass::processTiedPairs(
MachineInstr *MI,
1502 TiedPairList &TiedPairs,
1504 bool IsEarlyClobber =
false;
1505 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1510 bool RemovedKillFlag =
false;
1511 bool AllUsesCopied =
true;
1512 unsigned LastCopiedReg = 0;
1515 unsigned SubRegB = 0;
1516 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1517 unsigned SrcIdx = TiedPairs[tpi].first;
1518 unsigned DstIdx = TiedPairs[tpi].second;
1521 unsigned RegA = DstMO.
getReg();
1532 AllUsesCopied =
false;
1535 LastCopiedReg = RegA;
1538 "cannot make instruction into two-address form");
1552 TII->
get(TargetOpcode::COPY), RegA);
1555 MIB.
addReg(RegB, 0, SubRegB);
1561 "tied subregister must be a truncation");
1567 &&
"tied subregister must be a truncation");
1574 DistanceMap.
insert(std::make_pair(&*PrevMI, Dist));
1575 DistanceMap[
MI] = ++Dist;
1585 LI.
addSegment(LiveInterval::Segment(LastCopyIdx, endIdx, VNI));
1593 "inconsistent operand info for 2-reg pass");
1596 RemovedKillFlag =
true;
1610 SrcRegMap[RegA] = RegB;
1613 if (AllUsesCopied) {
1614 bool ReplacedAllUntiedUses =
true;
1615 if (!IsEarlyClobber) {
1618 if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) {
1619 if (MO.getSubReg() == SubRegB) {
1621 MO.setIsKill(
false);
1622 RemovedKillFlag =
true;
1624 MO.setReg(LastCopiedReg);
1627 ReplacedAllUntiedUses =
false;
1634 if (RemovedKillFlag && ReplacedAllUntiedUses &&
1646 assert(I != LI.
end() &&
"RegB must be live-in to use.");
1649 if (I->end == UseIdx)
1652 }
else if (RemovedKillFlag) {
1658 if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) {
1667 bool TwoAddressInstructionPass::runOnMachineFunction(
MachineFunction &Func) {
1674 LV = getAnalysisIfAvailable<LiveVariables>();
1675 LIS = getAnalysisIfAvailable<LiveIntervals>();
1676 if (
auto *AAPass = getAnalysisIfAvailable<AAResultsWrapperPass>())
1677 AA = &AAPass->getAAResults();
1686 bool MadeChange =
false;
1688 LLVM_DEBUG(
dbgs() <<
"********** REWRITING TWO-ADDR INSTRS **********\n");
1694 TiedOperandMap TiedOperands;
1696 MBBI != MBBE; ++MBBI) {
1699 DistanceMap.
clear();
1709 if (mi->isDebugInstr() || SunkInstrs.
count(&*mi)) {
1716 if (mi->isRegSequence())
1717 eliminateRegSequence(mi);
1719 DistanceMap.
insert(std::make_pair(&*mi, ++Dist));
1725 if (!collectTiedOperands(&*mi, TiedOperands)) {
1730 ++NumTwoAddressInstrs;
1737 if (TiedOperands.size() == 1) {
1739 = TiedOperands.
begin()->second;
1740 if (TiedPairs.
size() == 1) {
1741 unsigned SrcIdx = TiedPairs[0].first;
1742 unsigned DstIdx = TiedPairs[0].second;
1743 unsigned SrcReg = mi->getOperand(SrcIdx).getReg();
1744 unsigned DstReg = mi->getOperand(DstIdx).getReg();
1745 if (SrcReg != DstReg &&
1746 tryInstructionTransform(mi, nmi, SrcIdx, DstIdx, Dist,
false)) {
1749 TiedOperands.clear();
1757 for (
auto &TO : TiedOperands) {
1758 processTiedPairs(&*mi, TO.second, Dist);
1763 if (mi->isInsertSubreg()) {
1766 unsigned SubIdx = mi->getOperand(3).getImm();
1767 mi->RemoveOperand(3);
1768 assert(mi->getOperand(0).getSubReg() == 0 &&
"Unexpected subreg idx");
1769 mi->getOperand(0).setSubReg(SubIdx);
1770 mi->getOperand(0).setIsUndef(mi->getOperand(1).isUndef());
1771 mi->RemoveOperand(1);
1772 mi->setDesc(TII->
get(TargetOpcode::COPY));
1778 TiedOperands.clear();
1784 MF->
verify(
this,
"After two-address instruction pass");
1799 void TwoAddressInstructionPass::
1817 bool DefEmitted =
false;
1820 unsigned SrcReg = UseMO.
getReg();
1828 bool isKill = UseMO.
isKill();
1830 for (
unsigned j = i + 2; j < e; j += 2)
1840 TII->
get(TargetOpcode::COPY))
1864 LLVM_DEBUG(
dbgs() <<
"Turned: " << MI <<
" into an IMPLICIT_DEF");
1865 MI.
setDesc(TII->
get(TargetOpcode::IMPLICIT_DEF));
bool removeVirtualRegisterKilled(unsigned reg, MachineInstr &MI)
removeVirtualRegisterKilled - Remove the specified kill of the virtual register from the live variabl...
const MachineInstrBuilder & add(const MachineOperand &MO) const
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 isCall(QueryType Type=AnyInBundle) const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
This class represents lattice values for constants.
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.
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...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void push_back(const T &Elt)
bool isSubregToReg() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator_range< use_nodbg_iterator > use_nodbg_operands(unsigned Reg) const
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
void setIsUndef(bool Val=true)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
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...
MachineInstr * commuteInstruction(MachineInstr &MI, bool NewMI=false, unsigned OpIdx1=CommuteAnyOperandIndex, unsigned OpIdx2=CommuteAnyOperandIndex) const
This method commutes the operands of the given machine instruction MI.
unsigned getSubReg() const
static cl::opt< bool > EnableRescheduling("twoaddr-reschedule", cl::desc("Coalesce copies by rescheduling (default=true)"), cl::init(true), cl::Hidden)
iterator_range< reg_iterator > reg_operands(unsigned Reg) const
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
bool removeVirtualRegisterDead(unsigned reg, MachineInstr &MI)
removeVirtualRegisterDead - Remove the specified kill of the virtual register from the live variable ...
MachineInstr * findKill(const MachineBasicBlock *MBB) const
findKill - Find a kill instruction in MBB. Return NULL if none is found.
VNInfo - Value Number Information.
iterator_range< mop_iterator > operands()
bool isCopyLike() const
Return true if the instruction behaves like a copy.
bool removeKill(MachineInstr &MI)
removeKill - Delete a kill corresponding to the specified machine instruction.
bool isEarlyClobber() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool isNotInMIMap(const MachineInstr &Instr) const
Returns true if the specified machine instr has been removed or was never entered in the map...
#define INITIALIZE_PASS_DEPENDENCY(depName)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
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
static bool regOverlapsSet(const SmallVectorImpl< unsigned > &Set, unsigned Reg, const TargetRegisterInfo *TRI)
unsigned getNumOperands() const
Retuns the total number of operands.
const TargetRegisterClass * getRegClass(const MCInstrDesc &MCID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
Given a machine instruction descriptor, returns the register class constraint for OpNum...
VNInfo::Allocator & getVNInfoAllocator()
virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg, bool UnfoldLoad, bool UnfoldStore, SmallVectorImpl< MachineInstr *> &NewMIs) const
unfoldMemoryOperand - Separate a single instruction which folded a load or a store or a load and a st...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void initializeTwoAddressInstructionPassPass(PassRegistry &)
virtual MachineInstr * convertToThreeAddress(MachineFunction::iterator &MFI, MachineInstr &MI, LiveVariables *LV) const
This method must be implemented by targets that set the M_CONVERTIBLE_TO_3_ADDR flag.
def_iterator def_begin(unsigned RegNo) const
SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
MCInst const & instruction(MCInst const &MCB, size_t Index)
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
static bool regsAreCompatible(unsigned RegA, unsigned RegB, const TargetRegisterInfo *TRI)
Return true if the two registers are equal or aliased.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const
Compute the instruction latency of a given instruction.
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
AnalysisUsage & addPreservedID(const void *ID)
Itinerary data supplied by a subtarget to be used by a target.
virtual const TargetInstrInfo * getInstrInfo() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
virtual const InstrItineraryData * getInstrItineraryData() const
getInstrItineraryData - Returns instruction itinerary data for the target or specific subtarget...
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
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)
bool erase(const KeyT &Val)
MachineInstrBundleIterator< MachineInstr > iterator
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...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
unsigned const MachineRegisterInfo * MRI
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.
MachineInstrBuilder & UseMI
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Two Address instruction pass
Represent the analysis usage information of a pass.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the specified register class A so that each register in it has a sub-register of...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
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 ...
void repairIntervalsInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, ArrayRef< unsigned > OrigRegs)
Update live intervals for instructions in a range of iterators.
char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
VarInfo & getVarInfo(unsigned RegIdx)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setIsKill(bool Val=true)
iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
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.
void replaceKillInstruction(unsigned Reg, MachineInstr &OldMI, MachineInstr &NewMI)
replaceKillInstruction - Update register kill info by replacing a kill instruction with a new one...
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"))
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...
BlockVerifier::State From
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool regsOverlap(unsigned regA, unsigned regB) const
Returns true if the two registers are equal or alias each other.
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
bool isDebugValue() const
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 isInsertSubreg() const
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
LiveInterval & getInterval(unsigned Reg)
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
virtual bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool hasAtLeastOneValue() const
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
INITIALIZE_PASS_BEGIN(TwoAddressInstructionPass, DEBUG_TYPE, "Two-Address instruction pass", false, false) INITIALIZE_PASS_END(TwoAddressInstructionPass
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr kills the specified register.
void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr &MI, bool AddIfNotFound=false)
addVirtualRegisterDead - Add information about the fact that the specified register is dead after bei...
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
LLVM_NODISCARD bool empty() const
unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx, const TargetRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
void setSubReg(unsigned subReg)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Two Address instruction static false 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...
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static def_iterator def_end()
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
Return the maximal subclass of the given register class that is allocatable or NULL.
iterator_range< def_instr_iterator > def_instructions(unsigned Reg) const
Primary interface to the complete machine description for the target machine.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const MachineOperand & getOperand(unsigned i) const
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...
virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc, bool UnfoldLoad, bool UnfoldStore, unsigned *LoadRegIndex=nullptr) const
Returns the opcode of the would be new instruction after load / store are unfolded from an instructio...
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
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.
void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr &MI, bool AddIfNotFound=false)
addVirtualRegisterKilled - Add information about the fact that the specified register is killed after...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block...
static bool isTwoAddrUse(MachineInstr &MI, unsigned Reg, unsigned &DstReg)
Return true if the specified MI uses the specified register as a two-address use. ...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.