File tree 10 files changed +747
-3
lines changed 10 files changed +747
-3
lines changed Original file line number Diff line number Diff line change
1
+ // ===- IndexToSPIRV.h - Index to SPIRV dialect conversion -------*- 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_INDEXTOSPIRV_INDEXTOSPIRV_H
10
+ #define MLIR_CONVERSION_INDEXTOSPIRV_INDEXTOSPIRV_H
11
+
12
+ #include " mlir/Pass/Pass.h"
13
+ #include < memory>
14
+
15
+ namespace mlir {
16
+ class RewritePatternSet ;
17
+ class SPIRVTypeConverter ;
18
+ class Pass ;
19
+
20
+ #define GEN_PASS_DECL_CONVERTINDEXTOSPIRVPASS
21
+ #include " mlir/Conversion/Passes.h.inc"
22
+
23
+ namespace index {
24
+ void populateIndexToSPIRVPatterns (SPIRVTypeConverter &converter,
25
+ RewritePatternSet &patterns);
26
+ std::unique_ptr<OperationPass<>> createConvertIndexToSPIRVPass ();
27
+ } // namespace index
28
+ } // namespace mlir
29
+
30
+ #endif // MLIR_CONVERSION_INDEXTOSPIRV_INDEXTOSPIRV_H
Original file line number Diff line number Diff line change 35
35
#include " mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
36
36
#include " mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"
37
37
#include " mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
38
+ #include " mlir/Conversion/IndexToSPIRV/IndexToSPIRV.h"
38
39
#include " mlir/Conversion/LinalgToStandard/LinalgToStandard.h"
39
40
#include " mlir/Conversion/MathToFuncs/MathToFuncs.h"
40
41
#include " mlir/Conversion/MathToLLVM/MathToLLVM.h"
Original file line number Diff line number Diff line change @@ -644,6 +644,28 @@ def ConvertIndexToLLVMPass : Pass<"convert-index-to-llvm"> {
644
644
];
645
645
}
646
646
647
+ //===----------------------------------------------------------------------===//
648
+ // ConvertIndexToSPIRVPass
649
+ //===----------------------------------------------------------------------===//
650
+
651
+ def ConvertIndexToSPIRVPass : Pass<"convert-index-to-spirv"> {
652
+ let summary = "Lower the `index` dialect to the `spirv` dialect.";
653
+ let description = [{
654
+ This pass lowers Index dialect operations to SPIR-V dialect operations.
655
+ Operation conversions are 1-to-1 except for the exotic divides: `ceildivs`,
656
+ `ceildivu`, and `floordivs`. The index bitwidth will be 32 or 64 as
657
+ specified by use-64bit-index.
658
+ }];
659
+
660
+ let dependentDialects = ["::mlir::spirv::SPIRVDialect"];
661
+
662
+ let options = [
663
+ Option<"use64bitIndex", "use-64bit-index",
664
+ "bool", /*default=*/"false",
665
+ "Use 64-bit integers to convert index types">
666
+ ];
667
+ }
668
+
647
669
//===----------------------------------------------------------------------===//
648
670
// LinalgToStandard
649
671
//===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -55,13 +55,13 @@ struct SPIRVConversionOptions {
55
55
// / values will be packed into one 32-bit value to be memory efficient.
56
56
bool emulateLT32BitScalarTypes{true };
57
57
58
- // / Use 64-bit integers to convert index types.
59
- bool use64bitIndex{false };
60
-
61
58
// / Whether to enable fast math mode during conversion. If true, various
62
59
// / patterns would assume no NaN/infinity numbers as inputs, and thus there
63
60
// / will be no special guards emitted to check and handle such cases.
64
61
bool enableFastMathMode{false };
62
+
63
+ // / Use 64-bit integers when converting index types.
64
+ bool use64bitIndex{false };
65
65
};
66
66
67
67
// / Type conversion from builtin types to SPIR-V types for shader interface.
@@ -77,6 +77,11 @@ class SPIRVTypeConverter : public TypeConverter {
77
77
// / Gets the SPIR-V correspondence for the standard index type.
78
78
Type getIndexType () const ;
79
79
80
+ // / Gets the bitwidth of the index type when converted to SPIR-V.
81
+ unsigned getIndexTypeBitwidth () const {
82
+ return options.use64bitIndex ? 64 : 32 ;
83
+ }
84
+
80
85
const spirv::TargetEnv &getTargetEnv () const { return targetEnv; }
81
86
82
87
// / Returns the options controlling the SPIR-V type converter.
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ add_subdirectory(GPUToROCDL)
24
24
add_subdirectory (GPUToSPIRV)
25
25
add_subdirectory (GPUToVulkan)
26
26
add_subdirectory (IndexToLLVM)
27
+ add_subdirectory (IndexToSPIRV)
27
28
add_subdirectory (LinalgToStandard)
28
29
add_subdirectory (LLVMCommon)
29
30
add_subdirectory (MathToFuncs)
Original file line number Diff line number Diff line change
1
+ add_mlir_conversion_library(MLIRIndexToSPIRV
2
+ IndexToSPIRV.cpp
3
+
4
+ ADDITIONAL_HEADER_DIRS
5
+ ${MLIR_MAIN_INCLUDE_DIR} /mlir/Conversion/IndexToSPIRV
6
+
7
+ DEPENDS
8
+ MLIRConversionPassIncGen
9
+
10
+ LINK_COMPONENTS
11
+ Core
12
+
13
+ LINK_LIBS PUBLIC
14
+ MLIRIndexDialect
15
+ )
You can’t perform that action at this time.
0 commit comments