[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 11 00:26:52 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
After a pass calls addRequired<X>() it is strange to call
getAnalysisIfAvailable<X>() because analysis X should always be
available. Use getAnalysis<X>() instead.
---
Full diff: https://github.com/llvm/llvm-project/pull/65729.diff
5 Files Affected:
- (modified) llvm/lib/CodeGen/EarlyIfConversion.cpp (+2-2)
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+2-5)
- (modified) llvm/lib/CodeGen/VirtRegMap.cpp (+1-1)
- (modified) llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp (+1-1)
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+2-2)
``````````diff
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 61867d74bfa293c..3086d953a23699f 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -1092,7 +1092,7 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
SchedModel = STI.getSchedModel();
MRI = &MF.getRegInfo();
DomTree = &getAnalysis<MachineDominatorTree>();
- Loops = getAnalysisIfAvailable<MachineLoopInfo>();
+ Loops = &getAnalysis<MachineLoopInfo>();
Traces = &getAnalysis<MachineTraceMetrics>();
MinInstr = nullptr;
@@ -1226,7 +1226,7 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
MRI = &MF.getRegInfo();
SchedModel.init(&STI);
DomTree = &getAnalysis<MachineDominatorTree>();
- Loops = getAnalysisIfAvailable<MachineLoopInfo>();
+ Loops = &getAnalysis<MachineLoopInfo>();
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
bool Changed = false;
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 51f77e5fd8b08af..053caf518bd1f78 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -1016,11 +1016,8 @@ bool TypePromotionLegacy::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
- auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
- if (!TPC)
- return false;
-
- auto *TM = &TPC->getTM<TargetMachine>();
+ auto &TPC = getAnalysis<TargetPassConfig>();
+ auto *TM = &TPC.getTM<TargetMachine>();
auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp
index c1c6ce227334a4b..6e29a41b617a87e 100644
--- a/llvm/lib/CodeGen/VirtRegMap.cpp
+++ b/llvm/lib/CodeGen/VirtRegMap.cpp
@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction &fn) {
Indexes = &getAnalysis<SlotIndexes>();
LIS = &getAnalysis<LiveIntervals>();
VRM = &getAnalysis<VirtRegMap>();
- DebugVars = getAnalysisIfAvailable<LiveDebugVariables>();
+ DebugVars = &getAnalysis<LiveDebugVariables>();
LLVM_DEBUG(dbgs() << "********** REWRITE VIRTUAL REGISTERS **********\n"
<< "********** Function: " << MF->getName() << '\n');
LLVM_DEBUG(VRM->dump());
diff --git a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
index 4c8c03a4c693fe1..ad0ff8335647419 100644
--- a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
@@ -935,7 +935,7 @@ bool AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
SchedModel = MF.getSubtarget().getSchedModel();
MRI = &MF.getRegInfo();
DomTree = &getAnalysis<MachineDominatorTree>();
- Loops = getAnalysisIfAvailable<MachineLoopInfo>();
+ Loops = &getAnalysis<MachineLoopInfo>();
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
Traces = &getAnalysis<MachineTraceMetrics>();
MinInstr = nullptr;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 4c5b0ff3af16e53..f419d03c0ce3837 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3286,7 +3286,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
if (skipFunction(F))
return false;
- auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
+ auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
return Impl.runImpl(
@@ -3297,7 +3297,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
Impl.isMemDepEnabled()
? &getAnalysis<MemoryDependenceWrapperPass>().getMemDep()
: nullptr,
- LIWP ? &LIWP->getLoopInfo() : nullptr,
+ &LIWP.getLoopInfo(),
&getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(),
MSSAWP ? &MSSAWP->getMSSA() : nullptr);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/65729
More information about the cfe-commits
mailing list