Skip to content

Commit 0d1468d

Browse files
committed
[NFC][RDA] Make the interface const
Make all the public query methods const.
1 parent 48d4ba8 commit 0d1468d

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

llvm/include/llvm/CodeGen/ReachingDefAnalysis.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,51 +93,51 @@ class ReachingDefAnalysis : public MachineFunctionPass {
9393

9494
/// Provides the instruction id of the closest reaching def instruction of
9595
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
96-
int getReachingDef(MachineInstr *MI, int PhysReg);
96+
int getReachingDef(MachineInstr *MI, int PhysReg) const;
9797

9898
/// Provides the instruction of the closest reaching def instruction of
9999
/// PhysReg that reaches MI, relative to the begining of MI's basic block.
100-
MachineInstr *getReachingMIDef(MachineInstr *MI, int PhysReg);
100+
MachineInstr *getReachingMIDef(MachineInstr *MI, int PhysReg) const;
101101

102102
/// Provides the MI, from the given block, corresponding to the Id or a
103103
/// nullptr if the id does not refer to the block.
104-
MachineInstr *getInstFromId(MachineBasicBlock *MBB, int InstId);
104+
MachineInstr *getInstFromId(MachineBasicBlock *MBB, int InstId) const;
105105

106106
/// Return whether A and B use the same def of PhysReg.
107-
bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, int PhysReg);
107+
bool hasSameReachingDef(MachineInstr *A, MachineInstr *B, int PhysReg) const;
108108

109109
/// Return whether the reaching def for MI also is live out of its parent
110110
/// block.
111-
bool isReachingDefLiveOut(MachineInstr *MI, int PhysReg);
111+
bool isReachingDefLiveOut(MachineInstr *MI, int PhysReg) const;
112112

113113
/// Return the local MI that produces the live out value for PhysReg, or
114114
/// nullptr for a non-live out or non-local def.
115115
MachineInstr *getLocalLiveOutMIDef(MachineBasicBlock *MBB,
116-
int PhysReg);
116+
int PhysReg) const;
117117

118118
/// Return whether the given register is used after MI, whether it's a local
119119
/// use or a live out.
120-
bool isRegUsedAfter(MachineInstr *MI, int PhysReg);
120+
bool isRegUsedAfter(MachineInstr *MI, int PhysReg) const;
121121

122122
/// Provides the clearance - the number of instructions since the closest
123123
/// reaching def instuction of PhysReg that reaches MI.
124-
int getClearance(MachineInstr *MI, MCPhysReg PhysReg);
124+
int getClearance(MachineInstr *MI, MCPhysReg PhysReg) const;
125125

126126
/// Provides the uses, in the same block as MI, of register that MI defines.
127127
/// This does not consider live-outs.
128128
void getReachingLocalUses(MachineInstr *MI, int PhysReg,
129-
SmallPtrSetImpl<MachineInstr*> &Uses);
129+
SmallPtrSetImpl<MachineInstr*> &Uses) const;
130130

131131
/// For the given block, collect the instructions that use the live-in
132132
/// value of the provided register. Return whether the value is still
133133
/// live on exit.
134134
bool getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
135-
SmallPtrSetImpl<MachineInstr*> &Uses);
135+
SmallPtrSetImpl<MachineInstr*> &Uses) const;
136136

137137
/// Collect the users of the value stored in PhysReg, which is defined
138138
/// by MI.
139139
void getGlobalUses(MachineInstr *MI, int PhysReg,
140-
SmallPtrSetImpl<MachineInstr*> &Uses);
140+
SmallPtrSetImpl<MachineInstr*> &Uses) const;
141141

142142
private:
143143
/// Set up LiveRegs by merging predecessor live-out values.

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ void ReachingDefAnalysis::releaseMemory() {
169169
InstIds.clear();
170170
}
171171

172-
int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) {
172+
int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) const {
173173
assert(InstIds.count(MI) && "Unexpected machine instuction.");
174-
int InstId = InstIds[MI];
174+
int InstId = InstIds.lookup(MI);
175175
int DefRes = ReachingDefDefaultVal;
176176
unsigned MBBNumber = MI->getParent()->getNumber();
177177
assert(MBBNumber < MBBReachingDefs.size() &&
@@ -188,12 +188,13 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, int PhysReg) {
188188
return LatestDef;
189189
}
190190

191-
MachineInstr* ReachingDefAnalysis::getReachingMIDef(MachineInstr *MI, int PhysReg) {
191+
MachineInstr* ReachingDefAnalysis::getReachingMIDef(MachineInstr *MI,
192+
int PhysReg) const {
192193
return getInstFromId(MI->getParent(), getReachingDef(MI, PhysReg));
193194
}
194195

195196
bool ReachingDefAnalysis::hasSameReachingDef(MachineInstr *A, MachineInstr *B,
196-
int PhysReg) {
197+
int PhysReg) const {
197198
MachineBasicBlock *ParentA = A->getParent();
198199
MachineBasicBlock *ParentB = B->getParent();
199200
if (ParentA != ParentB)
@@ -203,7 +204,7 @@ bool ReachingDefAnalysis::hasSameReachingDef(MachineInstr *A, MachineInstr *B,
203204
}
204205

205206
MachineInstr *ReachingDefAnalysis::getInstFromId(MachineBasicBlock *MBB,
206-
int InstId) {
207+
int InstId) const {
207208
assert(static_cast<size_t>(MBB->getNumber()) < MBBReachingDefs.size() &&
208209
"Unexpected basic block number.");
209210
assert(InstId < static_cast<int>(MBB->size()) &&
@@ -213,19 +214,20 @@ MachineInstr *ReachingDefAnalysis::getInstFromId(MachineBasicBlock *MBB,
213214
return nullptr;
214215

215216
for (auto &MI : *MBB) {
216-
if (InstIds.count(&MI) && InstIds[&MI] == InstId)
217+
if (InstIds.count(&MI) && InstIds.lookup(&MI) == InstId)
217218
return &MI;
218219
}
219220
return nullptr;
220221
}
221222

222-
int ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) {
223+
int
224+
ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) const {
223225
assert(InstIds.count(MI) && "Unexpected machine instuction.");
224-
return InstIds[MI] - getReachingDef(MI, PhysReg);
226+
return InstIds.lookup(MI) - getReachingDef(MI, PhysReg);
225227
}
226228

227229
void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg,
228-
SmallPtrSetImpl<MachineInstr*> &Uses) {
230+
SmallPtrSetImpl<MachineInstr*> &Uses) const {
229231
MachineBasicBlock *MBB = Def->getParent();
230232
MachineBasicBlock::iterator MI = MachineBasicBlock::iterator(Def);
231233
while (++MI != MBB->end()) {
@@ -245,8 +247,9 @@ void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg,
245247
}
246248
}
247249

248-
bool ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
249-
SmallPtrSetImpl<MachineInstr*> &Uses) {
250+
bool
251+
ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
252+
SmallPtrSetImpl<MachineInstr*> &Uses) const {
250253
for (auto &MI : *MBB) {
251254
for (auto &MO : MI.operands()) {
252255
if (!MO.isReg() || !MO.isUse() || MO.getReg() != PhysReg)
@@ -259,8 +262,9 @@ bool ReachingDefAnalysis::getLiveInUses(MachineBasicBlock *MBB, int PhysReg,
259262
return isReachingDefLiveOut(&MBB->back(), PhysReg);
260263
}
261264

262-
void ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
263-
SmallPtrSetImpl<MachineInstr*> &Uses) {
265+
void
266+
ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
267+
SmallPtrSetImpl<MachineInstr*> &Uses) const {
264268
MachineBasicBlock *MBB = MI->getParent();
265269

266270
// Collect the uses that each def touches within the block.
@@ -288,7 +292,7 @@ void ReachingDefAnalysis::getGlobalUses(MachineInstr *MI, int PhysReg,
288292
}
289293
}
290294

291-
bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) {
295+
bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) const {
292296
MachineBasicBlock *MBB = MI->getParent();
293297
LivePhysRegs LiveRegs(*TRI);
294298
LiveRegs.addLiveOuts(*MBB);
@@ -302,12 +306,13 @@ bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) {
302306
for (auto Last = MBB->rbegin(), End = MBB->rend(); Last != End; ++Last) {
303307
LiveRegs.stepBackward(*Last);
304308
if (LiveRegs.contains(PhysReg))
305-
return InstIds[&*Last] > InstIds[MI];
309+
return InstIds.lookup(&*Last) > InstIds.lookup(MI);
306310
}
307311
return false;
308312
}
309313

310-
bool ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) {
314+
bool
315+
ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) const {
311316
MachineBasicBlock *MBB = MI->getParent();
312317
LivePhysRegs LiveRegs(*TRI);
313318
LiveRegs.addLiveOuts(*MBB);
@@ -328,7 +333,7 @@ bool ReachingDefAnalysis::isReachingDefLiveOut(MachineInstr *MI, int PhysReg) {
328333
}
329334

330335
MachineInstr* ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB,
331-
int PhysReg) {
336+
int PhysReg) const {
332337
LivePhysRegs LiveRegs(*TRI);
333338
LiveRegs.addLiveOuts(*MBB);
334339
if (!LiveRegs.contains(PhysReg))

0 commit comments

Comments
 (0)