[llvm] 6e23cd2 - [InstrProf][NFC] Save profile bias to function map
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 08:32:36 PDT 2022
Author: Ellis Hoag
Date: 2022-05-16T08:32:31-07:00
New Revision: 6e23cd2bf073ab5eb5a103b935af54046d007c52
URL: https://github.com/llvm/llvm-project/commit/6e23cd2bf073ab5eb5a103b935af54046d007c52
DIFF: https://github.com/llvm/llvm-project/commit/6e23cd2bf073ab5eb5a103b935af54046d007c52.diff
LOG: [InstrProf][NFC] Save profile bias to function map
Add a map from functions to load instructions that compute the profile bias. Previously we assumed that if the first instruction in the function was a load instruction, then it must be computing the bias. This was likely to work out because functions usually start with the `llvm.instrprof.increment` instruction, but optimizations could change this. For example, inlining into a non-profiled function.
Reviewed By: phosek
Differential Revision: https://reviews.llvm.org/D114319
Added:
Modified:
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
index af7c63da52089..90fc0670448b8 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -56,6 +56,9 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
}
};
DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
+ /// If runtime relocation is enabled, this maps functions to the load
+ /// instruction that produces the profile relocation bias.
+ DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
std::vector<GlobalValue *> CompilerUsedVars;
std::vector<GlobalValue *> UsedVars;
std::vector<GlobalVariable *> ReferencedNames;
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 06c1b8990dbe6..73c575e589df2 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -703,10 +703,9 @@ Value *InstrProfiling::getCounterAddress(InstrProfInstBase *I) {
Type *Int64Ty = Type::getInt64Ty(M->getContext());
Function *Fn = I->getParent()->getParent();
- Instruction &EntryI = Fn->getEntryBlock().front();
- LoadInst *LI = dyn_cast<LoadInst>(&EntryI);
- if (!LI) {
- IRBuilder<> EntryBuilder(&EntryI);
+ LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
+ if (!BiasLI) {
+ IRBuilder<> EntryBuilder(&Fn->getEntryBlock().front());
auto *Bias = M->getGlobalVariable(getInstrProfCounterBiasVarName());
if (!Bias) {
// Compiler must define this variable when runtime counter relocation
@@ -723,9 +722,9 @@ Value *InstrProfiling::getCounterAddress(InstrProfInstBase *I) {
if (TT.supportsCOMDAT())
Bias->setComdat(M->getOrInsertComdat(Bias->getName()));
}
- LI = EntryBuilder.CreateLoad(Int64Ty, Bias);
+ BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias);
}
- auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);
+ auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), BiasLI);
return Builder.CreateIntToPtr(Add, Addr->getType());
}
More information about the llvm-commits
mailing list