Skip to content

Commit c91fa95

Browse files
[SampleProfile] Always use FAM to get ORE
The split in this code path was left over from when we had to support the old PM and the new PM at the same time. Now that the legacy pass has been dropped, this simplifies the code a little bit and swaps pointers for references in a couple places. Reviewers: aeubanks, efriedma-quic, wlei-llvm Reviewed By: aeubanks Pull Request: #159858
1 parent f437309 commit c91fa95

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,11 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> {
485485
UseFlattenedProfile(UseFlattenedProfile) {}
486486

487487
bool doInitialization(Module &M, FunctionAnalysisManager *FAM = nullptr);
488-
bool runOnModule(Module &M, ModuleAnalysisManager *AM,
488+
bool runOnModule(Module &M, ModuleAnalysisManager &AM,
489489
ProfileSummaryInfo *_PSI);
490490

491491
protected:
492-
bool runOnFunction(Function &F, ModuleAnalysisManager *AM);
492+
bool runOnFunction(Function &F, ModuleAnalysisManager &AM);
493493
bool emitAnnotations(Function &F);
494494
ErrorOr<uint64_t> getInstWeight(const Instruction &I) override;
495495
const FunctionSamples *findCalleeFunctionSamples(const CallBase &I) const;
@@ -2160,7 +2160,7 @@ void SampleProfileLoader::removePseudoProbeInstsDiscriminator(Module &M) {
21602160
}
21612161
}
21622162

2163-
bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
2163+
bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager &AM,
21642164
ProfileSummaryInfo *_PSI) {
21652165
GUIDToFuncNameMapper Mapper(M, *Reader, GUIDToFuncNameMap);
21662166

@@ -2238,7 +2238,8 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager *AM,
22382238
return retval;
22392239
}
22402240

2241-
bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM) {
2241+
bool SampleProfileLoader::runOnFunction(Function &F,
2242+
ModuleAnalysisManager &AM) {
22422243
LLVM_DEBUG(dbgs() << "\n\nProcessing Function " << F.getName() << "\n");
22432244
DILocation2SampleMap.clear();
22442245
// By default the entry count is initialized to -1, which will be treated
@@ -2290,15 +2291,9 @@ bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM)
22902291
if (!F.getEntryCount())
22912292
F.setEntryCount(ProfileCount(initialEntryCount, Function::PCT_Real));
22922293
std::unique_ptr<OptimizationRemarkEmitter> OwnedORE;
2293-
if (AM) {
2294-
auto &FAM =
2295-
AM->getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
2296-
.getManager();
2297-
ORE = &FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
2298-
} else {
2299-
OwnedORE = std::make_unique<OptimizationRemarkEmitter>(&F);
2300-
ORE = OwnedORE.get();
2301-
}
2294+
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
2295+
.getManager();
2296+
ORE = &FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
23022297

23032298
if (FunctionSamples::ProfileIsCS)
23042299
Samples = ContextTracker->getBaseSamplesFor(F);
@@ -2363,7 +2358,7 @@ PreservedAnalyses SampleProfileLoaderPass::run(Module &M,
23632358
return PreservedAnalyses::all();
23642359

23652360
ProfileSummaryInfo *PSI = &AM.getResult<ProfileSummaryAnalysis>(M);
2366-
if (!SampleLoader.runOnModule(M, &AM, PSI))
2361+
if (!SampleLoader.runOnModule(M, AM, PSI))
23672362
return PreservedAnalyses::all();
23682363

23692364
return PreservedAnalyses::none();

0 commit comments

Comments
 (0)