[PATCH] D114319: [InstrProf][NFC] Save profile bias to function map

Ellis Hoag via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 08:06:30 PDT 2022


ellis updated this revision to Diff 429719.
ellis added a comment.

Rename function map and rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114319/new/

https://reviews.llvm.org/D114319

Files:
  llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp


Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -700,10 +700,9 @@
     Type *Int64Ty = Type::getInt64Ty(M->getContext());
     Type *Int64PtrTy = Type::getInt64PtrTy(M->getContext());
     Function *Fn = Inc->getParent()->getParent();
-    Instruction &I = Fn->getEntryBlock().front();
-    LoadInst *LI = dyn_cast<LoadInst>(&I);
-    if (!LI) {
-      IRBuilder<> Builder(&I);
+    LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
+    if (!BiasLI) {
+      IRBuilder<> Builder(&Fn->getEntryBlock().front());
       GlobalVariable *Bias =
           M->getGlobalVariable(getInstrProfCounterBiasVarName());
       if (!Bias) {
@@ -721,9 +720,10 @@
         if (TT.supportsCOMDAT())
           Bias->setComdat(M->getOrInsertComdat(Bias->getName()));
       }
-      LI = Builder.CreateLoad(Int64Ty, Bias);
+      BiasLI = Builder.CreateLoad(Int64Ty, Bias);
     }
-    auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);
+    auto *Add =
+        Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), BiasLI);
     Addr = Builder.CreateIntToPtr(Add, Int64PtrTy);
   }
 
Index: llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
===================================================================
--- llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
+++ llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
@@ -57,6 +57,9 @@
     }
   };
   DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
+  /// If runtime relocation is enabled, this maps functions to the load
+  /// instruction that produces the profile relocation bias.
+  DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
   std::vector<GlobalValue *> CompilerUsedVars;
   std::vector<GlobalValue *> UsedVars;
   std::vector<GlobalVariable *> ReferencedNames;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114319.429719.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/c6f3c7bb/attachment.bin>


More information about the llvm-commits mailing list