Skip to content

Commit 39f2d2f

Browse files
authored
[SandboxVec] Boilerplate for vectorization passes (llvm#108603)
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.
1 parent 9f738c8 commit 39f2d2f

File tree

7 files changed

+86
-3
lines changed

7 files changed

+86
-3
lines changed

llvm/include/llvm/SandboxIR/Pass.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Pass {
4040
virtual void print(raw_ostream &OS) const { OS << Name; }
4141
LLVM_DUMP_METHOD virtual void dump() const;
4242
#endif
43+
/// Similar to print() but adds a newline. Used for testing.
44+
void printPipeline(raw_ostream &OS) const { OS << Name << "\n"; }
4345
};
4446

4547
/// A pass that runs on a sandbox::Function.

llvm/include/llvm/SandboxIR/PassManager.h

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PassManager : public ParentPass {
4949
void print(raw_ostream &OS) const override {
5050
OS << this->getName();
5151
OS << "(";
52+
// TODO: This should call Pass->print(OS) because Pass may be a PM.
5253
interleave(Passes, OS, [&OS](auto *Pass) { OS << Pass->getName(); }, ",");
5354
OS << ")";
5455
}
@@ -57,6 +58,12 @@ class PassManager : public ParentPass {
5758
dbgs() << "\n";
5859
}
5960
#endif
61+
/// Similar to print() but prints one pass per line. Used for testing.
62+
void printPipeline(raw_ostream &OS) const {
63+
OS << this->getName() << "\n";
64+
for (const auto &PassPtr : Passes)
65+
PassPtr->printPipeline(OS);
66+
}
6067
};
6168

6269
class FunctionPassManager final
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- BottomUpVec.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// A Bottom-Up Vectorizer pass.
10+
//
11+
12+
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H
13+
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H
14+
15+
#include "llvm/SandboxIR/Pass.h"
16+
17+
namespace llvm::sandboxir {
18+
19+
class BottomUpVec final : public FunctionPass {
20+
21+
public:
22+
BottomUpVec() : FunctionPass("bottom-up-vec") {}
23+
bool runOnFunction(Function &F) final;
24+
};
25+
26+
} // namespace llvm::sandboxir
27+
28+
#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H

llvm/lib/Transforms/Vectorize/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_llvm_component_library(LLVMVectorize
33
LoopIdiomVectorize.cpp
44
LoopVectorizationLegality.cpp
55
LoopVectorize.cpp
6+
SandboxVectorizer/Passes/BottomUpVec.cpp
67
SandboxVectorizer/SandboxVectorizer.cpp
78
SLPVectorizer.cpp
89
Vectorize.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===- BottomUpVec.cpp - A bottom-up vectorizer pass ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
10+
11+
using namespace llvm::sandboxir;
12+
13+
bool BottomUpVec::runOnFunction(Function &F) { return false; }

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88

99
#include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.h"
1010
#include "llvm/Analysis/TargetTransformInfo.h"
11+
#include "llvm/SandboxIR/PassManager.h"
1112
#include "llvm/SandboxIR/SandboxIR.h"
13+
#include "llvm/Support/CommandLine.h"
14+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
1215

1316
using namespace llvm;
1417

1518
#define SV_NAME "sandbox-vectorizer"
1619
#define DEBUG_TYPE SV_NAME
1720

21+
cl::opt<bool>
22+
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
23+
cl::desc("Prints the pass pipeline and returns."));
24+
1825
PreservedAnalyses SandboxVectorizerPass::run(Function &F,
1926
FunctionAnalysisManager &AM) {
2027
TTI = &AM.getResult<TargetIRAnalysis>(F);
@@ -44,8 +51,22 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
4451
sandboxir::Context Ctx(LLVMF.getContext());
4552
// Create SandboxIR for `LLVMF`.
4653
sandboxir::Function &F = *Ctx.createFunction(&LLVMF);
47-
// TODO: Initialize SBVec Pass Manager
48-
(void)F;
54+
// Create the passes and register them with the PassRegistry.
55+
sandboxir::PassRegistry PR;
56+
auto &PM = static_cast<sandboxir::FunctionPassManager &>(
57+
PR.registerPass(std::make_unique<sandboxir::FunctionPassManager>("pm")));
58+
auto &BottomUpVecPass = static_cast<sandboxir::FunctionPass &>(
59+
PR.registerPass(std::make_unique<sandboxir::BottomUpVec>()));
60+
61+
// Create the default pass pipeline.
62+
PM.addPass(&BottomUpVecPass);
63+
64+
if (PrintPassPipeline) {
65+
PM.printPipeline(outs());
66+
return false;
67+
}
4968

50-
return false;
69+
// Run the pass pipeline.
70+
bool Change = PM.runOnFunction(F);
71+
return Change;
5172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: opt -passes=sandbox-vectorizer -sbvec-print-pass-pipeline %s -disable-output | FileCheck %s
2+
3+
; !!!WARNING!!! This won't get updated by update_test_checks.py !
4+
5+
; This checks the default pass pipeline for the sandbox vectorizer.
6+
define void @pipeline() {
7+
; CHECK: pm
8+
; CHECK: bottom-up-vec
9+
; CHECK-EMPTY:
10+
ret void
11+
}

0 commit comments

Comments
 (0)