Skip to content

Commit d912d33

Browse files
committed
[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public)
With the removal of mlir-vulkan-runner (as part of #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 d912d33

File tree

21 files changed

+74
-116
lines changed

21 files changed

+74
-116
lines changed

mlir/include/mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h

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

mlir/include/mlir/Conversion/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.h"
3131
#include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h"
3232
#include "mlir/Conversion/ConvertToLLVM/ToLLVMPass.h"
33-
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
3433
#include "mlir/Conversion/FuncToEmitC/FuncToEmitCPass.h"
3534
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
3635
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"

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: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
109
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
1110
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
1211
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
@@ -25,17 +24,13 @@
2524
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
2625
#include "mlir/IR/PatternMatch.h"
2726
#include "mlir/Pass/Pass.h"
27+
#include "mlir/Pass/PassOptions.h"
2828
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
2929
#include "mlir/Transforms/DialectConversion.h"
3030
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
3131
#include <memory>
3232

33-
#define DEBUG_TYPE "convert-to-spirv"
34-
35-
namespace mlir {
36-
#define GEN_PASS_DEF_CONVERTTOSPIRVPASS
37-
#include "mlir/Conversion/Passes.h.inc"
38-
} // namespace mlir
33+
#define DEBUG_TYPE "test-convert-to-spirv"
3934

4035
using namespace mlir;
4136

@@ -71,9 +66,44 @@ void populateConvertToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
7166
}
7267

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

78108
void runOnOperation() override {
79109
Operation *op = getOperation();
@@ -134,3 +164,14 @@ struct ConvertToSPIRVPass final
134164
};
135165

136166
} // namespace
167+
168+
namespace mlir::test {
169+
void registerTestConvertToSPIRVPass() {
170+
PassRegistration<TestConvertToSPIRVPass>();
171+
}
172+
std::unique_ptr<Pass> createTestConvertToSPIRVPass(bool convertGPUModules,
173+
bool nestInGPUModule) {
174+
return std::make_unique<TestConvertToSPIRVPass>(convertGPUModules,
175+
nestInGPUModule);
176+
}
177+
} // namespace mlir::test

mlir/test/lib/Pass/TestVulkanRunnerPipeline.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
1413
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
1514
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
1615
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
@@ -26,6 +25,12 @@
2625

2726
using namespace mlir;
2827

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

3136
struct VulkanRunnerPipelineOptions
@@ -47,10 +52,8 @@ void buildTestVulkanRunnerPipeline(OpPassManager &passManager,
4752
"SPV_KHR_storage_buffer_storage_class");
4853
passManager.addPass(createGpuSPIRVAttachTarget(attachTargetOptions));
4954

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

5558
OpPassManager &spirvModulePM =
5659
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)