[Mlir-commits] [mlir] 440ef33 - [mlir][spirv] Add get() method to TargetEnvAttr taking raw values
Lei Zhang
llvmlistbot at llvm.org
Wed Mar 4 11:01:41 PST 2020
Author: Lei Zhang
Date: 2020-03-04T14:01:26-05:00
New Revision: 440ef330737c0d60045b3072dbfe6c463e21fcb4
URL: https://github.com/llvm/llvm-project/commit/440ef330737c0d60045b3072dbfe6c463e21fcb4
DIFF: https://github.com/llvm/llvm-project/commit/440ef330737c0d60045b3072dbfe6c463e21fcb4.diff
LOG: [mlir][spirv] Add get() method to TargetEnvAttr taking raw values
Also make the getResourceLimits() method more explicit about its return type.
Differential Revision: https://reviews.llvm.org/D75484
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
index a20fe6e207dd..01b775846ee3 100644
--- a/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
+++ b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
@@ -52,6 +52,9 @@ class TargetEnvAttr
using Base::Base;
/// Gets a TargetEnvAttr instance.
+ static TargetEnvAttr get(Version version, ArrayRef<Extension> extensions,
+ ArrayRef<Capability> capabilities,
+ DictionaryAttr limits);
static TargetEnvAttr get(IntegerAttr version, ArrayAttr extensions,
ArrayAttr capabilities, DictionaryAttr limits);
@@ -86,7 +89,7 @@ class TargetEnvAttr
ArrayAttr getCapabilitiesAttr();
/// Returns the target resource limits.
- DictionaryAttr getResourceLimits();
+ ResourceLimitsAttr getResourceLimits();
static bool kindof(unsigned kind) { return kind == AttrKind::TargetEnv; }
diff --git a/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
index ee5dcb1f7f85..f8c5900eb842 100644
--- a/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
+++ b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
@@ -48,6 +48,27 @@ struct TargetEnvAttributeStorage : public AttributeStorage {
} // namespace spirv
} // namespace mlir
+spirv::TargetEnvAttr spirv::TargetEnvAttr::get(
+ spirv::Version version, ArrayRef<spirv::Extension> extensions,
+ ArrayRef<spirv::Capability> capabilities, DictionaryAttr limits) {
+ Builder b(limits.getContext());
+
+ auto versionAttr = b.getI32IntegerAttr(static_cast<uint32_t>(version));
+
+ SmallVector<Attribute, 4> extAttrs;
+ extAttrs.reserve(extensions.size());
+ for (spirv::Extension ext : extensions)
+ extAttrs.push_back(b.getStringAttr(spirv::stringifyExtension(ext)));
+
+ SmallVector<Attribute, 4> capAttrs;
+ capAttrs.reserve(capabilities.size());
+ for (spirv::Capability cap : capabilities)
+ capAttrs.push_back(b.getI32IntegerAttr(static_cast<uint32_t>(cap)));
+
+ return get(versionAttr, b.getArrayAttr(extAttrs), b.getArrayAttr(capAttrs),
+ limits);
+}
+
spirv::TargetEnvAttr spirv::TargetEnvAttr::get(IntegerAttr version,
ArrayAttr extensions,
ArrayAttr capabilities,
@@ -98,8 +119,8 @@ ArrayAttr spirv::TargetEnvAttr::getCapabilitiesAttr() {
return getImpl()->capabilities.cast<ArrayAttr>();
}
-DictionaryAttr spirv::TargetEnvAttr::getResourceLimits() {
- return getImpl()->limits.cast<DictionaryAttr>();
+spirv::ResourceLimitsAttr spirv::TargetEnvAttr::getResourceLimits() {
+ return getImpl()->limits.cast<spirv::ResourceLimitsAttr>();
}
LogicalResult spirv::TargetEnvAttr::verifyConstructionInvariants(
More information about the Mlir-commits
mailing list