[llvm] 767e429 - [Attributor][NFC] Allow to restrict the Attributor to cached passes
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 16:32:52 PDT 2023
Author: Johannes Doerfert
Date: 2023-06-23T16:32:36-07:00
New Revision: 767e429a8088b1387a0b9e640db08ac0636014e2
URL: https://github.com/llvm/llvm-project/commit/767e429a8088b1387a0b9e640db08ac0636014e2
DIFF: https://github.com/llvm/llvm-project/commit/767e429a8088b1387a0b9e640db08ac0636014e2.diff
LOG: [Attributor][NFC] Allow to restrict the Attributor to cached passes
If the user wants to avoid running additional passes, they can now
initialize the AnalysisGetter accordingly.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 365301a7e5e9b..90ebe12ca5c28 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1125,25 +1125,42 @@ struct AnalysisGetter {
template <typename, typename = void> static constexpr bool HasLegacyWrapper = false;
template <typename Analysis>
- typename Analysis::Result *getAnalysis(const Function &F) {
- if (FAM)
+ typename Analysis::Result *getAnalysis(const Function &F,
+ bool RequestCachedOnly = false) {
+ if (!LegacyPass && !FAM)
+ return nullptr;
+ if (FAM) {
+ if (CachedOnly || RequestCachedOnly)
+ return FAM->getCachedResult<Analysis>(const_cast<Function &>(F));
return &FAM->getResult<Analysis>(const_cast<Function &>(F));
- if constexpr (HasLegacyWrapper<Analysis>)
- if (LegacyPass)
+ }
+ if constexpr (HasLegacyWrapper<Analysis>) {
+ if (!CachedOnly && !RequestCachedOnly)
return &LegacyPass
->getAnalysis<typename Analysis::LegacyWrapper>(
const_cast<Function &>(F))
.getResult();
+ if (auto *P =
+ LegacyPass
+ ->getAnalysisIfAvailable<typename Analysis::LegacyWrapper>())
+ return &P->getResult();
+ }
return nullptr;
}
- AnalysisGetter(FunctionAnalysisManager &FAM) : FAM(&FAM) {}
- AnalysisGetter(Pass *P) : LegacyPass(P) {}
+ AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
+ : FAM(&FAM), CachedOnly(CachedOnly) {}
+ AnalysisGetter(Pass *P, bool CachedOnly = false)
+ : LegacyPass(P), CachedOnly(CachedOnly) {}
AnalysisGetter() = default;
private:
FunctionAnalysisManager *FAM = nullptr;
Pass *LegacyPass = nullptr;
+
+ /// If \p CachedOnly is true, no pass is created, just existing results are
+ /// used. Also available per request.
+ bool CachedOnly = false;
};
template <typename Analysis>
@@ -1288,9 +1305,6 @@ struct InformationCache {
return AG.getAnalysis<TargetLibraryAnalysis>(F);
}
- /// Return AliasAnalysis Result for function \p F.
- AAResults *getAAResultsForFunction(const Function &F);
-
/// Return true if \p Arg is involved in a must-tail call, thus the argument
/// of the caller or callee.
bool isInvolvedInMustTailCall(const Argument &Arg) {
@@ -1304,8 +1318,9 @@ struct InformationCache {
/// Return the analysis result from a pass \p AP for function \p F.
template <typename AP>
- typename AP::Result *getAnalysisResultForFunction(const Function &F) {
- return AG.getAnalysis<AP>(F);
+ typename AP::Result *getAnalysisResultForFunction(const Function &F,
+ bool CachedOnly = false) {
+ return AG.getAnalysis<AP>(F, CachedOnly);
}
/// Return datalayout used in the module.
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 1b51a115078fb..f7d1f1f13af28 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -3116,10 +3116,6 @@ void InformationCache::initializeInformationCache(const Function &CF,
InlineableFunctions.insert(&F);
}
-AAResults *InformationCache::getAAResultsForFunction(const Function &F) {
- return AG.getAnalysis<AAManager>(F);
-}
-
InformationCache::FunctionInfo::~FunctionInfo() {
// The instruction vectors are allocated using a BumpPtrAllocator, we need to
// manually destroy them.
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 58297b5fdc9c8..ce2255e7597eb 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -4016,7 +4016,8 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
// We have to utilize actual alias analysis queries so we need the object.
if (!AAR)
- AAR = A.getInfoCache().getAAResultsForFunction(*getAnchorScope());
+ AAR = A.getInfoCache().getAnalysisResultForFunction<AAManager>(
+ *getAnchorScope());
// Try to rule it out at the call site.
bool IsAliasing = !AAR || !AAR->isNoAlias(&getAssociatedValue(), ArgOp);
More information about the llvm-commits
mailing list