Skip to content

Commit b78f3ea

Browse files
authored
Clean up strange uses of getAnalysisIfAvailable (#65729)
After a pass calls addRequired<X>() it is strange to call getAnalysisIfAvailable<X>() because analysis X should always be available. Use getAnalysis<X>() instead.
1 parent 2888fa4 commit b78f3ea

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
10921092
SchedModel = STI.getSchedModel();
10931093
MRI = &MF.getRegInfo();
10941094
DomTree = &getAnalysis<MachineDominatorTree>();
1095-
Loops = getAnalysisIfAvailable<MachineLoopInfo>();
1095+
Loops = &getAnalysis<MachineLoopInfo>();
10961096
Traces = &getAnalysis<MachineTraceMetrics>();
10971097
MinInstr = nullptr;
10981098

@@ -1226,7 +1226,7 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
12261226
MRI = &MF.getRegInfo();
12271227
SchedModel.init(&STI);
12281228
DomTree = &getAnalysis<MachineDominatorTree>();
1229-
Loops = getAnalysisIfAvailable<MachineLoopInfo>();
1229+
Loops = &getAnalysis<MachineLoopInfo>();
12301230
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
12311231

12321232
bool Changed = false;

llvm/lib/CodeGen/TypePromotion.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,11 +1016,8 @@ bool TypePromotionLegacy::runOnFunction(Function &F) {
10161016
if (skipFunction(F))
10171017
return false;
10181018

1019-
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
1020-
if (!TPC)
1021-
return false;
1022-
1023-
auto *TM = &TPC->getTM<TargetMachine>();
1019+
auto &TPC = getAnalysis<TargetPassConfig>();
1020+
auto *TM = &TPC.getTM<TargetMachine>();
10241021
auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
10251022
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
10261023

llvm/lib/CodeGen/VirtRegMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction &fn) {
261261
Indexes = &getAnalysis<SlotIndexes>();
262262
LIS = &getAnalysis<LiveIntervals>();
263263
VRM = &getAnalysis<VirtRegMap>();
264-
DebugVars = getAnalysisIfAvailable<LiveDebugVariables>();
264+
DebugVars = &getAnalysis<LiveDebugVariables>();
265265
LLVM_DEBUG(dbgs() << "********** REWRITE VIRTUAL REGISTERS **********\n"
266266
<< "********** Function: " << MF->getName() << '\n');
267267
LLVM_DEBUG(VRM->dump());

llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ bool AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
935935
SchedModel = MF.getSubtarget().getSchedModel();
936936
MRI = &MF.getRegInfo();
937937
DomTree = &getAnalysis<MachineDominatorTree>();
938-
Loops = getAnalysisIfAvailable<MachineLoopInfo>();
938+
Loops = &getAnalysis<MachineLoopInfo>();
939939
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
940940
Traces = &getAnalysis<MachineTraceMetrics>();
941941
MinInstr = nullptr;

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,7 +3286,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
32863286
if (skipFunction(F))
32873287
return false;
32883288

3289-
auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
3289+
auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
32903290

32913291
auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
32923292
return Impl.runImpl(
@@ -3297,7 +3297,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
32973297
Impl.isMemDepEnabled()
32983298
? &getAnalysis<MemoryDependenceWrapperPass>().getMemDep()
32993299
: nullptr,
3300-
LIWP ? &LIWP->getLoopInfo() : nullptr,
3300+
&LIWP.getLoopInfo(),
33013301
&getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(),
33023302
MSSAWP ? &MSSAWP->getMSSA() : nullptr);
33033303
}

0 commit comments

Comments
 (0)