[PATCH] D53440: [LoopUnroll] allow customization for new-pass-manager version of LoopUnroll

Fedor Sergeev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 19 09:55:33 PDT 2018


fedor.sergeev created this revision.
fedor.sergeev added reviewers: chandlerc, tejohnson, silvas, haicheng, danielcdh.
Herald added subscribers: dmgreen, zzheng.

Unlike its legacy counterpart new pass manager's LoopUnrollPass does
not provide any means to select which flavors of unroll to run
(runtime, peeling, partial), relying on global defaults.

In some cases having ability to run a restricted LoopUnroll that
does more than LoopFullUnroll is needed.

Provide additional selectors to control desired optional behavior.
Intended to be called upon a pass just before adding it to a pass manager.


Repository:
  rL LLVM

https://reviews.llvm.org/D53440

Files:
  include/llvm/Transforms/Scalar/LoopUnrollPass.h
  lib/Transforms/Scalar/LoopUnrollPass.cpp


Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1333,23 +1333,22 @@
     Loop *ParentL = L.getParentLoop();
 #endif
 
-    // The API here is quite complex to call, but there are only two interesting
-    // states we support: partial and full (or "simple") unrolling. However, to
-    // enable these things we actually pass "None" in for the optional to avoid
-    // providing an explicit choice.
-    Optional<bool> AllowPartialParam, RuntimeParam, UpperBoundParam,
-        AllowPeeling;
+
     // Check if the profile summary indicates that the profiled application
     // has a huge working set size, in which case we disable peeling to avoid
     // bloating it further.
     if (PSI && PSI->hasHugeWorkingSetSize())
       AllowPeeling = false;
     std::string LoopName = L.getName();
+    // The API here is quite complex to call and we allow to select some
+    // flavors of unrolling during construction time (by setting Allow* values).
+    // As soon as the caller does not care we pass None for the corresponding
+    // optional to avoid providing an explicit choice.
     LoopUnrollResult Result =
         tryToUnrollLoop(&L, DT, &LI, SE, TTI, AC, ORE,
                         /*PreserveLCSSA*/ true, OptLevel, /*Count*/ None,
-                        /*Threshold*/ None, AllowPartialParam, RuntimeParam,
-                        UpperBoundParam, AllowPeeling);
+                        /*Threshold*/ None, AllowPartial, AllowRuntime,
+                        AllowUpperBound, AllowPeeling);
     Changed |= Result != LoopUnrollResult::Unmodified;
 
     // The parent must not be damaged by unrolling!
Index: include/llvm/Transforms/Scalar/LoopUnrollPass.h
===================================================================
--- include/llvm/Transforms/Scalar/LoopUnrollPass.h
+++ include/llvm/Transforms/Scalar/LoopUnrollPass.h
@@ -10,6 +10,7 @@
 #ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
 #define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/Analysis/LoopAnalysisManager.h"
 #include "llvm/IR/PassManager.h"
 
@@ -35,12 +36,33 @@
 /// It will also put loops into canonical form (simplified and LCSSA).
 class LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> {
   const int OptLevel;
+  Optional<bool> AllowPartial;
+  Optional<bool> AllowRuntime;
+  Optional<bool> AllowPeeling;
+  Optional<bool> AllowUpperBound;
 
 public:
   /// This uses the target information (or flags) to control the thresholds for
   /// different unrolling stategies but supports all of them.
   explicit LoopUnrollPass(int OptLevel = 2) : OptLevel(OptLevel) {}
 
+  /// Selector for the optional behavior - Partial unrolling.
+  /// Call with \p Partial being true to enable, false to disable.
+  /// Without calling this a global default will be used.
+  LoopUnrollPass&& setPartial(bool Partial) && { AllowPartial = Partial; return std::move(*this); }
+  /// Selector for the optional behavior - Runtime unrolling.
+  /// Call with \p Runtime being true to enable, false to disable.
+  /// Without calling this a global default will be used.
+  LoopUnrollPass&& setRuntime(bool Runtime) && { AllowRuntime = Runtime; return std::move(*this); }
+  /// Selector for the optional behavior - Peeling.
+  /// Call with \p Peeling being true to enable, false to disable.
+  /// Without calling this a global default will be used.
+  LoopUnrollPass&& setPeeling(bool Peeling) && { AllowPeeling = Peeling; return std::move(*this); }
+  /// Selector for the optional behavior - UpperBound.
+  /// Call with \p UpperBound being true to enable, false to disable.
+  /// Without calling this a global default will be used.
+  LoopUnrollPass&& setUpperBound(bool UpperBound) && { AllowUpperBound = UpperBound; return std::move(*this); }
+
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53440.170212.patch
Type: text/x-patch
Size: 4021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181019/526ea7df/attachment.bin>


More information about the llvm-commits mailing list