Skip to content

Commit 0359e1d

Browse files
committed
[mlir][spirv] NFC: Move shader ABI attributes to a new file
This allows us to include the definitions of these attributes in other files without pulling in all dependencies for lowering. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D72054
1 parent 5d38b26 commit 0359e1d

File tree

8 files changed

+113
-73
lines changed

8 files changed

+113
-73
lines changed

mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
1919
mlir_tablegen(SPIRVOpUtils.inc -gen-spirv-op-utils)
2020
add_public_tablegen_target(MLIRSPIRVOpUtilsGen)
2121

22-
set(LLVM_TARGET_DEFINITIONS SPIRVLowering.td)
23-
mlir_tablegen(SPIRVLowering.h.inc -gen-struct-attr-decls)
24-
mlir_tablegen(SPIRVLowering.cpp.inc -gen-struct-attr-defs)
25-
add_public_tablegen_target(MLIRSPIRVLoweringStructGen)
22+
set(LLVM_TARGET_DEFINITIONS TargetAndABI.td)
23+
mlir_tablegen(TargetAndABI.h.inc -gen-struct-attr-decls)
24+
mlir_tablegen(TargetAndABI.cpp.inc -gen-struct-attr-defs)
25+
add_public_tablegen_target(MLIRSPIRVTargetAndABIIncGen)

mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
#ifndef MLIR_DIALECT_SPIRV_SPIRVLOWERING_H
1414
#define MLIR_DIALECT_SPIRV_SPIRVLOWERING_H
1515

16-
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
17-
#include "mlir/IR/Attributes.h"
18-
#include "mlir/Support/StringExtras.h"
16+
#include "mlir/Dialect/SPIRV/TargetAndABI.h"
1917
#include "mlir/Transforms/DialectConversion.h"
20-
#include "llvm/ADT/SetVector.h"
2118

2219
namespace mlir {
2320

@@ -50,36 +47,18 @@ class SPIRVOpLowering : public OpConversionPattern<SourceOp> {
5047
SPIRVTypeConverter &typeConverter;
5148
};
5249

53-
#include "mlir/Dialect/SPIRV/SPIRVLowering.h.inc"
54-
5550
namespace spirv {
51+
enum class BuiltIn : uint32_t;
52+
5653
/// Returns a value that represents a builtin variable value within the SPIR-V
5754
/// module.
58-
Value getBuiltinVariableValue(Operation *op, spirv::BuiltIn builtin,
55+
Value getBuiltinVariableValue(Operation *op, BuiltIn builtin,
5956
OpBuilder &builder);
6057

61-
/// Attribute name for specifying argument ABI information.
62-
StringRef getInterfaceVarABIAttrName();
63-
64-
/// Get the InterfaceVarABIAttr given its fields.
65-
InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet,
66-
unsigned binding,
67-
spirv::StorageClass storageClass,
68-
MLIRContext *context);
69-
70-
/// Attribute name for specifying entry point information.
71-
StringRef getEntryPointABIAttrName();
72-
73-
/// Get the EntryPointABIAttr given its fields.
74-
EntryPointABIAttr getEntryPointABIAttr(ArrayRef<int32_t> localSize,
75-
MLIRContext *context);
76-
7758
/// Sets the InterfaceVarABIAttr and EntryPointABIAttr for a function and its
78-
/// arguments
79-
LogicalResult setABIAttrs(FuncOp funcOp,
80-
spirv::EntryPointABIAttr entryPointInfo,
81-
ArrayRef<spirv::InterfaceVarABIAttr> argABIInfo);
82-
59+
/// arguments.
60+
LogicalResult setABIAttrs(FuncOp funcOp, EntryPointABIAttr entryPointInfo,
61+
ArrayRef<InterfaceVarABIAttr> argABIInfo);
8362
} // namespace spirv
8463
} // namespace mlir
8564

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===- TargetAndABI.h - SPIR-V target and ABI utilities --------*- C++ -*-===//
2+
//
3+
// Part of the MLIR 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+
// This file declares utilities for SPIR-V target and shader interface ABI.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_SPIRV_TARGETANDABI_H
14+
#define MLIR_DIALECT_SPIRV_TARGETANDABI_H
15+
16+
#include "mlir/IR/Attributes.h"
17+
#include "mlir/Support/LLVM.h"
18+
19+
namespace mlir {
20+
class OpBuilder;
21+
class Operation;
22+
class Value;
23+
24+
// Pull in SPIR-V attribute definitions.
25+
#include "mlir/Dialect/SPIRV/TargetAndABI.h.inc"
26+
27+
namespace spirv {
28+
enum class StorageClass : uint32_t;
29+
30+
/// Attribute name for specifying argument ABI information.
31+
StringRef getInterfaceVarABIAttrName();
32+
33+
/// Get the InterfaceVarABIAttr given its fields.
34+
InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet,
35+
unsigned binding,
36+
StorageClass storageClass,
37+
MLIRContext *context);
38+
39+
/// Attribute name for specifying entry point information.
40+
StringRef getEntryPointABIAttrName();
41+
42+
/// Get the EntryPointABIAttr given its fields.
43+
EntryPointABIAttr getEntryPointABIAttr(ArrayRef<int32_t> localSize,
44+
MLIRContext *context);
45+
} // namespace spirv
46+
} // namespace mlir
47+
48+
#endif // MLIR_DIALECT_SPIRV_TARGETANDABI_H

mlir/lib/Dialect/SPIRV/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_llvm_library(MLIRSPIRV
99
SPIRVOps.cpp
1010
SPIRVLowering.cpp
1111
SPIRVTypes.cpp
12+
TargetAndABI.cpp
1213

1314
ADDITIONAL_HEADER_DIRS
1415
${MLIR_MAIN_INCLUDE_DIR}/mlir/SPIRV
@@ -18,9 +19,9 @@ add_dependencies(MLIRSPIRV
1819
MLIRSPIRVAvailabilityIncGen
1920
MLIRSPIRVCanonicalizationIncGen
2021
MLIRSPIRVEnumsIncGen
21-
MLIRSPIRVLoweringStructGen
2222
MLIRSPIRVOpsIncGen
23-
MLIRSPIRVOpUtilsGen)
23+
MLIRSPIRVOpUtilsGen
24+
MLIRSPIRVTargetAndABIIncGen)
2425

2526
target_link_libraries(MLIRSPIRV
2627
MLIRIR

mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,15 @@
99
// This file implements utilities used to lower to SPIR-V dialect.
1010
//
1111
//===----------------------------------------------------------------------===//
12+
1213
#include "mlir/Dialect/SPIRV/SPIRVLowering.h"
1314
#include "mlir/Dialect/SPIRV/LayoutUtils.h"
1415
#include "mlir/Dialect/SPIRV/SPIRVDialect.h"
16+
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
1517
#include "llvm/ADT/Sequence.h"
1618

1719
using namespace mlir;
1820

19-
//===----------------------------------------------------------------------===//
20-
// Attributes for ABI
21-
//===----------------------------------------------------------------------===//
22-
23-
// Pull in the attributes needed for lowering.
24-
namespace mlir {
25-
#include "mlir/Dialect/SPIRV/SPIRVLowering.cpp.inc"
26-
}
27-
28-
StringRef mlir::spirv::getInterfaceVarABIAttrName() {
29-
return "spirv.interface_var_abi";
30-
}
31-
32-
mlir::spirv::InterfaceVarABIAttr
33-
mlir::spirv::getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding,
34-
spirv::StorageClass storageClass,
35-
MLIRContext *context) {
36-
Type i32Type = IntegerType::get(32, context);
37-
return mlir::spirv::InterfaceVarABIAttr::get(
38-
IntegerAttr::get(i32Type, descriptorSet),
39-
IntegerAttr::get(i32Type, binding),
40-
IntegerAttr::get(i32Type, static_cast<int64_t>(storageClass)), context);
41-
}
42-
43-
StringRef mlir::spirv::getEntryPointABIAttrName() {
44-
return "spirv.entry_point_abi";
45-
}
46-
47-
mlir::spirv::EntryPointABIAttr
48-
mlir::spirv::getEntryPointABIAttr(ArrayRef<int32_t> localSize,
49-
MLIRContext *context) {
50-
assert(localSize.size() == 3);
51-
return mlir::spirv::EntryPointABIAttr::get(
52-
DenseElementsAttr::get<int32_t>(
53-
VectorType::get(3, IntegerType::get(32, context)), localSize)
54-
.cast<DenseIntElementsAttr>(),
55-
context);
56-
}
57-
5821
//===----------------------------------------------------------------------===//
5922
// Type Conversion
6023
//===----------------------------------------------------------------------===//
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===- SPIRVLowering.cpp - Standard to SPIR-V dialect conversion--===//
2+
//
3+
// Part of the MLIR 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+
#include "mlir/Dialect/SPIRV/TargetAndABI.h"
10+
#include "mlir/Dialect/SPIRV/SPIRVTypes.h"
11+
#include "mlir/IR/Operation.h"
12+
13+
using namespace mlir;
14+
15+
namespace mlir {
16+
#include "mlir/Dialect/SPIRV/TargetAndABI.cpp.inc"
17+
}
18+
19+
StringRef mlir::spirv::getInterfaceVarABIAttrName() {
20+
return "spirv.interface_var_abi";
21+
}
22+
23+
mlir::spirv::InterfaceVarABIAttr
24+
mlir::spirv::getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding,
25+
spirv::StorageClass storageClass,
26+
MLIRContext *context) {
27+
Type i32Type = IntegerType::get(32, context);
28+
return mlir::spirv::InterfaceVarABIAttr::get(
29+
IntegerAttr::get(i32Type, descriptorSet),
30+
IntegerAttr::get(i32Type, binding),
31+
IntegerAttr::get(i32Type, static_cast<int64_t>(storageClass)), context);
32+
}
33+
34+
StringRef mlir::spirv::getEntryPointABIAttrName() {
35+
return "spirv.entry_point_abi";
36+
}
37+
38+
mlir::spirv::EntryPointABIAttr
39+
mlir::spirv::getEntryPointABIAttr(ArrayRef<int32_t> localSize,
40+
MLIRContext *context) {
41+
assert(localSize.size() == 3);
42+
return mlir::spirv::EntryPointABIAttr::get(
43+
DenseElementsAttr::get<int32_t>(
44+
VectorType::get(3, IntegerType::get(32, context)), localSize)
45+
.cast<DenseIntElementsAttr>(),
46+
context);
47+
}

mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
#include "mlir/Dialect/SPIRV/Passes.h"
1616
#include "mlir/Dialect/SPIRV/SPIRVDialect.h"
1717
#include "mlir/Dialect/SPIRV/SPIRVLowering.h"
18+
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
1819
#include "mlir/Dialect/StandardOps/Ops.h"
1920
#include "mlir/Transforms/DialectConversion.h"
21+
#include "llvm/ADT/SetVector.h"
2022

2123
using namespace mlir;
2224

0 commit comments

Comments
 (0)