Skip to content

[SandboxVec] Boilerplate for vectorization passes #108603

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

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/SandboxIR/Pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/SandboxIR/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ")";
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
Expand Down Expand Up @@ -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 &BottomUpVecPass = static_cast<sandboxir::FunctionPass &>(
PR.registerPass(std::make_unique<sandboxir::BottomUpVec>()));

// 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;
}
11 changes: 11 additions & 0 deletions llvm/test/Transforms/SandboxVectorizer/default_pass_pipeline.ll
Original file line number Diff line number Diff line change
@@ -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
}
Loading