Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SandboxVec] User-defined pass pipeline #108625

Merged
merged 1 commit into from
Sep 13, 2024
Merged

[SandboxVec] User-defined pass pipeline #108625

merged 1 commit into from
Sep 13, 2024

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Sep 13, 2024

This patch adds support for a user-defined pass-pipeline that overrides the default pipeline of the vectorizer.
This will commonly be used by lit tests.

This patch adds support for a user-defined pass-pipeline that overrides the
default pipeline of the vectorizer.
This will commonly be used by lit tests.
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-llvm-transforms

Author: vporpo (vporpo)

Changes

This patch adds support for a user-defined pass-pipeline that overrides the default pipeline of the vectorizer.
This will commonly be used by lit tests.


Full diff: /~https://github.com/llvm/llvm-project/pull/108625.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp (+20-6)
  • (added) llvm/test/Transforms/SandboxVectorizer/user_pass_pipeline.ll (+12)
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
index 562cb5149e3198..161d300e6e9f2e 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -22,6 +22,14 @@ cl::opt<bool>
     PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
                       cl::desc("Prints the pass pipeline and returns."));
 
+/// A magic string for the default pass pipeline.
+const char *DefaultPipelineMagicStr = "*";
+
+cl::opt<std::string> UserDefinedPassPipeline(
+    "sbvec-passes", cl::init(DefaultPipelineMagicStr), cl::Hidden,
+    cl::desc("Comma-separated list of vectorizer passes. If not set "
+             "we run the predefined pipeline."));
+
 PreservedAnalyses SandboxVectorizerPass::run(Function &F,
                                              FunctionAnalysisManager &AM) {
   TTI = &AM.getResult<TargetIRAnalysis>(F);
@@ -53,20 +61,26 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
   sandboxir::Function &F = *Ctx.createFunction(&LLVMF);
   // Create the passes and register them with the PassRegistry.
   sandboxir::PassRegistry PR;
-  auto &PM = static_cast<sandboxir::FunctionPassManager &>(
-      PR.registerPass(std::make_unique<sandboxir::FunctionPassManager>("pm")));
   auto &BottomUpVecPass = static_cast<sandboxir::FunctionPass &>(
       PR.registerPass(std::make_unique<sandboxir::BottomUpVec>()));
 
-  // Create the default pass pipeline.
-  PM.addPass(&BottomUpVecPass);
+  sandboxir::FunctionPassManager *PM = nullptr;
+  if (UserDefinedPassPipeline == DefaultPipelineMagicStr) {
+    // Create the default pass pipeline.
+    PM = &static_cast<sandboxir::FunctionPassManager &>(PR.registerPass(
+        std::make_unique<sandboxir::FunctionPassManager>("pm")));
+    PM->addPass(&BottomUpVecPass);
+  } else {
+    // Create the user-defined pipeline.
+    PM = &PR.parseAndCreatePassPipeline(UserDefinedPassPipeline);
+  }
 
   if (PrintPassPipeline) {
-    PM.printPipeline(outs());
+    PM->printPipeline(outs());
     return false;
   }
 
   // Run the pass pipeline.
-  bool Change = PM.runOnFunction(F);
+  bool Change = PM->runOnFunction(F);
   return Change;
 }
diff --git a/llvm/test/Transforms/SandboxVectorizer/user_pass_pipeline.ll b/llvm/test/Transforms/SandboxVectorizer/user_pass_pipeline.ll
new file mode 100644
index 00000000000000..2879fbba1b9c00
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/user_pass_pipeline.ll
@@ -0,0 +1,12 @@
+; RUN: opt -passes=sandbox-vectorizer -sbvec-print-pass-pipeline -sbvec-passes=bottom-up-vec,bottom-up-vec %s -disable-output | FileCheck %s
+
+; !!!WARNING!!! This won't get updated by update_test_checks.py !
+
+; This checks the user defined pass pipeline.
+define void @pipeline() {
+; CHECK: pm
+; CHECK: bottom-up-vec
+; CHECK: bottom-up-vec
+; CHECK-EMPTY:
+  ret void
+}

@vporpo
Copy link
Contributor Author

vporpo commented Sep 13, 2024

The windows bot failure is not related to this patch, so I will go ahead and merge it.

@vporpo vporpo merged commit 5130f32 into llvm:main Sep 13, 2024
8 of 10 checks passed
@tschuett
Copy link

For the following patches please make both bots green.

"The windows bot failure is not related to this patch," can get you in trouble.

@vporpo
Copy link
Contributor Author

vporpo commented Sep 13, 2024

For the following patches please make both bots green.
"The windows bot failure is not related to this patch," can get you in trouble.

These changes are very localized and I am testing them extensively locally. If there is indeed an issue the post-commit bots will notify me and I will revert the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants