[PATCH] D36553: [InstCombine] Add a DEBUG_COUNTER to InstCombine to limit how many instructions are visited for debug

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 14:46:38 PDT 2017


craig.topper created this revision.

Sometimes it would be nice to stop InstCombine mid way through its combining to see the current IR. By using a debug counter we can place an upper limit on how many instructions to process.

The debug counter infrastructure also supports skipping some number of calls at the beginning as well, but that feels like it would generate very odd behavior with InstCombine.

I also wonder if we should change the DEBUG_COUNTER macro to have the semicolon outside like we do for STATISTIC. Since they are often going to appear at the top of a file near STATISTIC the inconsistency seems likely to cause people to add a semicolon after DEBUG_COUNTER anyway.


https://reviews.llvm.org/D36553

Files:
  lib/Transforms/InstCombine/InstructionCombining.cpp


Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -60,6 +60,7 @@
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Support/KnownBits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -79,6 +80,8 @@
 STATISTIC(NumExpand,    "Number of expansions");
 STATISTIC(NumFactor   , "Number of factorizations");
 STATISTIC(NumReassoc  , "Number of reassociations");
+DEBUG_COUNTER(VisitCounter, "instcombine-visit",
+              "Controls which instructions are visited");
 
 static cl::opt<bool>
 EnableExpensiveCombines("expensive-combines",
@@ -2882,6 +2885,9 @@
       continue;
     }
 
+    if (!DebugCounter::shouldExecute(VisitCounter))
+      continue;
+
     // Instruction isn't dead, see if we can constant propagate it.
     if (!I->use_empty() &&
         (I->getNumOperands() == 0 || isa<Constant>(I->getOperand(0)))) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36553.110481.patch
Type: text/x-patch
Size: 1180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/9a62cca0/attachment.bin>


More information about the llvm-commits mailing list