Skip to content

Commit

Permalink
Revert "[InstrProfiling] Emit bias variable eagerly"
Browse files Browse the repository at this point in the history
This reverts commit 6660cec since
it was superseded by https://reviews.llvm.org/D98061.
  • Loading branch information
petrhosek committed Aug 11, 2021
1 parent 97e41c0 commit c0c1c3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
3 changes: 0 additions & 3 deletions llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
Expand Up @@ -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
Expand Down
42 changes: 15 additions & 27 deletions llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
6 changes: 0 additions & 6 deletions llvm/test/Instrumentation/InstrProfiling/bias-var.ll

This file was deleted.

0 comments on commit c0c1c3c

Please sign in to comment.