Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
getInstrProfOptions(CodeGenOpts, LangOpts))
PB.registerPipelineStartEPCallback(
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(InstrProfiling(*Options, false));
MPM.addPass(InstrProfilingLoweringPass(*Options, false));
});

// TODO: Consider passing the MemoryProfileOutput to the pass builder via
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/Transforms/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Comdat *getOrCreateFunctionComdat(Function &F, Triple &T);
// Place global in a large section for x86-64 ELF binaries to mitigate
// relocation overflow pressure. This can be be used for metadata globals that
// aren't directly accessed by code, which has no performance impact.
void setGlobalVariableLargeSection(Triple &TargetTriple, GlobalVariable &GV);
void setGlobalVariableLargeSection(const Triple &TargetTriple,
GlobalVariable &GV);

// Insert GCOV profiling instrumentation
struct GCOVOptions {
Expand Down
45 changes: 28 additions & 17 deletions llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,45 @@ using LoadStorePair = std::pair<Instruction *, Instruction *>;
/// Instrumentation based profiling lowering pass. This pass lowers
/// the profile instrumented code generated by FE or the IR based
/// instrumentation pass.
class InstrProfiling : public PassInfoMixin<InstrProfiling> {
class InstrProfilingLoweringPass
: public PassInfoMixin<InstrProfilingLoweringPass> {
const InstrProfOptions Options;
// Is this lowering for the context-sensitive instrumentation.
const bool IsCS;

public:
InstrProfiling() : IsCS(false) {}
InstrProfiling(const InstrProfOptions &Options, bool IsCS = false)
InstrProfilingLoweringPass() : IsCS(false) {}
InstrProfilingLoweringPass(const InstrProfOptions &Options, bool IsCS = false)
: Options(Options), IsCS(IsCS) {}

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
bool run(Module &M,
std::function<const TargetLibraryInfo &(Function &F)> GetTLI);
};
class InstrProfiling final {
public:
InstrProfiling(Module &M, const InstrProfOptions &Options,
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
bool IsCS)
: M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
GetTLI(GetTLI) {}

bool lower();

private:
InstrProfOptions Options;
Module *M;
Triple TT;
Module &M;
const InstrProfOptions Options;
const Triple TT;
// Is this lowering for the context-sensitive instrumentation.
const bool IsCS;

std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
struct PerFunctionProfileData {
uint32_t NumValueSites[IPVK_Last + 1];
uint32_t NumValueSites[IPVK_Last + 1] = {};
GlobalVariable *RegionCounters = nullptr;
GlobalVariable *DataVar = nullptr;
GlobalVariable *RegionBitmaps = nullptr;
uint32_t NumBitmapBytes = 0;

PerFunctionProfileData() {
memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
}
PerFunctionProfileData() = default;
};
DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
/// If runtime relocation is enabled, this maps functions to the load
Expand All @@ -64,11 +78,8 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
std::vector<GlobalValue *> CompilerUsedVars;
std::vector<GlobalValue *> UsedVars;
std::vector<GlobalVariable *> ReferencedNames;
GlobalVariable *NamesVar;
size_t NamesSize;

// Is this lowering for the context-sensitive instrumentation.
bool IsCS;
GlobalVariable *NamesVar = nullptr;
size_t NamesSize = 0;

// vector of counter load/store pairs to be register promoted.
std::vector<LoadStorePair> PromotionCandidates;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
Options.DoCounterPromotion = true;
Options.UseBFIInPromotion = IsCS;
Options.Atomic = AtomicCounterUpdate;
MPM.addPass(InstrProfiling(Options, IsCS));
MPM.addPass(InstrProfilingLoweringPass(Options, IsCS));
}

void PassBuilder::addPGOInstrPassesForO0(
Expand All @@ -837,7 +837,7 @@ void PassBuilder::addPGOInstrPassesForO0(
Options.DoCounterPromotion = false;
Options.UseBFIInPromotion = IsCS;
Options.Atomic = AtomicCounterUpdate;
MPM.addPass(InstrProfiling(Options, IsCS));
MPM.addPass(InstrProfilingLoweringPass(Options, IsCS));
}

static InlineParams getInlineParamsFromOptLevel(OptimizationLevel Level) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ MODULE_PASS("inliner-wrapper-no-mandatory-first",
ModuleInlinerWrapperPass(getInlineParams(), false))
MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
MODULE_PASS("instrorderfile", InstrOrderFilePass())
MODULE_PASS("instrprof", InstrProfiling())
MODULE_PASS("instrprof", InstrProfilingLoweringPass())
MODULE_PASS("internalize", InternalizePass())
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("iroutliner", IROutlinerPass())
Expand Down
Loading