@@ -278,6 +278,10 @@ class InstrLowerer final {
278
278
// / using the index represented by the a temp value into a bitmap.
279
279
void lowerMCDCTestVectorBitmapUpdate (InstrProfMCDCTVBitmapUpdate *Ins);
280
280
281
+ // / Get the Bias value for data to access mmap-ed area.
282
+ // / Create it if it hasn't been seen.
283
+ GlobalVariable *getOrCreateBiasVar (StringRef VarName);
284
+
281
285
// / Compute the address of the counter value that this profiling instruction
282
286
// / acts on.
283
287
Value *getCounterAddress (InstrProfCntrInstBase *I);
@@ -885,6 +889,29 @@ void InstrLowerer::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
885
889
Ind->eraseFromParent ();
886
890
}
887
891
892
+ GlobalVariable *InstrLowerer::getOrCreateBiasVar (StringRef VarName) {
893
+ GlobalVariable *Bias = M.getGlobalVariable (VarName);
894
+ if (Bias)
895
+ return Bias;
896
+
897
+ Type *Int64Ty = Type::getInt64Ty (M.getContext ());
898
+
899
+ // Compiler must define this variable when runtime counter relocation
900
+ // is being used. Runtime has a weak external reference that is used
901
+ // to check whether that's the case or not.
902
+ Bias = new GlobalVariable (M, Int64Ty, false , GlobalValue::LinkOnceODRLinkage,
903
+ Constant::getNullValue (Int64Ty), VarName);
904
+ Bias->setVisibility (GlobalVariable::HiddenVisibility);
905
+ // A definition that's weak (linkonce_odr) without being in a COMDAT
906
+ // section wouldn't lead to link errors, but it would lead to a dead
907
+ // data word from every TU but one. Putting it in COMDAT ensures there
908
+ // will be exactly one data slot in the link.
909
+ if (TT.supportsCOMDAT ())
910
+ Bias->setComdat (M.getOrInsertComdat (VarName));
911
+
912
+ return Bias;
913
+ }
914
+
888
915
Value *InstrLowerer::getCounterAddress (InstrProfCntrInstBase *I) {
889
916
auto *Counters = getOrCreateRegionCounters (I);
890
917
IRBuilder<> Builder (I);
@@ -903,22 +930,7 @@ Value *InstrLowerer::getCounterAddress(InstrProfCntrInstBase *I) {
903
930
LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
904
931
if (!BiasLI) {
905
932
IRBuilder<> EntryBuilder (&Fn->getEntryBlock ().front ());
906
- auto *Bias = M.getGlobalVariable (getInstrProfCounterBiasVarName ());
907
- if (!Bias) {
908
- // Compiler must define this variable when runtime counter relocation
909
- // is being used. Runtime has a weak external reference that is used
910
- // to check whether that's the case or not.
911
- Bias = new GlobalVariable (
912
- M, Int64Ty, false , GlobalValue::LinkOnceODRLinkage,
913
- Constant::getNullValue (Int64Ty), getInstrProfCounterBiasVarName ());
914
- Bias->setVisibility (GlobalVariable::HiddenVisibility);
915
- // A definition that's weak (linkonce_odr) without being in a COMDAT
916
- // section wouldn't lead to link errors, but it would lead to a dead
917
- // data word from every TU but one. Putting it in COMDAT ensures there
918
- // will be exactly one data slot in the link.
919
- if (TT.supportsCOMDAT ())
920
- Bias->setComdat (M.getOrInsertComdat (Bias->getName ()));
921
- }
933
+ auto *Bias = getOrCreateBiasVar (getInstrProfCounterBiasVarName ());
922
934
BiasLI = EntryBuilder.CreateLoad (Int64Ty, Bias);
923
935
}
924
936
auto *Add = Builder.CreateAdd (Builder.CreatePtrToInt (Addr, Int64Ty), BiasLI);
0 commit comments