Skip to content

Commit 53fb2d9

Browse files
committed
[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public)
With the removal of mlir-vulkan-runner (as part of llvm#73457) in e7e3c45, this pass no longer has to be public (previously it had to be so the runner could use it). This commit makes it instead only available for use by mlir-opt.
1 parent 7ddeea3 commit 53fb2d9

19 files changed

+79
-87
lines changed

mlir/include/mlir/Conversion/Passes.td

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,6 @@ def ConvertToLLVMPass : Pass<"convert-to-llvm"> {
3939
];
4040
}
4141

42-
//===----------------------------------------------------------------------===//
43-
// ToSPIRV
44-
//===----------------------------------------------------------------------===//
45-
46-
def ConvertToSPIRVPass : Pass<"convert-to-spirv"> {
47-
let summary = "Convert to SPIR-V";
48-
let description = [{
49-
This is a generic pass to convert to SPIR-V.
50-
}];
51-
let dependentDialects = [
52-
"spirv::SPIRVDialect",
53-
"vector::VectorDialect",
54-
];
55-
let options = [
56-
Option<"runSignatureConversion", "run-signature-conversion", "bool",
57-
/*default=*/"true",
58-
"Run function signature conversion to convert vector types">,
59-
Option<"runVectorUnrolling", "run-vector-unrolling", "bool",
60-
/*default=*/"true",
61-
"Run vector unrolling to convert vector types in function bodies">,
62-
Option<"convertGPUModules", "convert-gpu-modules", "bool",
63-
/*default=*/"false",
64-
"Clone and convert GPU modules">,
65-
Option<"nestInGPUModule", "nest-in-gpu-module", "bool",
66-
/*default=*/"false",
67-
"Put converted SPIR-V module inside the gpu.module instead of alongside it.">,
68-
];
69-
}
70-
7142
//===----------------------------------------------------------------------===//
7243
// AffineToStandard
7344
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ add_subdirectory(ControlFlowToLLVM)
1919
add_subdirectory(ControlFlowToSCF)
2020
add_subdirectory(ControlFlowToSPIRV)
2121
add_subdirectory(ConvertToLLVM)
22-
add_subdirectory(ConvertToSPIRV)
2322
add_subdirectory(FuncToEmitC)
2423
add_subdirectory(FuncToLLVM)
2524
add_subdirectory(FuncToSPIRV)

mlir/lib/Conversion/ConvertToSPIRV/CMakeLists.txt

Lines changed: 0 additions & 36 deletions
This file was deleted.

mlir/test/Conversion/ConvertToSPIRV/argmax-kernel.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv -cse %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv -cse %s | FileCheck %s
22

33
module attributes {
44
gpu.container_module,

mlir/test/Conversion/ConvertToSPIRV/arith.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
//===----------------------------------------------------------------------===//
44
// arithmetic ops

mlir/test/Conversion/ConvertToSPIRV/combined.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @combined
44
// CHECK: %[[C0_F32:.*]] = spirv.Constant 0.000000e+00 : f32

mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules-nested.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="convert-gpu-modules=true nest-in-gpu-module=true run-signature-conversion=false run-vector-unrolling=false" %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="convert-gpu-modules=true nest-in-gpu-module=true run-signature-conversion=false run-vector-unrolling=false" %s | FileCheck %s
22

33
module attributes {
44
gpu.container_module,

mlir/test/Conversion/ConvertToSPIRV/convert-gpu-modules.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="convert-gpu-modules=true run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="convert-gpu-modules=true run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
module attributes {
44
gpu.container_module,

mlir/test/Conversion/ConvertToSPIRV/gpu.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv -split-input-file %s | FileCheck %s
22

33
module attributes {
44
gpu.container_module,

mlir/test/Conversion/ConvertToSPIRV/index.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @basic
44
func.func @basic(%a: index, %b: index) {

mlir/test/Conversion/ConvertToSPIRV/memref.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -cse %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -cse %s | FileCheck %s
22

33
module attributes {
44
spirv.target_env = #spirv.target_env<

mlir/test/Conversion/ConvertToSPIRV/scf.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @if_yield
44
// CHECK: %[[VAR:.*]] = spirv.Variable : !spirv.ptr<f32, Function>

mlir/test/Conversion/ConvertToSPIRV/simple.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @return_scalar
44
// CHECK-SAME: %[[ARG0:.*]]: i32

mlir/test/Conversion/ConvertToSPIRV/ub.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @ub
44
// CHECK: %[[UNDEF:.*]] = spirv.Undef : i32

mlir/test/Conversion/ConvertToSPIRV/vector.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
22

33
// CHECK-LABEL: @extract
44
// CHECK-SAME: %[[ARG:.+]]: vector<2xf32>

mlir/test/lib/Pass/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
22
# Exclude tests from libMLIR.so
33
add_mlir_library(MLIRTestPass
4+
TestConvertToSPIRVPass.cpp
45
TestDynamicPipeline.cpp
56
TestPassManager.cpp
67
TestSPIRVCPURunnerPipeline.cpp

mlir/lib/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.cpp renamed to mlir/test/lib/Pass/TestConvertToSPIRVPass.cpp

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
109
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
10+
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
1111
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
1212
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
1313
#include "mlir/Conversion/IndexToSPIRV/IndexToSPIRV.h"
@@ -25,12 +25,13 @@
2525
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
2626
#include "mlir/IR/PatternMatch.h"
2727
#include "mlir/Pass/Pass.h"
28+
#include "mlir/Pass/PassOptions.h"
2829
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
2930
#include "mlir/Transforms/DialectConversion.h"
3031
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
3132
#include <memory>
3233

33-
#define DEBUG_TYPE "convert-to-spirv"
34+
#define DEBUG_TYPE "test-convert-to-spirv"
3435

3536
namespace mlir {
3637
#define GEN_PASS_DEF_CONVERTTOSPIRVPASS
@@ -71,9 +72,44 @@ void populateConvertToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
7172
}
7273

7374
/// A pass to perform the SPIR-V conversion.
74-
struct ConvertToSPIRVPass final
75-
: impl::ConvertToSPIRVPassBase<ConvertToSPIRVPass> {
76-
using ConvertToSPIRVPassBase::ConvertToSPIRVPassBase;
75+
struct TestConvertToSPIRVPass final
76+
: PassWrapper<TestConvertToSPIRVPass, OperationPass<>> {
77+
Option<bool> runSignatureConversion{
78+
*this, "run-signature-conversion",
79+
llvm::cl::desc(
80+
"Run function signature conversion to convert vector types"),
81+
llvm::cl::init(true)};
82+
Option<bool> runVectorUnrolling{
83+
*this, "run-vector-unrolling",
84+
llvm::cl::desc(
85+
"Run vector unrolling to convert vector types in function bodies"),
86+
llvm::cl::init(true)};
87+
Option<bool> convertGPUModules{
88+
*this, "convert-gpu-modules",
89+
llvm::cl::desc("Clone and convert GPU modules"), llvm::cl::init(false)};
90+
Option<bool> nestInGPUModule{
91+
*this, "nest-in-gpu-module",
92+
llvm::cl::desc("Put converted SPIR-V module inside the gpu.module "
93+
"instead of alongside it."),
94+
llvm::cl::init(false)};
95+
96+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConvertToSPIRVPass)
97+
98+
StringRef getArgument() const final { return "test-convert-to-spirv"; }
99+
StringRef getDescription() const final {
100+
return "Conversion to SPIR-V pass only used for internal tests.";
101+
}
102+
void getDependentDialects(DialectRegistry &registry) const override {
103+
registry.insert<spirv::SPIRVDialect>();
104+
registry.insert<vector::VectorDialect>();
105+
}
106+
107+
TestConvertToSPIRVPass() = default;
108+
TestConvertToSPIRVPass(bool convertGPUModules, bool nestInGPUModule) {
109+
this->convertGPUModules = std::move(convertGPUModules);
110+
this->nestInGPUModule = std::move(nestInGPUModule);
111+
};
112+
TestConvertToSPIRVPass(const TestConvertToSPIRVPass &) {}
77113

78114
void runOnOperation() override {
79115
Operation *op = getOperation();
@@ -134,3 +170,16 @@ struct ConvertToSPIRVPass final
134170
};
135171

136172
} // namespace
173+
174+
namespace mlir {
175+
namespace test {
176+
void registerTestConvertToSPIRVPass() {
177+
PassRegistration<TestConvertToSPIRVPass>();
178+
}
179+
std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
180+
bool nestInGPUModule) {
181+
return std::make_unique<TestConvertToSPIRVPass>(convertGPUModules,
182+
nestInGPUModule);
183+
}
184+
} // namespace test
185+
} // namespace mlir

mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626

2727
using namespace mlir;
2828

29+
// Defined in the test directory, no public header.
30+
namespace mlir {
31+
namespace test {
32+
std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
33+
bool nestInGPUModule);
34+
}
35+
} // namespace mlir
36+
2937
namespace {
3038

3139
struct VulkanRunnerPipelineOptions
@@ -47,10 +55,8 @@ void buildTestVulkanRunnerPipeline(OpPassManager &passManager,
4755
"SPV_KHR_storage_buffer_storage_class");
4856
passManager.addPass(createGpuSPIRVAttachTarget(attachTargetOptions));
4957

50-
ConvertToSPIRVPassOptions convertToSPIRVOptions{};
51-
convertToSPIRVOptions.convertGPUModules = true;
52-
convertToSPIRVOptions.nestInGPUModule = true;
53-
passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
58+
passManager.addPass(test::createTestConvertToSPIRVPass(
59+
/*convertGPUModules=*/true, /*nestInGPUModule=*/true));
5460

5561
OpPassManager &spirvModulePM =
5662
passManager.nest<gpu::GPUModuleOp>().nest<spirv::ModuleOp>();

mlir/tools/mlir-opt/mlir-opt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void registerTestComposeSubView();
8787
void registerTestCompositePass();
8888
void registerTestConstantFold();
8989
void registerTestControlFlowSink();
90+
void registerTestConvertToSPIRVPass();
9091
void registerTestDataLayoutPropagation();
9192
void registerTestDataLayoutQuery();
9293
void registerTestDeadCodeAnalysisPass();
@@ -226,6 +227,7 @@ void registerTestPasses() {
226227
mlir::test::registerTestCompositePass();
227228
mlir::test::registerTestConstantFold();
228229
mlir::test::registerTestControlFlowSink();
230+
mlir::test::registerTestConvertToSPIRVPass();
229231
mlir::test::registerTestDataLayoutPropagation();
230232
mlir::test::registerTestDataLayoutQuery();
231233
mlir::test::registerTestDeadCodeAnalysisPass();

0 commit comments

Comments
 (0)