[llvm] c0c1c3c - Revert "[InstrProfiling] Emit bias variable eagerly"
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 10 23:21:31 PDT 2021
Author: Petr Hosek
Date: 2021-08-10T23:21:15-07:00
New Revision: c0c1c3cf93ec089887944027ebfa95da03f8040b
URL: https://github.com/llvm/llvm-project/commit/c0c1c3cf93ec089887944027ebfa95da03f8040b
DIFF: https://github.com/llvm/llvm-project/commit/c0c1c3cf93ec089887944027ebfa95da03f8040b.diff
LOG: Revert "[InstrProfiling] Emit bias variable eagerly"
This reverts commit 6660cec568504df47d9becb0c552c20577880df8 since
it was superseded by https://reviews.llvm.org/D98061.
Added:
Modified:
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Removed:
llvm/test/Instrumentation/InstrProfiling/bias-var.ll
################################################################################
diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
index b1764b64c8a3a..94b156f3b137b 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -121,9 +121,6 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
/// Create a static initializer for our data, on platforms that need it,
/// and for any profile output file that was specified.
void emitInitialization();
-
- // Emit the variable used for runtime counter relocation.
- bool emitBiasVar();
};
} // end namespace llvm
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 39f863fe2f768..9c931ded3db37 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -551,10 +551,6 @@ bool InstrProfiling::run(
// Emit the runtime hook even if no counters are present.
bool MadeChange = emitRuntimeHook();
- // Emit the bias variable in each module when counter relocation is enabled.
- if (isRuntimeCounterRelocationEnabled())
- MadeChange |= emitBiasVar();
-
// Improve compile time by avoiding linear scans when there is no work.
GlobalVariable *CoverageNamesVar =
M.getNamedGlobal(getCoverageUnusedNamesVarName());
@@ -697,6 +693,21 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
if (!LI) {
IRBuilder<> Builder(&I);
GlobalVariable *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()));
+ }
LI = Builder.CreateLoad(Int64Ty, Bias);
}
auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);
@@ -1183,26 +1194,3 @@ void InstrProfiling::emitInitialization() {
appendToGlobalCtors(*M, F, 0);
}
-
-bool InstrProfiling::emitBiasVar() {
- // Module already provided its own variable, nothin to do.
- if (M->getGlobalVariable(getInstrProfCounterBiasVarName()))
- return false;
-
- // 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.
- Type *Int64Ty = Type::getInt64Ty(M->getContext());
- auto *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()));
-
- return true;
-}
diff --git a/llvm/test/Instrumentation/InstrProfiling/bias-var.ll b/llvm/test/Instrumentation/InstrProfiling/bias-var.ll
deleted file mode 100644
index 354751ebfa236..0000000000000
--- a/llvm/test/Instrumentation/InstrProfiling/bias-var.ll
+++ /dev/null
@@ -1,6 +0,0 @@
-; RUN: opt < %s -S -instrprof -runtime-counter-relocation | FileCheck -check-prefixes=RELOC %s
-
-target triple = "x86_64-unknown-linux-gnu"
-
-; RELOC: $__llvm_profile_counter_bias = comdat any
-; RELOC: @__llvm_profile_counter_bias = linkonce_odr hidden global i64 0, comdat
More information about the llvm-commits
mailing list