[PATCH] D50093: Introduce DebugCounter into PartiallyInlineLibCalls pass

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


zhizhouy created this revision.
zhizhouy added a reviewer: davide.
Herald added a subscriber: eraman.

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

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

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


Repository:
  rL LLVM

https://reviews.llvm.org/D50093

Files:
  lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
  test/Other/debugcounter-partiallyinlinelibcalls.ll


Index: test/Other/debugcounter-partiallyinlinelibcalls.ll
===================================================================
--- /dev/null
+++ test/Other/debugcounter-partiallyinlinelibcalls.ll
@@ -0,0 +1,43 @@
+; RUN: opt -S -debug-counter=partially-inline-libcalls-transform-skip=1,partially-inline-libcalls-transform-count=1 \
+; RUN:     -partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+;; Test that, with debug counters on, we will skip the first optimization opportunity, perform next 1,
+;; and ignore all the others left.
+
+define float @f1(float %val) {
+; CHECK-LABEL: @f1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]])
+; CHECK-NEXT:    ret float [[RES:%.*]]
+entry:
+  %res = tail call float @sqrtf(float %val)
+  ret float %res
+}
+
+define float @f2(float %val) {
+; CHECK-LABEL: @f2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #0
+; CHECK-NEXT:    [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00
+; CHECK-NEXT:    br i1 [[TMP0]], label [[ENTRY_SPLIT:%.*]], label [[CALL_SQRT:%.*]]
+; CHECK:       call.sqrt:
+; CHECK-NEXT:    [[TMP1:%.*]] = tail call float @sqrtf(float [[VAL]])
+; CHECK-NEXT:    br label [[ENTRY_SPLIT]]
+; CHECK:       entry.split:
+; CHECK-NEXT:    [[TMP2:%.*]] = phi float [ [[RES]], [[ENTRY:%.*]] ], [ [[TMP1]], [[CALL_SQRT]] ]
+; CHECK-NEXT:    ret float [[TMP2]]
+entry:
+  %res = tail call float @sqrtf(float %val)
+  ret float %res
+}
+
+define float @f3(float %val) {
+; CHECK-LABEL: @f3(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]])
+; CHECK-NEXT:    ret float [[RES:%.*]]
+entry:
+  %res = tail call float @sqrtf(float %val)
+  ret float %res
+}
+
+declare float @sqrtf(float)
Index: lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
===================================================================
--- lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -17,13 +17,16 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 
 using namespace llvm;
 
 #define DEBUG_TYPE "partially-inline-libcalls"
 
+DEBUG_COUNTER(PILCounter, "partially-inline-libcalls-transform",
+              "Controls transformations in partially-inline-libcalls");
 
 static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
                          BasicBlock &CurrBB, Function::iterator &BB,
@@ -33,6 +36,9 @@
   if (Call->onlyReadsMemory())
     return false;
 
+  if (!DebugCounter::shouldExecute(PILCounter))
+    return false;
+
   // Do the following transformation:
   //
   // (before)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50093.158347.patch
Type: text/x-patch
Size: 2878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180731/dd10b8b9/attachment.bin>


More information about the llvm-commits mailing list