[PATCH] D20655: Attach profile summary in IR based instrumentation pass

Easwaran Raman via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 16:03:35 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL270933: Attach profile summary in IR based instrumentation pass. (authored by eraman).

Changed prior to commit:
  http://reviews.llvm.org/D20655?vs=58542&id=58715#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20655

Files:
  llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/trunk/test/Transforms/PGOProfile/branch1.ll

Index: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -67,6 +67,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/ProfileData/InstrProfReader.h"
+#include "llvm/ProfileData/ProfileCommon.h"
 #include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/JamCRC.h"
@@ -478,6 +479,9 @@
   // Return the function hotness from the profile.
   FuncFreqAttr getFuncFreqAttr() const { return FreqAttr; }
 
+  // Return the profile record for this function;
+  InstrProfRecord &getProfileRecord() { return ProfileRecord; }
+
 private:
   Function &F;
   Module *M;
@@ -883,20 +887,23 @@
 
   std::vector<Function *> HotFunctions;
   std::vector<Function *> ColdFunctions;
+  InstrProfSummaryBuilder Builder(ProfileSummaryBuilder::DefaultCutoffs);
   for (auto &F : M) {
     if (F.isDeclaration())
       continue;
     auto *BPI = LookupBPI(F);
     auto *BFI = LookupBFI(F);
     PGOUseFunc Func(F, &M, BPI, BFI);
     setPGOCountOnFunc(Func, PGOReader.get());
+    if (!Func.getProfileRecord().Counts.empty())
+      Builder.addRecord(Func.getProfileRecord());
     PGOUseFunc::FuncFreqAttr FreqAttr = Func.getFuncFreqAttr();
     if (FreqAttr == PGOUseFunc::FFA_Cold)
       ColdFunctions.push_back(&F);
     else if (FreqAttr == PGOUseFunc::FFA_Hot)
       HotFunctions.push_back(&F);
   }
-
+  M.setProfileSummary(Builder.getSummary()->getMD(M.getContext()));
   // Set function hotness attribute from the profile.
   for (auto &F : HotFunctions) {
     F->addFnAttr(llvm::Attribute::InlineHint);
Index: llvm/trunk/test/Transforms/PGOProfile/branch1.ll
===================================================================
--- llvm/trunk/test/Transforms/PGOProfile/branch1.ll
+++ llvm/trunk/test/Transforms/PGOProfile/branch1.ll
@@ -28,7 +28,7 @@
   br i1 %cmp, label %if.then, label %if.end
 ; USE: br i1 %cmp, label %if.then, label %if.end
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
-; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
+; USE-DAG: ![[BW_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
 
 if.then:
 ; GEN: if.then:
@@ -42,3 +42,5 @@
   %retv = phi i32 [ %add, %if.then ], [ %i, %entry ]
   ret i32 %retv
 }
+; USE-DAG: {{![0-9]+}} = !{i32 1, !"ProfileSummary", {{![0-9]+}}}
+; USE-DAG: {{![0-9]+}} = !{!"DetailedSummary", {{![0-9]+}}}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20655.58715.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160526/7e84d3b6/attachment.bin>


More information about the llvm-commits mailing list