[llvm] [SandboxVec] Boilerplate for vectorization passes (PR #108603)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 09:38:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: vporpo (vporpo)

<details>
<summary>Changes</summary>

This patch implements a new empty pass for the Bottom-up vectorizer and creates a pass pipeline that includes it.
The SandboxVectorizer LLVM pass runs the Sandbox IR pass pipeline.

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


7 Files Affected:

- (modified) llvm/include/llvm/SandboxIR/Pass.h (+2) 
- (modified) llvm/include/llvm/SandboxIR/PassManager.h (+7) 
- (added) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h (+28) 
- (modified) llvm/lib/Transforms/Vectorize/CMakeLists.txt (+1) 
- (added) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.cpp (+13) 
- (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp (+24-3) 
- (added) llvm/test/Transforms/SandboxVectorizer/default_pass_pipeline.ll (+11) 


``````````diff
diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h
index caf1c70a841477..34776e3529e5c6 100644
--- a/llvm/include/llvm/SandboxIR/Pass.h
+++ b/llvm/include/llvm/SandboxIR/Pass.h
@@ -40,6 +40,8 @@ class Pass {
   virtual void print(raw_ostream &OS) const { OS << Name; }
   LLVM_DUMP_METHOD virtual void dump() const;
 #endif
+  /// Similar to print() but adds a newline. Used for testing.
+  void printPipeline(raw_ostream &OS) const { OS << Name << "\n"; }
 };
 
 /// A pass that runs on a sandbox::Function.
diff --git a/llvm/include/llvm/SandboxIR/PassManager.h b/llvm/include/llvm/SandboxIR/PassManager.h
index 2cc669a966e0bc..98b56ba08c4eb6 100644
--- a/llvm/include/llvm/SandboxIR/PassManager.h
+++ b/llvm/include/llvm/SandboxIR/PassManager.h
@@ -49,6 +49,7 @@ class PassManager : public ParentPass {
   void print(raw_ostream &OS) const override {
     OS << this->getName();
     OS << "(";
+    // TODO: This should call Pass->print(OS) because Pass may be a PM.
     interleave(Passes, OS, [&OS](auto *Pass) { OS << Pass->getName(); }, ",");
     OS << ")";
   }
@@ -57,6 +58,12 @@ class PassManager : public ParentPass {
     dbgs() << "\n";
   }
 #endif
+  /// Similar to print() but prints one pass per line. Used for testing.
+  void printPipeline(raw_ostream &OS) const {
+    OS << this->getName() << "\n";
+    for (const auto &PassPtr : Passes)
+      PassPtr->printPipeline(OS);
+  }
 };
 
 class FunctionPassManager final
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h
new file mode 100644
index 00000000000000..ece4902984c855
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h
@@ -0,0 +1,28 @@
+//===- BoUpVec.h ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A Bottom-Up Vectorizer pass.
+//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOUPVEC_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOUPVEC_H
+
+#include "llvm/SandboxIR/Pass.h"
+
+namespace llvm::sandboxir {
+
+class BoUpVec final : public FunctionPass {
+
+public:
+  BoUpVec() : FunctionPass("boup-vec") {}
+  bool runOnFunction(Function &F) final;
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOUPVEC_H
diff --git a/llvm/lib/Transforms/Vectorize/CMakeLists.txt b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
index 649faad48d71e5..3e2a8582e00db3 100644
--- a/llvm/lib/Transforms/Vectorize/CMakeLists.txt
+++ b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
@@ -3,6 +3,7 @@ add_llvm_component_library(LLVMVectorize
   LoopIdiomVectorize.cpp
   LoopVectorizationLegality.cpp
   LoopVectorize.cpp
+  SandboxVectorizer/Passes/BoUpVec.cpp
   SandboxVectorizer/SandboxVectorizer.cpp
   SLPVectorizer.cpp
   Vectorize.cpp
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.cpp
new file mode 100644
index 00000000000000..422f86e81e0df9
--- /dev/null
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.cpp
@@ -0,0 +1,13 @@
+//===- BoUpVec.cpp - A bottom-up vectorizer pass ------------ -------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h"
+
+using namespace llvm::sandboxir;
+
+bool BoUpVec::runOnFunction(Function &F) { return false; }
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
index c5d2ebf5156843..1a5050a805c056 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -8,13 +8,20 @@
 
 #include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/SandboxIR/PassManager.h"
 #include "llvm/SandboxIR/SandboxIR.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BoUpVec.h"
 
 using namespace llvm;
 
 #define SV_NAME "sandbox-vectorizer"
 #define DEBUG_TYPE SV_NAME
 
+cl::opt<bool>
+    PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
+                      cl::desc("Prints the pass pipeline and returns."));
+
 PreservedAnalyses SandboxVectorizerPass::run(Function &F,
                                              FunctionAnalysisManager &AM) {
   TTI = &AM.getResult<TargetIRAnalysis>(F);
@@ -44,8 +51,22 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
   sandboxir::Context Ctx(LLVMF.getContext());
   // Create SandboxIR for `LLVMF`.
   sandboxir::Function &F = *Ctx.createFunction(&LLVMF);
-  // TODO: Initialize SBVec Pass Manager
-  (void)F;
+  // 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 &BoUpVecPass = static_cast<sandboxir::FunctionPass &>(
+      PR.registerPass(std::make_unique<sandboxir::BoUpVec>()));
+
+  // Create the default pass pipeline.
+  PM.addPass(&BoUpVecPass);
+
+  if (PrintPassPipeline) {
+    PM.printPipeline(outs());
+    return false;
+  }
 
-  return false;
+  // Run the pass pipeline.
+  bool Change = PM.runOnFunction(F);
+  return Change;
 }
diff --git a/llvm/test/Transforms/SandboxVectorizer/default_pass_pipeline.ll b/llvm/test/Transforms/SandboxVectorizer/default_pass_pipeline.ll
new file mode 100644
index 00000000000000..90ebb443496032
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/default_pass_pipeline.ll
@@ -0,0 +1,11 @@
+; RUN: opt -passes=sandbox-vectorizer -sbvec-print-pass-pipeline %s -disable-output | FileCheck %s
+
+; !!!WARNING!!! This won't get updated by update_test_checks.py !
+
+; This checks the default pass pipeline for the sandbox vectorizer.
+define void @pipeline() {
+; CHECK: pm
+; CHECK: boup-vec
+; CHECK-EMPTY:
+  ret void
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/108603


More information about the llvm-commits mailing list