[PATCH] D50094: Introduce DebugCounter into ConstProp pass

Zhizhou Yang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 31 11:29:26 PDT 2018


zhizhouy created this revision.
zhizhouy added a reviewer: davide.

This patch introduces DebugCounter into ConstProp pass at per-transformation level.

It will provide an option to skip first n or stop after n transformations for the whole ConstProp pass.

This will make debug easier for the pass, also providing chance to do transformation level bisecting.


Repository:
  rL LLVM

https://reviews.llvm.org/D50094

Files:
  lib/Transforms/Scalar/ConstantProp.cpp
  test/Other/debugcounter-constprop.ll


Index: test/Other/debugcounter-constprop.ll
===================================================================
--- /dev/null
+++ test/Other/debugcounter-constprop.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -constprop -S -debug-counter=constprop-transform-skip=1,constprop-transform-count=1 | FileCheck %s
+;; Test that, with debug counters on, we will skip the first constprop optimization opportunity, perform next 1,
+;; and ignore all the others left.
+
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  %add1 = add i32 1, 2
+; CHECK-NEXT:  %add2 = add i32 %add1, 2
+; CHECK-NEXT:  %add4 = add i32 4, 2
+; CHECK-NEXT:  %add5 = add i32 3, 2
+; CHECK-NEXT:  %add6 = add i32 %add5, 2
+define void @test() {
+    %add1 = add i32 1, 2
+    %add2 = add i32 %add1, 2
+    %add3 = add i32 2, 2
+    %add4 = add i32 %add3, 2
+    %add5 = add i32 3, 2
+    %add6 = add i32 %add5, 2
+    ret void
+}
\ No newline at end of file
Index: lib/Transforms/Scalar/ConstantProp.cpp
===================================================================
--- lib/Transforms/Scalar/ConstantProp.cpp
+++ lib/Transforms/Scalar/ConstantProp.cpp
@@ -26,13 +26,16 @@
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Transforms/Scalar.h"
 #include <set>
 using namespace llvm;
 
 #define DEBUG_TYPE "constprop"
 
 STATISTIC(NumInstKilled, "Number of instructions killed");
+DEBUG_COUNTER(CPCounter, "constprop-transform",
+              "Controls which instructions are killed");
 
 namespace {
   struct ConstantPropagation : public FunctionPass {
@@ -81,6 +84,9 @@
 
     if (!I->use_empty())                 // Don't muck with dead instructions...
       if (Constant *C = ConstantFoldInstruction(I, DL, TLI)) {
+        if (!DebugCounter::shouldExecute(CPCounter))
+          continue;
+
         // Add all of the users of this instruction to the worklist, they might
         // be constant propagatable now...
         for (User *U : I->users())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50094.158349.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180731/5b71205f/attachment.bin>


More information about the llvm-commits mailing list