17 #define DEBUG_TYPE "reaching-deps-analysis" 28 assert(MBBNumber < MBBReachingDefs.size() &&
29 "Unexpected basic block number.");
30 MBBReachingDefs[MBBNumber].resize(NumRegUnits);
38 LiveRegs.assign(NumRegUnits, ReachingDefDefaultVal);
42 for (
const auto &LI : MBB->
liveins()) {
48 MBBReachingDefs[MBBNumber][*Unit].push_back(LiveRegs[*Unit]);
57 assert(
unsigned(
pred->getNumber()) < MBBOutRegsInfos.size() &&
58 "Should have pre-allocated MBBInfos for all MBBs");
59 const LiveRegsDefInfo &Incoming = MBBOutRegsInfos[
pred->getNumber()];
65 for (
unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
67 LiveRegs[Unit] =
std::max(LiveRegs[Unit], Incoming[Unit]);
68 if ((LiveRegs[Unit] != ReachingDefDefaultVal))
69 MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
74 << (!TraversedMBB.IsDone ?
": incomplete\n" 75 :
": all preds known\n"));
78 void ReachingDefAnalysis::leaveBasicBlock(
80 assert(!LiveRegs.empty() &&
"Must enter basic block first.");
83 "Unexpected basic block number.");
85 MBBOutRegsInfos[MBBNumber] = LiveRegs;
91 for (
int &OutLiveReg : MBBOutRegsInfos[MBBNumber])
92 OutLiveReg -= CurInstr;
101 "Unexpected basic block number.");
117 LiveRegs[*Unit] = CurInstr;
118 MBBReachingDefs[MBBNumber][*Unit].
push_back(CurInstr);
121 InstIds[
MI] = CurInstr;
125 void ReachingDefAnalysis::processBasicBlock(
127 enterBasicBlock(TraversedMBB);
132 leaveBasicBlock(TraversedMBB);
144 LLVM_DEBUG(
dbgs() <<
"********** REACHING DEFINITION ANALYSIS **********\n");
153 processBasicBlock(TraversedMBB);
157 for (MBBDefsInfo &MBBDefs : MBBReachingDefs) {
167 MBBOutRegsInfos.
clear();
168 MBBReachingDefs.
clear();
173 assert(InstIds.count(MI) &&
"Unexpected machine instuction.");
174 int InstId = InstIds[
MI];
175 int DefRes = ReachingDefDefaultVal;
178 "Unexpected basic block number.");
179 int LatestDef = ReachingDefDefaultVal;
181 for (
int Def : MBBReachingDefs[MBBNumber][*Unit]) {
186 LatestDef =
std::max(LatestDef, DefRes);
199 if (ParentA != ParentB)
208 "Unexpected basic block number.");
209 assert(InstId < static_cast<int>(MBB->
size()) &&
210 "Unexpected instruction id.");
215 for (
auto &MI : *MBB) {
216 if (InstIds.count(&MI) && InstIds[&
MI] == InstId)
223 assert(InstIds.count(MI) &&
"Unexpected machine instuction.");
231 while (++MI != MBB->
end()) {
237 for (
auto &MO : MI->operands()) {
238 if (!MO.isReg() || !MO.isUse() || MO.getReg() != PhysReg)
265 for (
auto Last = MBB->
rbegin(), End = MBB->
rend(); Last != End; ++Last) {
268 return InstIds[&*Last] > InstIds[MI];
287 if (MO.isReg() && MO.isDef() && MO.getReg() == PhysReg)
303 if (MO.isReg() && MO.isDef() && MO.getReg() == PhysReg)
316 for (
auto &MO :
I->operands())
317 if (MO.isReg() && MO.isUse() && MO.getReg() == PhysReg)
bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, int PhysReg)
Return whether A and B use the same def of PhysReg.
void getAllInstWithUseBefore(MachineInstr *MI, int PhysReg, SmallVectorImpl< MachineInstr *> &Uses)
Provides all instructions before MI that uses PhysReg.
This class represents lattice values for constants.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
unsigned const TargetRegisterInfo * TRI
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
iterator_range< mop_iterator > operands()
unsigned getNumRegUnits() const
Return the number of (native) register units in the target.
INITIALIZE_PASS(ReachingDefAnalysis, DEBUG_TYPE, "ReachingDefAnalysis", false, true) void ReachingDefAnalysis
This class provides the reaching def analysis.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getNumOperands() const
Retuns the total number of operands.
A Use represents the edge between a Value definition and its users.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
unsigned getNumUses(MachineInstr *MI, int PhysReg)
Provide the number of uses, in the same block as MI, of the register that MI defines.
reverse_iterator rbegin()
MachineInstrBundleIterator< MachineInstr > iterator
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineInstr * getInstFromId(MachineBasicBlock *MBB, int InstId)
Provides the MI, from the given block, corresponding to the Id or a nullptr if the id does not refer ...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
MachineInstr * getReachingMIDef(MachineInstr *MI, int PhysReg)
Provides the instruction of the closest reaching def instruction of PhysReg that reaches MI...
iterator_range< pred_iterator > predecessors()
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
bool isDebugInstr() const
void getReachingLocalUses(MachineInstr *MI, int PhysReg, SmallVectorImpl< MachineInstr *> &Uses)
Provides the uses, in the same block as MI, of register that MI defines.
void sort(IteratorTy Start, IteratorTy End)
bool isReachingDefLiveOut(MachineInstr *MI, int PhysReg)
Return whether the reaching def for MI also is live out of its parent block.
bool isRegUsedAfter(MachineInstr *MI, int PhysReg)
Return whether the given register is used after MI, whether it's a local use or a live out...
Align max(MaybeAlign Lhs, Align Rhs)
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...
MachineInstr * getInstWithUseBefore(MachineInstr *MI, int PhysReg)
Provides the first instruction before MI that uses PhysReg.
bool isVariadic(QueryType Type=IgnoreBundle) const
Return true if this instruction can have a variable number of operands.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
int getClearance(MachineInstr *MI, MCPhysReg PhysReg)
Provides the clearance - the number of instructions since the closest reaching def instuction of Phys...
TraversalOrder traverse(MachineFunction &MF)
This class provides the basic blocks traversal order used by passes like ReachingDefAnalysis and Exec...
iterator_range< livein_iterator > liveins() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
int getReachingDef(MachineInstr *MI, int PhysReg)
Provides the instruction id of the closest reaching def instruction of PhysReg that reaches MI...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineBasicBlock * MBB
The basic block.
MachineInstr * getLocalLiveOutMIDef(MachineBasicBlock *MBB, int PhysReg)
Return the local MI that produces the live out value for PhysReg, or nullptr for a non-live out or no...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const