[llvm] 127d3ab - [Instrumentation] Set hidden visibility for the bias variable

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 12:07:10 PST 2020


Author: Petr Hosek
Date: 2020-01-28T12:07:03-08:00
New Revision: 127d3abf25b309f56575118530f8f6df08d9e843

URL: https://github.com/llvm/llvm-project/commit/127d3abf25b309f56575118530f8f6df08d9e843
DIFF: https://github.com/llvm/llvm-project/commit/127d3abf25b309f56575118530f8f6df08d9e843.diff

LOG: [Instrumentation] Set hidden visibility for the bias variable

We have to avoid using a GOT relocation to access the bias variable,
setting the hidden visibility achieves that.

Differential Revision: https://reviews.llvm.org/D73529

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
    llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 290e155ad9cc..292ab89433cb 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -686,10 +686,12 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
       IRBuilder<> Builder(&I);
       Type *Int64Ty = Type::getInt64Ty(M->getContext());
       GlobalVariable *Bias = M->getGlobalVariable(getInstrProfCounterBiasVarName());
-      if (!Bias)
+      if (!Bias) {
         Bias = new GlobalVariable(*M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
                                   Constant::getNullValue(Int64Ty),
                                   getInstrProfCounterBiasVarName());
+        Bias->setVisibility(GlobalVariable::HiddenVisibility);
+      }
       LI = Builder.CreateLoad(Int64Ty, Bias);
     }
     auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);

diff  --git a/llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll b/llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
index afe5ff68724b..52065921bd76 100644
--- a/llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
+++ b/llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
@@ -4,7 +4,7 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 @__profn_foo = hidden constant [3 x i8] c"foo"
-; RELOC: @__llvm_profile_counter_bias = linkonce_odr global i64 0
+; RELOC: @__llvm_profile_counter_bias = linkonce_odr hidden global i64 0
 
 ; CHECK-LABEL: define void @foo
 ; CHECK-NEXT: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i64 0, i64 0)


        


More information about the llvm-commits mailing list