Skip to content

Commit c0c1c3c

Browse files
committed
Revert "[InstrProfiling] Emit bias variable eagerly"
This reverts commit 6660cec since it was superseded by https://reviews.llvm.org/D98061.
1 parent 97e41c0 commit c0c1c3c

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
121121
/// Create a static initializer for our data, on platforms that need it,
122122
/// and for any profile output file that was specified.
123123
void emitInitialization();
124-
125-
// Emit the variable used for runtime counter relocation.
126-
bool emitBiasVar();
127124
};
128125

129126
} // end namespace llvm

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,6 @@ bool InstrProfiling::run(
551551
// Emit the runtime hook even if no counters are present.
552552
bool MadeChange = emitRuntimeHook();
553553

554-
// Emit the bias variable in each module when counter relocation is enabled.
555-
if (isRuntimeCounterRelocationEnabled())
556-
MadeChange |= emitBiasVar();
557-
558554
// Improve compile time by avoiding linear scans when there is no work.
559555
GlobalVariable *CoverageNamesVar =
560556
M.getNamedGlobal(getCoverageUnusedNamesVarName());
@@ -697,6 +693,21 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
697693
if (!LI) {
698694
IRBuilder<> Builder(&I);
699695
GlobalVariable *Bias = M->getGlobalVariable(getInstrProfCounterBiasVarName());
696+
if (!Bias) {
697+
// Compiler must define this variable when runtime counter relocation
698+
// is being used. Runtime has a weak external reference that is used
699+
// to check whether that's the case or not.
700+
Bias = new GlobalVariable(*M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
701+
Constant::getNullValue(Int64Ty),
702+
getInstrProfCounterBiasVarName());
703+
Bias->setVisibility(GlobalVariable::HiddenVisibility);
704+
// A definition that's weak (linkonce_odr) without being in a COMDAT
705+
// section wouldn't lead to link errors, but it would lead to a dead
706+
// data word from every TU but one. Putting it in COMDAT ensures there
707+
// will be exactly one data slot in the link.
708+
if (TT.supportsCOMDAT())
709+
Bias->setComdat(M->getOrInsertComdat(Bias->getName()));
710+
}
700711
LI = Builder.CreateLoad(Int64Ty, Bias);
701712
}
702713
auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);
@@ -1183,26 +1194,3 @@ void InstrProfiling::emitInitialization() {
11831194

11841195
appendToGlobalCtors(*M, F, 0);
11851196
}
1186-
1187-
bool InstrProfiling::emitBiasVar() {
1188-
// Module already provided its own variable, nothin to do.
1189-
if (M->getGlobalVariable(getInstrProfCounterBiasVarName()))
1190-
return false;
1191-
1192-
// Compiler must define this variable when runtime counter relocation
1193-
// is being used. Runtime has a weak external reference that is used
1194-
// to check whether that's the case or not.
1195-
Type *Int64Ty = Type::getInt64Ty(M->getContext());
1196-
auto *Bias = new GlobalVariable(*M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
1197-
Constant::getNullValue(Int64Ty),
1198-
getInstrProfCounterBiasVarName());
1199-
Bias->setVisibility(GlobalVariable::HiddenVisibility);
1200-
// A definition that's weak (linkonce_odr) without being in a COMDAT
1201-
// section wouldn't lead to link errors, but it would lead to a dead
1202-
// data word from every TU but one. Putting it in COMDAT ensures there
1203-
// will be exactly one data slot in the link.
1204-
if (TT.supportsCOMDAT())
1205-
Bias->setComdat(M->getOrInsertComdat(Bias->getName()));
1206-
1207-
return true;
1208-
}

llvm/test/Instrumentation/InstrProfiling/bias-var.ll

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)