MLIR  16.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 // Pull in TableGen'erated SPIR-V attribute definitions for target and ABI.
21 #define GET_ATTRDEF_CLASSES
22 #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h.inc"
23 
24 namespace mlir {
25 namespace spirv {
26 enum class Capability : uint32_t;
27 enum class DeviceType : uint32_t;
28 enum class Extension : uint32_t;
29 enum class Vendor : uint32_t;
30 enum class Version : uint32_t;
31 
32 namespace detail {
36 } // namespace detail
37 
38 // TableGen'erated helper functions.
39 //
40 // Get the name used in the Op to refer to an enum value of the given
41 // `EnumClass`.
42 // template <typename EnumClass> StringRef attributeName();
43 //
44 #include "mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc"
45 
46 /// An attribute that specifies the information regarding the interface
47 /// variable: descriptor set, binding, storage class.
49  : public Attribute::AttrBase<InterfaceVarABIAttr, Attribute,
50  detail::InterfaceVarABIAttributeStorage> {
51 public:
52  using Base::Base;
53 
54  /// Gets a InterfaceVarABIAttr.
55  static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding,
56  Optional<StorageClass> storageClass,
57  MLIRContext *context);
58  static InterfaceVarABIAttr get(IntegerAttr descriptorSet, IntegerAttr binding,
59  IntegerAttr storageClass);
60 
61  /// Returns the attribute kind's name (without the 'spirv.' prefix).
62  static StringRef getKindName();
63 
64  /// Returns descriptor set.
65  uint32_t getDescriptorSet();
66 
67  /// Returns binding.
68  uint32_t getBinding();
69 
70  /// Returns `spirv::StorageClass`.
72 
74  IntegerAttr descriptorSet, IntegerAttr binding,
75  IntegerAttr storageClass);
76 };
77 
78 /// An attribute that specifies the SPIR-V (version, capabilities, extensions)
79 /// triple.
81  : public Attribute::AttrBase<VerCapExtAttr, Attribute,
82  detail::VerCapExtAttributeStorage> {
83 public:
84  using Base::Base;
85 
86  /// Gets a VerCapExtAttr instance.
87  static VerCapExtAttr get(Version version, ArrayRef<Capability> capabilities,
88  ArrayRef<Extension> extensions,
89  MLIRContext *context);
90  static VerCapExtAttr get(IntegerAttr version, ArrayAttr capabilities,
91  ArrayAttr extensions);
92 
93  /// Returns the attribute kind's name (without the 'spirv.' prefix).
94  static StringRef getKindName();
95 
96  /// Returns the version.
97  Version getVersion();
98 
99  struct ext_iterator final
100  : public llvm::mapped_iterator<ArrayAttr::iterator,
101  Extension (*)(Attribute)> {
102  explicit ext_iterator(ArrayAttr::iterator it);
103  };
105 
106  /// Returns the extensions.
108  /// Returns the extensions as a string array attribute.
109  ArrayAttr getExtensionsAttr();
110 
111  struct cap_iterator final
112  : public llvm::mapped_iterator<ArrayAttr::iterator,
113  Capability (*)(Attribute)> {
114  explicit cap_iterator(ArrayAttr::iterator it);
115  };
117 
118  /// Returns the capabilities.
120  /// Returns the capabilities as an integer array attribute.
121  ArrayAttr getCapabilitiesAttr();
122 
124  IntegerAttr version, ArrayAttr capabilities,
125  ArrayAttr extensions);
126 };
127 
128 /// An attribute that specifies the target version, allowed extensions and
129 /// capabilities, and resource limits. These information describes a SPIR-V
130 /// target environment.
132  : public Attribute::AttrBase<TargetEnvAttr, Attribute,
133  detail::TargetEnvAttributeStorage> {
134 public:
135  /// ID for unknown devices.
136  static constexpr uint32_t kUnknownDeviceID = 0x7FFFFFFF;
137 
138  using Base::Base;
139 
140  /// Gets a TargetEnvAttr instance.
141  static TargetEnvAttr get(VerCapExtAttr triple, ResourceLimitsAttr limits,
142  ClientAPI clientAPI = ClientAPI::Unknown,
143  Vendor vendorID = Vendor::Unknown,
144  DeviceType deviceType = DeviceType::Unknown,
145  uint32_t deviceId = kUnknownDeviceID);
146 
147  /// Returns the attribute kind's name (without the 'spirv.' prefix).
148  static StringRef getKindName();
149 
150  /// Returns the (version, capabilities, extensions) triple attribute.
152 
153  /// Returns the target version.
154  Version getVersion() const;
155 
156  /// Returns the target extensions.
158  /// Returns the target extensions as a string array attribute.
159  ArrayAttr getExtensionsAttr();
160 
161  /// Returns the target capabilities.
163  /// Returns the target capabilities as an integer array attribute.
164  ArrayAttr getCapabilitiesAttr();
165 
166  /// Returns the client API.
167  ClientAPI getClientAPI() const;
168 
169  /// Returns the vendor ID.
170  Vendor getVendorID() const;
171 
172  /// Returns the device type.
173  DeviceType getDeviceType() const;
174 
175  /// Returns the device ID.
176  uint32_t getDeviceID() const;
177 
178  /// Returns the target resource limits.
179  ResourceLimitsAttr getResourceLimits() const;
180 };
181 } // namespace spirv
182 } // namespace mlir
183 
184 #endif // MLIR_DIALECT_SPIRV_IR_SPIRVATTRIBUTES_H
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:307
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
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).
Optional< StorageClass > getStorageClass()
Returns spirv::StorageClass.
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, Optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
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.
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.
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