MLIR  19.0.0git
SPIRVAttributes.h
Go to the documentation of this file.
1 //===- SPIRVAttributes.h - SPIR-V attribute declarations -------*- 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 // This file declares SPIR-V dialect specific attributes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SPIRV_IR_SPIRVATTRIBUTES_H
14 #define MLIR_DIALECT_SPIRV_IR_SPIRVATTRIBUTES_H
15 
18 #include "mlir/Support/LLVM.h"
19 
20 namespace mlir {
21 namespace spirv {
22 class VerCapExtAttr;
23 }
24 } // namespace mlir
25 
26 // Pull in TableGen'erated SPIR-V attribute definitions for target and ABI.
27 #define GET_ATTRDEF_CLASSES
28 #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h.inc"
29 
30 namespace mlir {
31 namespace spirv {
32 enum class Capability : uint32_t;
33 enum class DeviceType : uint32_t;
34 enum class Extension : uint32_t;
35 enum class Vendor : uint32_t;
36 enum class Version : uint32_t;
37 
38 namespace detail {
42 } // namespace detail
43 
44 // TableGen'erated helper functions.
45 //
46 // Get the name used in the Op to refer to an enum value of the given
47 // `EnumClass`.
48 // template <typename EnumClass> StringRef attributeName();
49 //
50 #include "mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc"
51 
52 /// An attribute that specifies the information regarding the interface
53 /// variable: descriptor set, binding, storage class.
55  : public Attribute::AttrBase<InterfaceVarABIAttr, Attribute,
56  detail::InterfaceVarABIAttributeStorage> {
57 public:
58  using Base::Base;
59 
60  /// Gets a InterfaceVarABIAttr.
61  static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding,
62  std::optional<StorageClass> storageClass,
63  MLIRContext *context);
64  static InterfaceVarABIAttr get(IntegerAttr descriptorSet, IntegerAttr binding,
65  IntegerAttr storageClass);
66 
67  /// Returns the attribute kind's name (without the 'spirv.' prefix).
68  static StringRef getKindName();
69 
70  /// Returns descriptor set.
71  uint32_t getDescriptorSet();
72 
73  /// Returns binding.
74  uint32_t getBinding();
75 
76  /// Returns `spirv::StorageClass`.
77  std::optional<StorageClass> getStorageClass();
78 
80  IntegerAttr descriptorSet, IntegerAttr binding,
81  IntegerAttr storageClass);
82 
83  static constexpr StringLiteral name = "spirv.interface_var_abi";
84 };
85 
86 /// An attribute that specifies the SPIR-V (version, capabilities, extensions)
87 /// triple.
89  : public Attribute::AttrBase<VerCapExtAttr, Attribute,
90  detail::VerCapExtAttributeStorage> {
91 public:
92  using Base::Base;
93 
94  /// Gets a VerCapExtAttr instance.
95  static VerCapExtAttr get(Version version, ArrayRef<Capability> capabilities,
96  ArrayRef<Extension> extensions,
97  MLIRContext *context);
98  static VerCapExtAttr get(IntegerAttr version, ArrayAttr capabilities,
99  ArrayAttr extensions);
100 
101  /// Returns the attribute kind's name (without the 'spirv.' prefix).
102  static StringRef getKindName();
103 
104  /// Returns the version.
105  Version getVersion();
106 
107  struct ext_iterator final
108  : public llvm::mapped_iterator<ArrayAttr::iterator,
109  Extension (*)(Attribute)> {
110  explicit ext_iterator(ArrayAttr::iterator it);
111  };
113 
114  /// Returns the extensions.
116  /// Returns the extensions as a string array attribute.
117  ArrayAttr getExtensionsAttr();
118 
119  struct cap_iterator final
120  : public llvm::mapped_iterator<ArrayAttr::iterator,
121  Capability (*)(Attribute)> {
122  explicit cap_iterator(ArrayAttr::iterator it);
123  };
125 
126  /// Returns the capabilities.
128  /// Returns the capabilities as an integer array attribute.
129  ArrayAttr getCapabilitiesAttr();
130 
132  IntegerAttr version, ArrayAttr capabilities,
133  ArrayAttr extensions);
134 
135  static constexpr StringLiteral name = "spirv.ver_cap_ext";
136 };
137 
138 /// An attribute that specifies the target version, allowed extensions and
139 /// capabilities, and resource limits. These information describes a SPIR-V
140 /// target environment.
142  : public Attribute::AttrBase<TargetEnvAttr, Attribute,
143  detail::TargetEnvAttributeStorage> {
144 public:
145  /// ID for unknown devices.
146  static constexpr uint32_t kUnknownDeviceID = 0x7FFFFFFF;
147 
148  using Base::Base;
149 
150  /// Gets a TargetEnvAttr instance.
151  static TargetEnvAttr get(VerCapExtAttr triple, ResourceLimitsAttr limits,
152  ClientAPI clientAPI = ClientAPI::Unknown,
153  Vendor vendorID = Vendor::Unknown,
154  DeviceType deviceType = DeviceType::Unknown,
155  uint32_t deviceId = kUnknownDeviceID);
156 
157  /// Returns the attribute kind's name (without the 'spirv.' prefix).
158  static StringRef getKindName();
159 
160  /// Returns the (version, capabilities, extensions) triple attribute.
162 
163  /// Returns the target version.
164  Version getVersion() const;
165 
166  /// Returns the target extensions.
168  /// Returns the target extensions as a string array attribute.
169  ArrayAttr getExtensionsAttr();
170 
171  /// Returns the target capabilities.
173  /// Returns the target capabilities as an integer array attribute.
174  ArrayAttr getCapabilitiesAttr();
175 
176  /// Returns the client API.
177  ClientAPI getClientAPI() const;
178 
179  /// Returns the vendor ID.
180  Vendor getVendorID() const;
181 
182  /// Returns the device type.
183  DeviceType getDeviceType() const;
184 
185  /// Returns the device ID.
186  uint32_t getDeviceID() const;
187 
188  /// Returns the target resource limits.
189  ResourceLimitsAttr getResourceLimits() const;
190 
191  static constexpr StringLiteral name = "spirv.target_env";
192 };
193 } // namespace spirv
194 } // namespace mlir
195 
196 #endif // MLIR_DIALECT_SPIRV_IR_SPIRVATTRIBUTES_H
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:308
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
An attribute that specifies the information regarding the interface variable: descriptor set,...
uint32_t getBinding()
Returns binding.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
static constexpr StringLiteral name
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, IntegerAttr descriptorSet, IntegerAttr binding, IntegerAttr storageClass)
uint32_t getDescriptorSet()
Returns descriptor set.
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, std::optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
std::optional< StorageClass > getStorageClass()
Returns spirv::StorageClass.
An attribute that specifies the target version, allowed extensions and capabilities,...
Version getVersion() const
Returns the target version.
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
VerCapExtAttr getTripleAttr() const
Returns the (version, capabilities, extensions) triple attribute.
ArrayAttr getCapabilitiesAttr()
Returns the target capabilities as an integer array attribute.
VerCapExtAttr::ext_range getExtensions()
Returns the target extensions.
static constexpr StringLiteral name
Vendor getVendorID() const
Returns the vendor ID.
DeviceType getDeviceType() const
Returns the device type.
ClientAPI getClientAPI() const
Returns the client API.
ArrayAttr getExtensionsAttr()
Returns the target extensions as a string array attribute.
uint32_t getDeviceID() const
Returns the device ID.
static constexpr uint32_t kUnknownDeviceID
ID for unknown devices.
static TargetEnvAttr get(VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI=ClientAPI::Unknown, Vendor vendorID=Vendor::Unknown, DeviceType deviceType=DeviceType::Unknown, uint32_t deviceId=kUnknownDeviceID)
Gets a TargetEnvAttr instance.
An attribute that specifies the SPIR-V (version, capabilities, extensions) triple.
cap_range getCapabilities()
Returns the capabilities.
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, IntegerAttr version, ArrayAttr capabilities, ArrayAttr extensions)
Version getVersion()
Returns the version.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
ArrayAttr getCapabilitiesAttr()
Returns the capabilities as an integer array attribute.
static constexpr StringLiteral name
ext_range getExtensions()
Returns the extensions.
ArrayAttr getExtensionsAttr()
Returns the extensions as a string array attribute.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26