Skip to content

Commit 5130f32

Browse files
authored
[SandboxVec] User-defined pass pipeline (llvm#108625)
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.
1 parent ae3e825 commit 5130f32

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

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

+20-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ cl::opt<bool>
2222
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
2323
cl::desc("Prints the pass pipeline and returns."));
2424

25+
/// A magic string for the default pass pipeline.
26+
const char *DefaultPipelineMagicStr = "*";
27+
28+
cl::opt<std::string> UserDefinedPassPipeline(
29+
"sbvec-passes", cl::init(DefaultPipelineMagicStr), cl::Hidden,
30+
cl::desc("Comma-separated list of vectorizer passes. If not set "
31+
"we run the predefined pipeline."));
32+
2533
PreservedAnalyses SandboxVectorizerPass::run(Function &F,
2634
FunctionAnalysisManager &AM) {
2735
TTI = &AM.getResult<TargetIRAnalysis>(F);
@@ -53,20 +61,26 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
5361
sandboxir::Function &F = *Ctx.createFunction(&LLVMF);
5462
// Create the passes and register them with the PassRegistry.
5563
sandboxir::PassRegistry PR;
56-
auto &PM = static_cast<sandboxir::FunctionPassManager &>(
57-
PR.registerPass(std::make_unique<sandboxir::FunctionPassManager>("pm")));
5864
auto &BottomUpVecPass = static_cast<sandboxir::FunctionPass &>(
5965
PR.registerPass(std::make_unique<sandboxir::BottomUpVec>()));
6066

61-
// Create the default pass pipeline.
62-
PM.addPass(&BottomUpVecPass);
67+
sandboxir::FunctionPassManager *PM = nullptr;
68+
if (UserDefinedPassPipeline == DefaultPipelineMagicStr) {
69+
// Create the default pass pipeline.
70+
PM = &static_cast<sandboxir::FunctionPassManager &>(PR.registerPass(
71+
std::make_unique<sandboxir::FunctionPassManager>("pm")));
72+
PM->addPass(&BottomUpVecPass);
73+
} else {
74+
// Create the user-defined pipeline.
75+
PM = &PR.parseAndCreatePassPipeline(UserDefinedPassPipeline);
76+
}
6377

6478
if (PrintPassPipeline) {
65-
PM.printPipeline(outs());
79+
PM->printPipeline(outs());
6680
return false;
6781
}
6882

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

0 commit comments

Comments
 (0)