Skip to content

Commit 767e429

Browse files
committed
[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.
1 parent 23dafbb commit 767e429

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,25 +1125,42 @@ struct AnalysisGetter {
11251125
template <typename, typename = void> static constexpr bool HasLegacyWrapper = false;
11261126

11271127
template <typename Analysis>
1128-
typename Analysis::Result *getAnalysis(const Function &F) {
1129-
if (FAM)
1128+
typename Analysis::Result *getAnalysis(const Function &F,
1129+
bool RequestCachedOnly = false) {
1130+
if (!LegacyPass && !FAM)
1131+
return nullptr;
1132+
if (FAM) {
1133+
if (CachedOnly || RequestCachedOnly)
1134+
return FAM->getCachedResult<Analysis>(const_cast<Function &>(F));
11301135
return &FAM->getResult<Analysis>(const_cast<Function &>(F));
1131-
if constexpr (HasLegacyWrapper<Analysis>)
1132-
if (LegacyPass)
1136+
}
1137+
if constexpr (HasLegacyWrapper<Analysis>) {
1138+
if (!CachedOnly && !RequestCachedOnly)
11331139
return &LegacyPass
11341140
->getAnalysis<typename Analysis::LegacyWrapper>(
11351141
const_cast<Function &>(F))
11361142
.getResult();
1143+
if (auto *P =
1144+
LegacyPass
1145+
->getAnalysisIfAvailable<typename Analysis::LegacyWrapper>())
1146+
return &P->getResult();
1147+
}
11371148
return nullptr;
11381149
}
11391150

1140-
AnalysisGetter(FunctionAnalysisManager &FAM) : FAM(&FAM) {}
1141-
AnalysisGetter(Pass *P) : LegacyPass(P) {}
1151+
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
1152+
: FAM(&FAM), CachedOnly(CachedOnly) {}
1153+
AnalysisGetter(Pass *P, bool CachedOnly = false)
1154+
: LegacyPass(P), CachedOnly(CachedOnly) {}
11421155
AnalysisGetter() = default;
11431156

11441157
private:
11451158
FunctionAnalysisManager *FAM = nullptr;
11461159
Pass *LegacyPass = nullptr;
1160+
1161+
/// If \p CachedOnly is true, no pass is created, just existing results are
1162+
/// used. Also available per request.
1163+
bool CachedOnly = false;
11471164
};
11481165

11491166
template <typename Analysis>
@@ -1288,9 +1305,6 @@ struct InformationCache {
12881305
return AG.getAnalysis<TargetLibraryAnalysis>(F);
12891306
}
12901307

1291-
/// Return AliasAnalysis Result for function \p F.
1292-
AAResults *getAAResultsForFunction(const Function &F);
1293-
12941308
/// Return true if \p Arg is involved in a must-tail call, thus the argument
12951309
/// of the caller or callee.
12961310
bool isInvolvedInMustTailCall(const Argument &Arg) {
@@ -1304,8 +1318,9 @@ struct InformationCache {
13041318

13051319
/// Return the analysis result from a pass \p AP for function \p F.
13061320
template <typename AP>
1307-
typename AP::Result *getAnalysisResultForFunction(const Function &F) {
1308-
return AG.getAnalysis<AP>(F);
1321+
typename AP::Result *getAnalysisResultForFunction(const Function &F,
1322+
bool CachedOnly = false) {
1323+
return AG.getAnalysis<AP>(F, CachedOnly);
13091324
}
13101325

13111326
/// Return datalayout used in the module.

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,10 +3116,6 @@ void InformationCache::initializeInformationCache(const Function &CF,
31163116
InlineableFunctions.insert(&F);
31173117
}
31183118

3119-
AAResults *InformationCache::getAAResultsForFunction(const Function &F) {
3120-
return AG.getAnalysis<AAManager>(F);
3121-
}
3122-
31233119
InformationCache::FunctionInfo::~FunctionInfo() {
31243120
// The instruction vectors are allocated using a BumpPtrAllocator, we need to
31253121
// manually destroy them.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4016,7 +4016,8 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
40164016

40174017
// We have to utilize actual alias analysis queries so we need the object.
40184018
if (!AAR)
4019-
AAR = A.getInfoCache().getAAResultsForFunction(*getAnchorScope());
4019+
AAR = A.getInfoCache().getAnalysisResultForFunction<AAManager>(
4020+
*getAnchorScope());
40204021

40214022
// Try to rule it out at the call site.
40224023
bool IsAliasing = !AAR || !AAR->isNoAlias(&getAssociatedValue(), ArgOp);

0 commit comments

Comments
 (0)