[PATCH] D16015: [PGO] Create the profile data variable before the lowering

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 8 15:21:04 PST 2016


xur created this revision.
xur added reviewers: davidxl, silvas, bogner.
xur added a subscriber: llvm-commits.

This patch creates the profile data variable before lowering the profile intrinsics (i.e. InstrProfIncrementInst and InstrProfValueProfileInst).

This is for IR level instrumentation. Lowering InstrProfValueProfileInst assumes the existing of profile data variable. For clang based instrumentation, we always see InstrProfIncrementInst before the first InstrProfValueProfileInst. But this is not true for IR level instrumeatnion (as we may not instrument the entry BB).


http://reviews.llvm.org/D16015

Files:
  lib/Transforms/Instrumentation/InstrProfiling.cpp

Index: lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -137,12 +137,34 @@
   // We did not know how many value sites there would be inside
   // the instrumented function. This is counting the number of instrumented
   // target value sites to enter it as field in the profile data variable.
-  for (Function &F : M)
+  //
+  // Also create the profile data variable -- do it here because there is no
+  // guarantee that a counter increment will be ahead of value profile
+  // instrumentation in IR level instrumentation where the profile data
+  // variable are needed in the lowering. We only need to see the first
+  // counter increment instruction to create the variable. This needs
+  // to be done after counting the number of value sites in this function.
+  for (Function &F : M) {
     for (BasicBlock &BB : F)
       for (auto I = BB.begin(), E = BB.end(); I != E;)
         if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I++))
           computeNumValueSiteCounts(Ind);
 
+    // Create the profile data variable.
+    bool CounterVarSet = false;
+    for (BasicBlock &BB : F) {
+      if (CounterVarSet) break;
+      for (auto I = BB.begin(), E = BB.end(); I != E;)
+        if (!CounterVarSet) {
+          if (auto *Inc = dyn_cast<InstrProfIncrementInst>(I++)) {
+            getOrCreateRegionCounters(Inc);
+            CounterVarSet = true;
+            break;
+          }
+        }
+    }
+  }
+
   for (Function &F : M)
     for (BasicBlock &BB : F)
       for (auto I = BB.begin(), E = BB.end(); I != E;) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16015.44382.patch
Type: text/x-patch
Size: 1718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160108/4430c459/attachment.bin>


More information about the llvm-commits mailing list