[llvm] 0d1468d - [NFC][RDA] Make the interface const
Sam Parker via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 05:32:25 PST 2020
Author: Sam Parker
Date: 2020-01-23T13:32:11Z
New Revision: 0d1468db58535900270a3d3d10ed61d7d45dc4b9
URL: https://github.com/llvm/llvm-project/commit/0d1468db58535900270a3d3d10ed61d7d45dc4b9
DIFF: https://github.com/llvm/llvm-project/commit/0d1468db58535900270a3d3d10ed61d7d45dc4b9.diff
LOG: [NFC][RDA] Make the interface const
Make all the public query methods const.
Added:
Modified:
llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
llvm/lib/CodeGen/ReachingDefAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
index 9bc06e5e23b4..465709617460 100644
--- a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
+++ b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
@@ -93,51 +93,51 @@ class ReachingDefAnalysis : public MachineFunctionPass {
/// 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.
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index 7559a8aff5bf..80f1835bbe9e 100644
--- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -169,9 +169,9 @@ void ReachingDefAnalysis::releaseMemory() {
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() &&
@@ -188,12 +188,13 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) {
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)
@@ -203,7 +204,7 @@ bool ReachingDefAnalysis::hasSameReachingDef(MachineInstr *A, MachineInstr *B,
}
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()) &&
@@ -213,19 +214,20 @@ MachineInstr *ReachingDefAnalysis::getInstFromId(MachineBasicBlock *MBB,
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()) {
@@ -245,8 +247,9 @@ void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg,
}
}
-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)
@@ -259,8 +262,9 @@ bool ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int 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.
@@ -288,7 +292,7 @@ void ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
}
}
-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);
@@ -302,12 +306,13 @@ bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) {
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);
@@ -328,7 +333,7 @@ bool ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) {
}
MachineInstr* ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB,
- int PhysReg) {
+ int PhysReg) const {
LivePhysRegs LiveRegs(*TRI);
LiveRegs.addLiveOuts(*MBB);
if (!LiveRegs.contains(PhysReg))
More information about the llvm-commits
mailing list