Skip to content

Commit 4573c85

Browse files
committed
Revert "[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public) (#124301)"
This reverts commit 058d183 due to build failures (missing symbols when linking).
1 parent 4a1a697 commit 4573c85

File tree

21 files changed

+116
-74
lines changed

21 files changed

+116
-74
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- ConvertToSPIRVPass.h - Conversion to SPIR-V pass ---*- 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+
#ifndef MLIR_CONVERSION_CONVERTTOSPIRV_CONVERTTOSPIRVPASS_H
10+
#define MLIR_CONVERSION_CONVERTTOSPIRV_CONVERTTOSPIRVPASS_H
11+
12+
#include <memory>
13+
14+
namespace mlir {
15+
class Pass;
16+
17+
#define GEN_PASS_DECL_CONVERTTOSPIRVPASS
18+
#include "mlir/Conversion/Passes.h.inc"
19+
20+
} // namespace mlir
21+
22+
#endif // MLIR_CONVERSION_CONVERTTOSPIRV_CONVERTTOSPIRVPASS_H

mlir/include/mlir/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
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"
3334
#include "mlir/Conversion/FuncToEmitC/FuncToEmitCPass.h"
3435
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
3536
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ 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+
4271
//===----------------------------------------------------------------------===//
4372
// AffineToStandard
4473
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_subdirectory(ControlFlowToLLVM)
1919
add_subdirectory(ControlFlowToSCF)
2020
add_subdirectory(ControlFlowToSPIRV)
2121
add_subdirectory(ConvertToLLVM)
22+
add_subdirectory(ConvertToSPIRV)
2223
add_subdirectory(FuncToEmitC)
2324
add_subdirectory(FuncToLLVM)
2425
add_subdirectory(FuncToSPIRV)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
set(LLVM_OPTIONAL_SOURCES
2+
ConvertToSPIRVPass.cpp
3+
)
4+
5+
add_mlir_conversion_library(MLIRConvertToSPIRVPass
6+
ConvertToSPIRVPass.cpp
7+
8+
ADDITIONAL_HEADER_DIRS
9+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/ConvertToSPIRV
10+
11+
DEPENDS
12+
MLIRConversionPassIncGen
13+
14+
LINK_LIBS PUBLIC
15+
MLIRArithToSPIRV
16+
MLIRArithTransforms
17+
MLIRFuncToSPIRV
18+
MLIRGPUDialect
19+
MLIRGPUToSPIRV
20+
MLIRIndexToSPIRV
21+
MLIRIR
22+
MLIRMemRefToSPIRV
23+
MLIRPass
24+
MLIRRewrite
25+
MLIRSCFToSPIRV
26+
MLIRSPIRVConversion
27+
MLIRSPIRVDialect
28+
MLIRSPIRVTransforms
29+
MLIRSupport
30+
MLIRTransforms
31+
MLIRTransformUtils
32+
MLIRUBToSPIRV
33+
MLIRVectorDialect
34+
MLIRVectorToSPIRV
35+
MLIRVectorTransforms
36+
)

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

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
910
#include "mlir/Conversion/ArithToSPIRV/ArithToSPIRV.h"
1011
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRV.h"
1112
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
@@ -23,12 +24,16 @@
2324
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
2425
#include "mlir/IR/PatternMatch.h"
2526
#include "mlir/Pass/Pass.h"
26-
#include "mlir/Pass/PassOptions.h"
2727
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
2828
#include "mlir/Transforms/DialectConversion.h"
2929
#include <memory>
3030

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

3338
using namespace mlir;
3439

@@ -64,44 +69,9 @@ void populateConvertToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
6469
}
6570

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

10676
void runOnOperation() override {
10777
Operation *op = getOperation();
@@ -162,14 +132,3 @@ struct TestConvertToSPIRVPass final
162132
};
163133

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

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 -test-convert-to-spirv -cse %s | FileCheck %s
1+
// RUN: mlir-opt -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 -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -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 -test-convert-to-spirv="run-signature-conversion=false run-vector-unrolling=false" -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -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 -test-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 -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,

0 commit comments

Comments
 (0)