[llvm] r297892 - [PGO] Minor cleanup for count instruction in SelectInstVisitor.

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 14:05:25 PDT 2017


Author: xur
Date: Wed Mar 15 16:05:24 2017
New Revision: 297892

URL: http://llvm.org/viewvc/llvm-project?rev=297892&view=rev
Log:
[PGO] Minor cleanup for count instruction in SelectInstVisitor.

Summary:
NSIs can be double-counted by different operations in
SelectInstVisitor. Sink the the update to VM_counting mode only.
Also reset the value for each counting operation.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: xur, llvm-commits

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

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=297892&r1=297891&r2=297892&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Wed Mar 15 16:05:24 2017
@@ -200,6 +200,7 @@ struct SelectInstVisitor : public InstVi
   SelectInstVisitor(Function &Func) : F(Func) {}
 
   void countSelects(Function &Func) {
+    NSIs = 0;
     Mode = VM_counting;
     visit(Func);
   }
@@ -229,6 +230,8 @@ struct SelectInstVisitor : public InstVi
   void annotateOneSelectInst(SelectInst &SI);
   // Visit \p SI instruction and perform tasks according to visit mode.
   void visitSelectInst(SelectInst &SI);
+  // Return the number of select instructions. This needs be called after
+  // countSelects().
   unsigned getNumOfSelectInsts() const { return NSIs; }
 };
 
@@ -1058,9 +1061,9 @@ void SelectInstVisitor::visitSelectInst(
   if (SI.getCondition()->getType()->isVectorTy())
     return;
 
-  NSIs++;
   switch (Mode) {
   case VM_counting:
+    NSIs++;
     return;
   case VM_instrument:
     instrumentOneSelectInst(SI);




More information about the llvm-commits mailing list