67 #define DEBUG_TYPE "twoaddressinstruction" 69 STATISTIC(NumTwoAddressInstrs,
"Number of two-address instructions");
70 STATISTIC(NumCommuted ,
"Number of instructions commuted to coalesce");
71 STATISTIC(NumAggrCommuted ,
"Number of instructions aggressively commuted");
72 STATISTIC(NumConvertedTo3Addr,
"Number of instructions promoted to 3-address");
73 STATISTIC(Num3AddrSunk,
"Number of 3-address instructions sunk");
74 STATISTIC(NumReSchedUps,
"Number of instructions re-scheduled up");
75 STATISTIC(NumReSchedDowns,
"Number of instructions re-scheduled down");
80 cl::desc(
"Coalesce copies by rescheduling (default=true)"),
87 cl::desc(
"Maximum number of dataflow edges to traverse when evaluating " 88 "the benefit of commuting operands"));
129 bool isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
int Maxlen);
131 bool noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
unsigned &LastDef);
133 bool isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
137 unsigned RegBIdx,
unsigned RegCIdx,
unsigned Dist);
139 bool isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB);
143 unsigned RegA,
unsigned RegB,
unsigned Dist);
156 unsigned SrcIdx,
unsigned DstIdx,
157 unsigned Dist,
bool shouldOnlyCommute);
164 void scanUses(
unsigned DstReg);
172 void processTiedPairs(
MachineInstr *
MI, TiedPairList&,
unsigned &Dist);
205 "Two-Address instruction pass",
false,
false)
215 bool TwoAddressInstructionPass::
216 sink3AddrInstruction(
MachineInstr *MI,
unsigned SavedReg,
223 bool SeenStore =
true;
224 if (!MI->isSafeToMove(AA, SeenStore))
236 if (MO.isUse() && MOReg != SavedReg)
237 UseRegs.
insert(MO.getReg());
246 DefReg = MO.getReg();
254 "Reg should not have empty live interval.");
258 if (I != LI.
end() && I->start < MBBEndIdx)
262 KillMI = LIS->getInstructionFromIndex(I->end);
276 if (!KillMI || KillMI->
getParent() != MBB || KillMI == MI ||
290 unsigned NumVisited = 0;
293 if (OtherMI.isDebugInstr())
298 for (
unsigned i = 0,
e = OtherMI.getNumOperands(); i !=
e; ++i) {
309 if (&OtherMI == KillMI && MOReg == SavedReg)
313 else if (UseRegs.
count(MOReg))
319 assert(KillMO &&
"Didn't find kill");
324 KillMO = MI->findRegisterUseOperand(SavedReg,
false, TRI);
336 LIS->handleMove(*MI);
347 if (
DefMI.getParent() != BB ||
DefMI.isDebugValue())
351 else if (Ret != &
DefMI)
364 bool TwoAddressInstructionPass::isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
366 unsigned TmpReg = FromReg;
367 for (
int i = 0; i < Maxlen; i++) {
369 if (!Def || !Def->
isCopy())
384 bool TwoAddressInstructionPass::noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
387 unsigned LastUse = Dist;
393 if (DI == DistanceMap.
end())
395 if (MO.isUse() && DI->second < LastUse)
396 LastUse = DI->second;
397 if (MO.isDef() && DI->second > LastDef)
398 LastDef = DI->second;
401 return !(LastUse > LastDef && LastUse < Dist);
408 unsigned &SrcReg,
unsigned &DstReg,
409 bool &IsSrcPhys,
bool &IsDstPhys) {
445 assert(I != LI.
end() &&
"Reg must be live-in to use.");
473 bool allowFalsePositives) {
478 (allowFalsePositives || MRI->
hasOneUse(Reg)))
487 if (std::next(Begin) != MRI->
def_end())
490 bool IsSrcPhys, IsDstPhys;
491 unsigned SrcReg, DstReg;
494 if (!
isCopyToReg(*DefMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys))
503 for (
unsigned i = 0, NumOps = MI.
getNumOperands(); i != NumOps; ++i) {
523 unsigned &DstReg,
bool &IsDstPhys) {
532 if (
isCopyToReg(UseMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) {
550 if (SI == RegMap.
end())
572 for (
unsigned R : Set)
582 TwoAddressInstructionPass::
583 isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
630 if ((!FromRegB && CompC) || (FromRegB && !CompB && (!FromRegC || CompC)))
636 if ((!FromRegC && CompB) || (FromRegC && !CompC && (!FromRegB || CompB)))
642 unsigned LastDefC = 0;
643 if (!noUseAfterLastDef(regC, Dist, LastDefC))
648 unsigned LastDefB = 0;
649 if (!noUseAfterLastDef(regB, Dist, LastDefB))
675 return LastDefB && LastDefC && LastDefC > LastDefB;
680 bool TwoAddressInstructionPass::commuteInstruction(
MachineInstr *MI,
689 if (NewMI ==
nullptr) {
696 "TargetInstrInfo::commuteInstruction() should not return a new " 697 "instruction unless it was requested.");
703 SrcRegMap[RegA] = FromRegC;
712 TwoAddressInstructionPass::isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB){
731 unsigned RegA,
unsigned RegB,
737 "convertToThreeAddress changed iterator reference");
752 Sunk = sink3AddrInstruction(NewMI, RegB, mi);
757 DistanceMap.
insert(std::make_pair(NewMI, Dist));
765 SrcRegMap.
erase(RegA);
766 DstRegMap.
erase(RegB);
773 TwoAddressInstructionPass::scanUses(
unsigned DstReg) {
778 unsigned Reg = DstReg;
780 NewReg, IsDstPhys)) {
785 if (DI != DistanceMap.
end())
793 bool isNew = SrcRegMap.
insert(std::make_pair(NewReg, Reg)).second;
795 assert(SrcRegMap[NewReg] == Reg &&
"Can't map to two src registers!");
800 if (!VirtRegPairs.
empty()) {
801 unsigned ToReg = VirtRegPairs.
back();
803 while (!VirtRegPairs.
empty()) {
804 unsigned FromReg = VirtRegPairs.
back();
806 bool isNew = DstRegMap.
insert(std::make_pair(FromReg, ToReg)).second;
808 assert(DstRegMap[FromReg] == ToReg &&
"Can't map to two dst registers!");
811 bool isNew = DstRegMap.
insert(std::make_pair(DstReg, ToReg)).second;
813 assert(DstRegMap[DstReg] == ToReg &&
"Can't map to two dst registers!");
829 void TwoAddressInstructionPass::processCopy(
MachineInstr *MI) {
830 if (Processed.
count(MI))
833 bool IsSrcPhys, IsDstPhys;
834 unsigned SrcReg, DstReg;
835 if (!
isCopyToReg(*MI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys))
838 if (IsDstPhys && !IsSrcPhys)
839 DstRegMap.
insert(std::make_pair(SrcReg, DstReg));
840 else if (!IsDstPhys && IsSrcPhys) {
841 bool isNew = SrcRegMap.
insert(std::make_pair(DstReg, SrcReg)).second;
843 assert(SrcRegMap[DstReg] == SrcReg &&
844 "Can't map to two src physical registers!");
855 bool TwoAddressInstructionPass::
866 if (DI == DistanceMap.
end())
874 "Reg should not have empty live interval.");
878 if (I != LI.
end() && I->start < MBBEndIdx)
899 bool SeenStore =
true;
920 if (MOReg != Reg && (MO.isKill() ||
930 while (End != MBB->
end()) {
933 Defs.
push_back(End->getOperand(0).getReg());
940 unsigned NumVisited = 0;
945 if (OtherMI.isDebugInstr())
950 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
951 OtherMI.isBranch() || OtherMI.isTerminator())
974 if (MOReg != Reg && ((isKill &&
regOverlapsSet(Uses, MOReg, TRI)) ||
978 if (MOReg == Reg && !isKill)
982 assert((MOReg != Reg || &OtherMI == KillMI) &&
983 "Found multiple kills of a register in a basic block");
989 while (Begin != MBB->
begin() && std::prev(Begin)->isDebugInstr())
998 auto CopyMI = MBBI++;
999 MBB->
splice(InsertPos, MBB, CopyMI);
1007 MBB->
splice(InsertPos, MBB, Begin, End);
1008 DistanceMap.
erase(DI);
1024 bool TwoAddressInstructionPass::isDefTooClose(
unsigned Reg,
unsigned Dist,
1032 if (DDI == DistanceMap.
end())
1034 unsigned DefDist = DDI->second;
1035 assert(Dist > DefDist &&
"Visited def already?");
1045 bool TwoAddressInstructionPass::
1056 if (DI == DistanceMap.
end())
1064 "Reg should not have empty live interval.");
1068 if (I != LI.
end() && I->start < MBBEndIdx)
1084 bool SeenStore =
true;
1099 if (isDefTooClose(MOReg, DI->second, MI))
1101 bool isKill = MO.isKill() || (LIS &&
isPlainlyKilled(KillMI, MOReg, LIS));
1102 if (MOReg == Reg && !isKill)
1105 if (isKill && MOReg != Reg)
1115 unsigned NumVisited = 0;
1119 if (OtherMI.isDebugInstr())
1121 if (NumVisited > 10)
1124 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
1125 OtherMI.isBranch() || OtherMI.isTerminator())
1136 if (Defs.
count(MOReg))
1140 if (Kills.
count(MOReg))
1143 if (&OtherMI != MI && MOReg == Reg &&
1152 for (
unsigned i = 0,
e = OtherDefs.
size(); i !=
e; ++i) {
1153 unsigned MOReg = OtherDefs[i];
1154 if (Uses.
count(MOReg))
1165 while (InsertPos != MBB->
begin() && std::prev(InsertPos)->isDebugInstr())
1169 while (std::prev(From)->isDebugInstr())
1171 MBB->
splice(InsertPos, MBB, From, To);
1173 nmi = std::prev(InsertPos);
1174 DistanceMap.
erase(DI);
1200 bool TwoAddressInstructionPass::tryInstructionCommute(
MachineInstr *MI,
1208 bool MadeChange =
false;
1213 for (; OtherOpIdx < OpsNum; OtherOpIdx++) {
1223 bool AggressiveCommute =
false;
1227 bool OtherOpKilled =
isKilled(*MI, OtherOpReg, MRI, TII, LIS,
false);
1228 bool DoCommute = !BaseOpKilled && OtherOpKilled;
1231 isProfitableToCommute(DstOpReg, BaseOpReg, OtherOpReg, MI, Dist)) {
1233 AggressiveCommute =
true;
1237 if (DoCommute && commuteInstruction(MI, DstOpIdx, BaseOpIdx, OtherOpIdx,
1241 if (AggressiveCommute) {
1247 BaseOpReg = OtherOpReg;
1248 BaseOpKilled = OtherOpKilled;
1268 bool TwoAddressInstructionPass::
1271 unsigned SrcIdx,
unsigned DstIdx,
1272 unsigned Dist,
bool shouldOnlyCommute) {
1281 "cannot make instruction into two-address form");
1282 bool regBKilled =
isKilled(MI, regB, MRI, TII, LIS,
true);
1287 bool Commuted = tryInstructionCommute(&MI, DstIdx, SrcIdx, regBKilled, Dist);
1300 if (shouldOnlyCommute)
1314 regBKilled =
isKilled(MI, regB, MRI, TII, LIS,
true);
1320 if (!regBKilled || isProfitableToConv3Addr(regA, regB)) {
1322 if (convertInstTo3Addr(mi, nmi, regA, regB, Dist)) {
1323 ++NumConvertedTo3Addr;
1348 if (MI.
mayLoad() && !regBKilled) {
1350 unsigned LoadRegIndex;
1363 TII->
getRegClass(UnfoldMCID, LoadRegIndex, TRI, *MF));
1373 "Unfolded a load into multiple instructions!");
1375 NewMIs[1]->addRegisterKilled(Reg, TRI);
1379 MBB->
insert(mi, NewMIs[0]);
1380 MBB->
insert(mi, NewMIs[1]);
1383 <<
"2addr: NEW INST: " << *NewMIs[1]);
1386 unsigned NewDstIdx = NewMIs[1]->findRegisterDefOperandIdx(regA);
1387 unsigned NewSrcIdx = NewMIs[1]->findRegisterUseOperandIdx(regB);
1389 bool TransformResult =
1390 tryInstructionTransform(NewMI, mi, NewSrcIdx, NewDstIdx, Dist,
true);
1391 (void)TransformResult;
1392 assert(!TransformResult &&
1393 "tryInstructionTransform() should return false.");
1394 if (NewMIs[1]->getOperand(NewSrcIdx).isKill()) {
1403 if (NewMIs[0]->killsRegister(MO.
getReg()))
1407 "Kill missing after load unfold!");
1412 if (NewMIs[1]->registerDefIsDead(MO.
getReg()))
1416 "Dead flag missing after load unfold!");
1448 NewMIs[0]->eraseFromParent();
1449 NewMIs[1]->eraseFromParent();
1461 bool TwoAddressInstructionPass::
1462 collectTiedOperands(
MachineInstr *MI, TiedOperandMap &TiedOperands) {
1464 bool AnyOps =
false;
1467 for (
unsigned SrcIdx = 0; SrcIdx < NumOps; ++SrcIdx) {
1468 unsigned DstIdx = 0;
1477 if (SrcReg == DstReg)
1480 assert(SrcReg && SrcMO.
isUse() &&
"two address instruction invalid");
1494 TiedOperands[SrcReg].push_back(std::make_pair(SrcIdx, DstIdx));
1502 TwoAddressInstructionPass::processTiedPairs(
MachineInstr *MI,
1503 TiedPairList &TiedPairs,
1505 bool IsEarlyClobber =
false;
1506 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1511 bool RemovedKillFlag =
false;
1512 bool AllUsesCopied =
true;
1513 unsigned LastCopiedReg = 0;
1516 unsigned SubRegB = 0;
1517 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1518 unsigned SrcIdx = TiedPairs[tpi].first;
1519 unsigned DstIdx = TiedPairs[tpi].second;
1533 AllUsesCopied =
false;
1536 LastCopiedReg = RegA;
1539 "cannot make instruction into two-address form");
1553 TII->
get(TargetOpcode::COPY), RegA);
1556 MIB.
addReg(RegB, 0, SubRegB);
1562 "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;
1609 SrcRegMap[RegA] = RegB;
1612 if (AllUsesCopied) {
1613 bool ReplacedAllUntiedUses =
true;
1614 if (!IsEarlyClobber) {
1617 if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) {
1618 if (MO.getSubReg() == SubRegB) {
1620 MO.setIsKill(
false);
1621 RemovedKillFlag =
true;
1623 MO.setReg(LastCopiedReg);
1626 ReplacedAllUntiedUses =
false;
1633 if (RemovedKillFlag && ReplacedAllUntiedUses &&
1645 assert(I != LI.
end() &&
"RegB must be live-in to use.");
1648 if (I->end == UseIdx)
1651 }
else if (RemovedKillFlag) {
1657 if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) {
1666 bool TwoAddressInstructionPass::runOnMachineFunction(
MachineFunction &Func) {
1673 LV = getAnalysisIfAvailable<LiveVariables>();
1674 LIS = getAnalysisIfAvailable<LiveIntervals>();
1675 if (
auto *AAPass = getAnalysisIfAvailable<AAResultsWrapperPass>())
1676 AA = &AAPass->getAAResults();
1685 bool MadeChange =
false;
1687 LLVM_DEBUG(
dbgs() <<
"********** REWRITING TWO-ADDR INSTRS **********\n");
1693 TiedOperandMap TiedOperands;
1695 MBBI != MBBE; ++MBBI) {
1698 DistanceMap.
clear();
1708 if (mi->isDebugInstr() || SunkInstrs.
count(&*mi)) {
1715 if (mi->isRegSequence())
1716 eliminateRegSequence(mi);
1718 DistanceMap.
insert(std::make_pair(&*mi, ++Dist));
1724 if (!collectTiedOperands(&*mi, TiedOperands)) {
1729 ++NumTwoAddressInstrs;
1736 if (TiedOperands.size() == 1) {
1738 = TiedOperands.
begin()->second;
1739 if (TiedPairs.
size() == 1) {
1740 unsigned SrcIdx = TiedPairs[0].first;
1741 unsigned DstIdx = TiedPairs[0].second;
1742 Register SrcReg = mi->getOperand(SrcIdx).getReg();
1743 Register DstReg = mi->getOperand(DstIdx).getReg();
1744 if (SrcReg != DstReg &&
1745 tryInstructionTransform(mi, nmi, SrcIdx, DstIdx, Dist,
false)) {
1748 TiedOperands.clear();
1756 for (
auto &TO : TiedOperands) {
1757 processTiedPairs(&*mi, TO.second, Dist);
1762 if (mi->isInsertSubreg()) {
1765 unsigned SubIdx = mi->getOperand(3).getImm();
1766 mi->RemoveOperand(3);
1767 assert(mi->getOperand(0).getSubReg() == 0 &&
"Unexpected subreg idx");
1768 mi->getOperand(0).setSubReg(SubIdx);
1769 mi->getOperand(0).setIsUndef(mi->getOperand(1).isUndef());
1770 mi->RemoveOperand(1);
1771 mi->setDesc(TII->
get(TargetOpcode::COPY));
1777 TiedOperands.clear();
1783 MF->
verify(
this,
"After two-address instruction pass");
1798 void TwoAddressInstructionPass::
1815 bool DefEmitted =
false;
1826 bool isKill = UseMO.
isKill();
1828 for (
unsigned j = i + 2; j <
e; j += 2)
1838 TII->
get(TargetOpcode::COPY))
1862 LLVM_DEBUG(
dbgs() <<
"Turned: " << MI <<
" into an IMPLICIT_DEF");
1863 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
MachineOperand * findRegisterUseOperand(Register Reg, bool isKill=false, const TargetRegisterInfo *TRI=nullptr)
Wrapper for findRegisterUseOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
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
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...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
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.
void setIsUndef(bool Val=true)
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.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
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.
virtual 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)
bool regsOverlap(Register regA, Register regB) const
Returns true if the two registers are equal or alias each other.
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.
void setReg(Register Reg)
Change the register this operand corresponds to.
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.
bool killsRegister(Register Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr kills the specified register.
MachineInstrBuilder & UseMI
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()
LiveInterval & getInterval(Register Reg)
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.
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:
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.
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.
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...
virtual bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setSubReg(unsigned subReg)
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 use of the specified register...
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()
bool isSafeToMove(AAResults *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
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.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
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...
Register getReg() const
getReg - Returns the register number.
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...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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 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...
void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block...
Wrapper class representing virtual and physical registers.
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.