Skip to content

Commit

Permalink
[CGProfile] Don't fetch BFI without profile (NFCI)
Browse files Browse the repository at this point in the history
Don't fetch BFI if the function has no entry count. Peculiarly,
the implementation was already doing this for the (no longer
existing) legacy PM implementation, but the same principle applies
to the new pass manager. The only reason why the new PM doesn't
have LazyBFI is that with the new pass manager all passes are
lazy.

This improves compile-time for non-PGO builds.
  • Loading branch information
nikic committed Feb 28, 2023
1 parent d8d91b2 commit 26202a5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/test/CodeGen/sanitizer-module-constructor.c
Expand Up @@ -18,4 +18,4 @@ void h(void) { f(e); }

// CHECK: Running pass: {{.*}}SanitizerPass
// CHECK-NOT: Running pass: LoopSimplifyPass on {{.*}}san.module_ctor
// CHECK: Running analysis: DominatorTreeAnalysis on {{.*}}san.module_ctor
// CHECK: Running analysis: TargetLibraryAnalysis on {{.*}}san.module_ctor
10 changes: 4 additions & 6 deletions llvm/lib/Transforms/Instrumentation/CGProfile.cpp
Expand Up @@ -46,7 +46,7 @@ addModuleFlags(Module &M,
}

static bool runCGProfilePass(
Module &M, FunctionAnalysisManager &FAM, bool LazyBFI) {
Module &M, FunctionAnalysisManager &FAM) {
MapVector<std::pair<Function *, Function *>, uint64_t> Counts;
InstrProfSymtab Symtab;
auto UpdateCounts = [&](TargetTransformInfo &TTI, Function *F,
Expand All @@ -63,10 +63,8 @@ static bool runCGProfilePass(
(void)(bool) Symtab.create(M);
for (auto &F : M) {
// Avoid extra cost of running passes for BFI when the function doesn't have
// entry count. Since LazyBlockFrequencyInfoPass only exists in LPM, check
// if using LazyBlockFrequencyInfoPass.
// TODO: Remove LazyBFI when LazyBlockFrequencyInfoPass is available in NPM.
if (F.isDeclaration() || (LazyBFI && !F.getEntryCount()))
// entry count.
if (F.isDeclaration() || !F.getEntryCount())
continue;
auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(F);
if (BFI.getEntryFreq() == 0)
Expand Down Expand Up @@ -104,7 +102,7 @@ static bool runCGProfilePass(
PreservedAnalyses CGProfilePass::run(Module &M, ModuleAnalysisManager &MAM) {
FunctionAnalysisManager &FAM =
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
runCGProfilePass(M, FAM, false);
runCGProfilePass(M, FAM);

return PreservedAnalyses::all();
}
2 changes: 0 additions & 2 deletions llvm/test/Other/new-pm-defaults.ll
Expand Up @@ -274,8 +274,6 @@
; CHECK-O-NEXT: Running pass: GlobalDCEPass
; CHECK-O-NEXT: Running pass: ConstantMergePass
; CHECK-DEFAULT-NEXT: Running pass: CGProfilePass
; CHECK-DEFAULT-NEXT: Running analysis: BlockFrequencyAnalysis
; CHECK-DEFAULT-NEXT: Running analysis: BranchProbabilityAnalysis
; CHECK-DEFAULT-NEXT: Running pass: RelLookupTableConverterPass
; CHECK-LTO-NOT: Running pass: RelLookupTableConverterPass
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
Expand Down
2 changes: 0 additions & 2 deletions llvm/test/Other/new-pm-lto-defaults.ll
Expand Up @@ -140,8 +140,6 @@
; CHECK-O23SZ-NEXT: Running pass: EliminateAvailableExternallyPass
; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass
; CHECK-O23SZ-NEXT: Running pass: CGProfilePass
; CHECK-O23SZ-NEXT: Running analysis: BlockFrequencyAnalysis on foo
; CHECK-O23SZ-NEXT: Running analysis: BranchProbabilityAnalysis on foo
; CHECK-EP-NEXT: Running pass: NoOpModulePass
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
; CHECK-O-NEXT: Running pass: PrintModulePass
Expand Down
2 changes: 0 additions & 2 deletions llvm/test/Other/new-pm-thinlto-defaults.ll
Expand Up @@ -236,8 +236,6 @@
; CHECK-POSTLINK-O-NEXT: Running pass: GlobalDCEPass
; CHECK-POSTLINK-O-NEXT: Running pass: ConstantMergePass
; CHECK-POSTLINK-O-NEXT: Running pass: CGProfilePass
; CHECK-POSTLINK-O-NEXT: Running analysis: BlockFrequencyAnalysis
; CHECK-POSTLINK-O-NEXT: Running analysis: BranchProbabilityAnalysis
; CHECK-POSTLINK-O-NEXT: Running pass: RelLookupTableConverterPass
; CHECK-EP-OPT-EARLY-NEXT: Running pass: NoOpModulePass
; CHECK-EP-OPT-LAST-NEXT: Running pass: NoOpModulePass
Expand Down

0 comments on commit 26202a5

Please sign in to comment.