Skip to content

Commit 263d6e7

Browse files
committed
[ctx_prof] Flattened profile lowering pass
1 parent 9fef09f commit 263d6e7

File tree

8 files changed

+447
-4
lines changed

8 files changed

+447
-4
lines changed

llvm/include/llvm/Analysis/ProfileSummaryInfo.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ProfileSummaryInfo {
4242
private:
4343
const Module *M;
4444
std::unique_ptr<ProfileSummary> Summary;
45-
void computeThresholds();
45+
4646
// Count thresholds to answer isHotCount and isColdCount queries.
4747
std::optional<uint64_t> HotCountThreshold, ColdCountThreshold;
4848
// True if the working set size of the code is considered huge,
@@ -63,6 +63,14 @@ class ProfileSummaryInfo {
6363
ProfileSummaryInfo(const Module &M) : M(&M) { refresh(); }
6464
ProfileSummaryInfo(ProfileSummaryInfo &&Arg) = default;
6565

66+
/// Replace the summary with the provided one.
67+
void overrideSummary(std::unique_ptr<ProfileSummary> NewSummary) {
68+
Summary.swap(NewSummary);
69+
}
70+
71+
/// Compute the hot and cold thresholds.
72+
void computeThresholds();
73+
6674
/// If no summary is present, attempt to refresh.
6775
void refresh();
6876

llvm/include/llvm/ProfileData/ProfileCommon.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class ProfileSummaryBuilder {
7979
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
8080
uint64_t MaxInternalBlockCount = 0;
8181

82-
inline void addEntryCount(uint64_t Count);
83-
inline void addInternalCount(uint64_t Count);
84-
8582
public:
8683
InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
8784
: ProfileSummaryBuilder(std::move(Cutoffs)) {}
8885

86+
void addEntryCount(uint64_t Count);
87+
void addInternalCount(uint64_t Count);
88+
8989
void addRecord(const InstrProfRecord &);
9090
std::unique_ptr<ProfileSummary> getSummary();
9191
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- PGOCtxProfFlattening.h - Contextual Instr. Flattening ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the PGOCtxProfFlattening class.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOCTXPROFFLATTENING_H
13+
#define LLVM_TRANSFORMS_INSTRUMENTATION_PGOCTXPROFFLATTENING_H
14+
15+
#include "llvm/IR/PassManager.h"
16+
namespace llvm {
17+
18+
class PGOCtxProfFlattening : public PassInfoMixin<PGOCtxProfFlattening> {
19+
public:
20+
explicit PGOCtxProfFlattening() = default;
21+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
22+
};
23+
} // namespace llvm
24+
#endif

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
198198
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
199199
#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
200+
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"
200201
#include "llvm/Transforms/Instrumentation/PGOCtxProfLowering.h"
201202
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
202203
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ MODULE_PASS("coro-early", CoroEarlyPass())
5858
MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
5959
MODULE_PASS("ctx-instr-gen",
6060
PGOInstrumentationGen(PGOInstrumentationType::CTXPROF))
61+
MODULE_PASS("ctx-prof-flatten", PGOCtxProfFlattening())
6162
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
6263
MODULE_PASS("debugify", NewPMDebugifyPass())
6364
MODULE_PASS("dfsan", DataFlowSanitizerPass())

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_llvm_component_library(LLVMInstrumentation
1515
InstrProfiling.cpp
1616
KCFI.cpp
1717
LowerAllowCheckPass.cpp
18+
PGOCtxProfFlattening.cpp
1819
PGOCtxProfLowering.cpp
1920
PGOForceFunctionAttrs.cpp
2021
PGOInstrumentation.cpp

0 commit comments

Comments
 (0)