-
Notifications
You must be signed in to change notification settings - Fork 14.3k
InstrProfiling: Split creating Bias offset to getOrCreateBiasVar(Name). NFC. #95692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-transforms Author: NAKAMURA Takumi (chapuni) ChangesFull diff: https://github.com/llvm/llvm-project/pull/95692.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 9c34374f0ece1..213044800053f 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -278,6 +278,10 @@ class InstrLowerer final {
/// using the index represented by the a temp value into a bitmap.
void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
+ /// Get the Bias value for data to access mmap-ed area.
+ /// Create it if it hasn't been seen.
+ GlobalVariable *getOrCreateBiasVar(StringRef VarName);
+
/// Compute the address of the counter value that this profiling instruction
/// acts on.
Value *getCounterAddress(InstrProfCntrInstBase *I);
@@ -885,6 +889,29 @@ void InstrLowerer::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
Ind->eraseFromParent();
}
+GlobalVariable *InstrLowerer::getOrCreateBiasVar(StringRef VarName) {
+ auto *Bias = M.getGlobalVariable(VarName);
+ if (Bias)
+ return Bias;
+
+ Type *Int64Ty = Type::getInt64Ty(M.getContext());
+
+ // Compiler must define this variable when runtime counter relocation
+ // is being used. Runtime has a weak external reference that is used
+ // to check whether that's the case or not.
+ Bias = new GlobalVariable(M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
+ Constant::getNullValue(Int64Ty), VarName);
+ Bias->setVisibility(GlobalVariable::HiddenVisibility);
+ // A definition that's weak (linkonce_odr) without being in a COMDAT
+ // section wouldn't lead to link errors, but it would lead to a dead
+ // data word from every TU but one. Putting it in COMDAT ensures there
+ // will be exactly one data slot in the link.
+ if (TT.supportsCOMDAT())
+ Bias->setComdat(M.getOrInsertComdat(VarName));
+
+ return Bias;
+}
+
Value *InstrLowerer::getCounterAddress(InstrProfCntrInstBase *I) {
auto *Counters = getOrCreateRegionCounters(I);
IRBuilder<> Builder(I);
@@ -903,22 +930,7 @@ Value *InstrLowerer::getCounterAddress(InstrProfCntrInstBase *I) {
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
- // is being used. Runtime has a weak external reference that is used
- // to check whether that's the case or not.
- Bias = new GlobalVariable(
- M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
- Constant::getNullValue(Int64Ty), getInstrProfCounterBiasVarName());
- Bias->setVisibility(GlobalVariable::HiddenVisibility);
- // A definition that's weak (linkonce_odr) without being in a COMDAT
- // section wouldn't lead to link errors, but it would lead to a dead
- // data word from every TU but one. Putting it in COMDAT ensures there
- // will be exactly one data slot in the link.
- if (TT.supportsCOMDAT())
- Bias->setComdat(M.getOrInsertComdat(Bias->getName()));
- }
+ auto *Bias = getOrCreateBiasVar(getInstrProfCounterBiasVarName());
BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias);
}
auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), BiasLI);
|
This is a preparation for bitmap bias. |
This was too intrusive. This reverts commit 9b47d56.
What is bitmap bias? Is there an RFC or something? |
@ornata Do you want me to post the RFC before reviewing this NFC change? |
auto *Bias = M.getGlobalVariable(VarName); | ||
if (Bias) | ||
return Bias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto *Bias = M.getGlobalVariable(VarName); | |
if (Bias) | |
return Bias; | |
if (auto *Bias = M.getGlobalVariable(VarName)) | |
return Bias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes the scope of Bias
smaller and causes errors.
Do you think I should introduce another variable for new GlobalVariable
? I don't think so, because the characteristics of Bias
is same here and it is tied to the return value.
That said, auto
is lazy a bit. I'll rewrite shortly.
It seems that you have a few related refactorings before your main change. One unfortunate drawback of not having stacked diffs on github is that we cannot see how patches are dependent on each other. I would recommend commenting with dependent PRs to allow folks to get more context into these changes. It also helps users find dependent patches to pick if they need to do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seams fine to me
No description provided.