/// Provides the instruction id of the closest reaching def instruction of
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
- int getReachingDef(MachineInstr *MI, int PhysReg);
+ int getReachingDef(MachineInstr *MI, int PhysReg) const;
/// Provides the instruction of the closest reaching def instruction of
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
- MachineInstr *getReachingMIDef(MachineInstr *MI, int PhysReg);
+ MachineInstr *getReachingMIDef(MachineInstr *MI, int PhysReg) const;
/// Provides the MI, from the given block, corresponding to the Id or a
/// nullptr if the id does not refer to the block.
- MachineInstr *getInstFromId(MachineBasicBlock *MBB, int InstId);
+ MachineInstr *getInstFromId(MachineBasicBlock *MBB, int InstId) const;
/// Return whether A and B use the same def of PhysReg.
- bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, int PhysReg);
+ bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, int PhysReg) const;
/// Return whether the reaching def for MI also is live out of its parent
/// block.
- bool isReachingDefLiveOut(MachineInstr *MI, int PhysReg);
+ bool isReachingDefLiveOut(MachineInstr *MI, int PhysReg) const;
/// Return the local MI that produces the live out value for PhysReg, or
/// nullptr for a non-live out or non-local def.
MachineInstr *getLocalLiveOutMIDef(MachineBasicBlock *MBB,
- int PhysReg);
+ int PhysReg) const;
/// Return whether the given register is used after MI, whether it's a local
/// use or a live out.
- bool isRegUsedAfter(MachineInstr *MI, int PhysReg);
+ bool isRegUsedAfter(MachineInstr *MI, int PhysReg) const;
/// Provides the clearance - the number of instructions since the closest
/// reaching def instuction of PhysReg that reaches MI.
- int getClearance(MachineInstr *MI, MCPhysReg PhysReg);
+ int getClearance(MachineInstr *MI, MCPhysReg PhysReg) const;
/// Provides the uses, in the same block as MI, of register that MI defines.
/// This does not consider live-outs.
void getReachingLocalUses(MachineInstr *MI, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses);
+ SmallPtrSetImpl<MachineInstr*> &Uses) const;
/// For the given block, collect the instructions that use the live-in
/// value of the provided register. Return whether the value is still
/// live on exit.
bool getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses);
+ SmallPtrSetImpl<MachineInstr*> &Uses) const;
/// Collect the users of the value stored in PhysReg, which is defined
/// by MI.
void getGlobalUses(MachineInstr *MI, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses);
+ SmallPtrSetImpl<MachineInstr*> &Uses) const;
private:
/// Set up LiveRegs by merging predecessor live-out values.
InstIds.clear();
}
-int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) {
+int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) const {
assert(InstIds.count(MI) && "Unexpected machine instuction.");
- int InstId = InstIds[MI];
+ int InstId = InstIds.lookup(MI);
int DefRes = ReachingDefDefaultVal;
unsigned MBBNumber = MI->getParent()->getNumber();
assert(MBBNumber < MBBReachingDefs.size() &&
return LatestDef;
}
-MachineInstr* ReachingDefAnalysis::getReachingMIDef(MachineInstr *MI, int PhysReg) {
+MachineInstr* ReachingDefAnalysis::getReachingMIDef(MachineInstr *MI,
+ int PhysReg) const {
return getInstFromId(MI->getParent(), getReachingDef(MI, PhysReg));
}
bool ReachingDefAnalysis::hasSameReachingDef(MachineInstr *A, MachineInstr *B,
- int PhysReg) {
+ int PhysReg) const {
MachineBasicBlock *ParentA = A->getParent();
MachineBasicBlock *ParentB = B->getParent();
if (ParentA != ParentB)
}
MachineInstr *ReachingDefAnalysis::getInstFromId(MachineBasicBlock *MBB,
- int InstId) {
+ int InstId) const {
assert(static_cast<size_t>(MBB->getNumber()) < MBBReachingDefs.size() &&
"Unexpected basic block number.");
assert(InstId < static_cast<int>(MBB->size()) &&
return nullptr;
for (auto &MI : *MBB) {
- if (InstIds.count(&MI) && InstIds[&MI] == InstId)
+ if (InstIds.count(&MI) && InstIds.lookup(&MI) == InstId)
return &MI;
}
return nullptr;
}
-int ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) {
+int
+ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) const {
assert(InstIds.count(MI) && "Unexpected machine instuction.");
- return InstIds[MI] - getReachingDef(MI, PhysReg);
+ return InstIds.lookup(MI) - getReachingDef(MI, PhysReg);
}
void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses) {
+ SmallPtrSetImpl<MachineInstr*> &Uses) const {
MachineBasicBlock *MBB = Def->getParent();
MachineBasicBlock::iterator MI = MachineBasicBlock::iterator(Def);
while (++MI != MBB->end()) {
}
}
-bool ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses) {
+bool
+ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
+ SmallPtrSetImpl<MachineInstr*> &Uses) const {
for (auto &MI : *MBB) {
for (auto &MO : MI.operands()) {
if (!MO.isReg() || !MO.isUse() || MO.getReg() != PhysReg)
return isReachingDefLiveOut(&MBB->back(), PhysReg);
}
-void ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
- SmallPtrSetImpl<MachineInstr*> &Uses) {
+void
+ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
+ SmallPtrSetImpl<MachineInstr*> &Uses) const {
MachineBasicBlock *MBB = MI->getParent();
// Collect the uses that each def touches within the block.
}
}
-bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) {
+bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) const {
MachineBasicBlock *MBB = MI->getParent();
LivePhysRegs LiveRegs(*TRI);
LiveRegs.addLiveOuts(*MBB);
for (auto Last = MBB->rbegin(), End = MBB->rend(); Last != End; ++Last) {
LiveRegs.stepBackward(*Last);
if (LiveRegs.contains(PhysReg))
- return InstIds[&*Last] > InstIds[MI];
+ return InstIds.lookup(&*Last) > InstIds.lookup(MI);
}
return false;
}
-bool ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) {
+bool
+ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) const {
MachineBasicBlock *MBB = MI->getParent();
LivePhysRegs LiveRegs(*TRI);
LiveRegs.addLiveOuts(*MBB);
}
MachineInstr* ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB,
- int PhysReg) {
+ int PhysReg) const {
LivePhysRegs LiveRegs(*TRI);
LiveRegs.addLiveOuts(*MBB);
if (!LiveRegs.contains(PhysReg))