Skip to content

Commit 209eec2

Browse files
committed
Revert "[mlir][spirv] Make ConvertToSPIRVPass into a test pass (non-public) (llvm#124301)"
This reverts commit 058d183.
1 parent 08aadb4 commit 209eec2

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"
@@ -24,13 +25,17 @@
2425
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
2526
#include "mlir/IR/PatternMatch.h"
2627
#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 "test-convert-to-spirv"
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
3439

3540
using namespace mlir;
3641

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

6873
/// A pass to perform the SPIR-V conversion.
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 &) {}
74+
struct ConvertToSPIRVPass final
75+
: impl::ConvertToSPIRVPassBase<ConvertToSPIRVPass> {
76+
using ConvertToSPIRVPassBase::ConvertToSPIRVPassBase;
10777

10878
void runOnOperation() override {
10979
Operation *op = getOperation();
@@ -164,14 +134,3 @@ struct TestConvertToSPIRVPass final
164134
};
165135

166136
} // 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/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)