[PATCH] D153437: [opt] Exposing the parameters of LoopRotate to the -passes interface

Yann Girsberger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 21 08:48:52 PDT 2023


Quarub created this revision.
Quarub added reviewers: aeubanks, fhahn.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
Quarub requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There is a gap between running opt -Oz and running opt -passes="OZ_PASSES" where OZ_PASSES is taken from running opt -Oz -print-pipeline-passes.

One of the reasons causing this is that -Oz uses non-default setting for LoopRotate but LoopRotate does not expose its settings when printing the pipeline.

This commit fixes by exposing LoopRotates parameters.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153437

Files:
  llvm/include/llvm/Transforms/Scalar/LoopRotation.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Scalar/LoopRotation.cpp


Index: llvm/lib/Transforms/Scalar/LoopRotation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopRotation.cpp
+++ llvm/lib/Transforms/Scalar/LoopRotation.cpp
@@ -43,6 +43,21 @@
     : EnableHeaderDuplication(EnableHeaderDuplication),
       PrepareForLTO(PrepareForLTO) {}
 
+void LoopRotatePass::printPipeline(
+    raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
+  static_cast<PassInfoMixin<LoopRotatePass> *>(this)->printPipeline(
+      OS, MapClassName2PassName);
+  OS << "<";
+  if (!EnableHeaderDuplication)
+    OS << "no-";
+  OS << "header-duplication;";
+
+  if (!PrepareForLTO)
+    OS << "no-";
+  OS << "prepare-for-lto";
+  OS << ">";
+}
+
 PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM,
                                       LoopStandardAnalysisResults &AR,
                                       LPMUpdater &) {
Index: llvm/lib/Passes/PassRegistry.def
===================================================================
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -565,7 +565,6 @@
 LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
 LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
 LOOP_PASS("loop-instsimplify", LoopInstSimplifyPass())
-LOOP_PASS("loop-rotate", LoopRotatePass())
 LOOP_PASS("no-op-loop", NoOpLoopPass())
 LOOP_PASS("print", PrintLoopPass(dbgs()))
 LOOP_PASS("loop-deletion", LoopDeletionPass())
@@ -608,4 +607,12 @@
                       },
                       parseLICMOptions,
                       "allowspeculation");
+
+LOOP_PASS_WITH_PARAMS("loop-rotate",
+                      "LoopRotatePass",
+                      [](std::pair<bool, bool> Params) {
+                        return LoopRotatePass(Params.first, Params.second);
+                      },
+                      parseLoopRotateOptions,
+                      "no-header-duplication;header-duplication;no-prepare-for-lto;prepare-for-lto")
 #undef LOOP_PASS_WITH_PARAMS
Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -897,6 +897,26 @@
   return Result;
 }
 
+Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
+  std::pair<bool, bool> Result = {false, false};
+  while (!Params.empty()) {
+    StringRef ParamName;
+    std::tie(ParamName, Params) = Params.split(';');
+
+    bool Enable = !ParamName.consume_front("no-");
+    if (ParamName == "header-duplication") {
+      Result.first = Enable;
+    } else if (ParamName == "prepare-for-lto") {
+      Result.second = Enable;
+    } else {
+      return make_error<StringError>(
+          formatv("invalid LoopRotate pass parameter '{0}' ", ParamName).str(),
+          inconvertibleErrorCode());
+    }
+  }
+  return Result;
+}
+
 Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
   bool Result = false;
   while (!Params.empty()) {
Index: llvm/include/llvm/Transforms/Scalar/LoopRotation.h
===================================================================
--- llvm/include/llvm/Transforms/Scalar/LoopRotation.h
+++ llvm/include/llvm/Transforms/Scalar/LoopRotation.h
@@ -28,6 +28,9 @@
   PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
                         LoopStandardAnalysisResults &AR, LPMUpdater &U);
 
+  void printPipeline(raw_ostream &OS,
+                     function_ref<StringRef(StringRef)> MapClassName2PassName);
+
 private:
   const bool EnableHeaderDuplication;
   const bool PrepareForLTO;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153437.533271.patch
Type: text/x-patch
Size: 3628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230621/ea5516dc/attachment.bin>


More information about the llvm-commits mailing list