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

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 13:14:39 PST 2016


xur updated this revision to Diff 45026.
xur added a comment.

Changed the patch based on comments.


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,11 +137,30 @@
   // 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) {
+    InstrProfIncrementInst *FirstProfIncInst = nullptr;
+    bool hasValueInstrumentation = false;
     for (BasicBlock &BB : F)
-      for (auto I = BB.begin(), E = BB.end(); I != E;)
-        if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I++))
+      for (auto I = BB.begin(), E = BB.end(); I != E; I++)
+        if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I)) {
           computeNumValueSiteCounts(Ind);
+          hasValueInstrumentation = true;
+        }
+        else if (FirstProfIncInst == nullptr)
+          FirstProfIncInst = dyn_cast<InstrProfIncrementInst>(I);
+
+    if (hasValueInstrumentation) {
+      assert (FirstProfIncInst != nullptr);
+      getOrCreateRegionCounters(FirstProfIncInst);
+    }
+  }
 
   for (Function &F : M)
     for (BasicBlock &BB : F)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16015.45026.patch
Type: text/x-patch
Size: 1769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160115/8ccbdac8/attachment.bin>


More information about the llvm-commits mailing list