diff --git a/llvm/include/llvm/SandboxIR/Pass.h b/llvm/include/llvm/SandboxIR/Pass.h index caf1c70a84147..34776e3529e5c 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 2cc669a966e0b..98b56ba08c4eb 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/BottomUpVec.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h new file mode 100644 index 0000000000000..5b3d1a50aa1ec --- /dev/null +++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h @@ -0,0 +1,28 @@ +//===- BottomUpVec.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_BOTTOMUPVEC_H +#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H + +#include "llvm/SandboxIR/Pass.h" + +namespace llvm::sandboxir { + +class BottomUpVec final : public FunctionPass { + +public: + BottomUpVec() : FunctionPass("bottom-up-vec") {} + bool runOnFunction(Function &F) final; +}; + +} // namespace llvm::sandboxir + +#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H diff --git a/llvm/lib/Transforms/Vectorize/CMakeLists.txt b/llvm/lib/Transforms/Vectorize/CMakeLists.txt index 649faad48d71e..b11631350e8b4 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/BottomUpVec.cpp SandboxVectorizer/SandboxVectorizer.cpp SLPVectorizer.cpp Vectorize.cpp diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp new file mode 100644 index 0000000000000..c4870b70fd52d --- /dev/null +++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp @@ -0,0 +1,13 @@ +//===- BottomUpVec.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/BottomUpVec.h" + +using namespace llvm::sandboxir; + +bool BottomUpVec::runOnFunction(Function &F) { return false; } diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp index c5d2ebf515684..562cb5149e319 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/BottomUpVec.h" using namespace llvm; #define SV_NAME "sandbox-vectorizer" #define DEBUG_TYPE SV_NAME +cl::opt + 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(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( + PR.registerPass(std::make_unique("pm"))); + auto &BottomUpVecPass = static_cast( + PR.registerPass(std::make_unique())); + + // Create the default pass pipeline. + PM.addPass(&BottomUpVecPass); + + 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 0000000000000..5ccd64d9f487a --- /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: bottom-up-vec +; CHECK-EMPTY: + ret void +}