[Mlir-commits] [mlir] 21eb812 - [mlir][spirv] Expose more query APIs directly on TargetEnv
Lei Zhang
llvmlistbot at llvm.org
Mon Nov 9 15:03:01 PST 2020
Author: Lei Zhang
Date: 2020-11-09T18:02:53-05:00
New Revision: 21eb8127f41214c03934e9c7c6115ab70174d213
URL: https://github.com/llvm/llvm-project/commit/21eb8127f41214c03934e9c7c6115ab70174d213
DIFF: https://github.com/llvm/llvm-project/commit/21eb8127f41214c03934e9c7c6115ab70174d213.diff
LOG: [mlir][spirv] Expose more query APIs directly on TargetEnv
This allows us to omit one level of indirection when querying
the information from the underlying attribute.
Reviewed By: hanchung, ThomasRaoux
Differential Revision: https://reviews.llvm.org/D91080
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h
mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h
index 129e91795870f..5cd6b033d0587 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h
@@ -139,10 +139,10 @@ class TargetEnvAttr
static StringRef getKindName();
/// Returns the (version, capabilities, extensions) triple attribute.
- VerCapExtAttr getTripleAttr();
+ VerCapExtAttr getTripleAttr() const;
/// Returns the target version.
- Version getVersion();
+ Version getVersion() const;
/// Returns the target extensions.
VerCapExtAttr::ext_range getExtensions();
@@ -155,16 +155,16 @@ class TargetEnvAttr
ArrayAttr getCapabilitiesAttr();
/// Returns the vendor ID.
- Vendor getVendorID();
+ Vendor getVendorID() const;
/// Returns the device type.
- DeviceType getDeviceType();
+ DeviceType getDeviceType() const;
/// Returns the device ID.
- uint32_t getDeviceID();
+ uint32_t getDeviceID() const;
/// Returns the target resource limits.
- ResourceLimitsAttr getResourceLimits();
+ ResourceLimitsAttr getResourceLimits() const;
static LogicalResult
verifyConstructionInvariants(Location loc, VerCapExtAttr triple,
diff --git a/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
index e276123c4bb54..4d7b96fae009f 100644
--- a/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
+++ b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
@@ -29,7 +29,7 @@ class TargetEnv {
public:
explicit TargetEnv(TargetEnvAttr targetAttr);
- Version getVersion();
+ Version getVersion() const;
/// Returns true if the given capability is allowed.
bool allows(Capability) const;
@@ -43,9 +43,23 @@ class TargetEnv {
/// Returns llvm::None otherwise.
Optional<Extension> allows(ArrayRef<Extension>) const;
+ /// Returns the vendor ID.
+ Vendor getVendorID() const;
+
+ /// Returns the device type.
+ DeviceType getDeviceType() const;
+
+ /// Returns the device ID.
+ uint32_t getDeviceID() const;
+
/// Returns the MLIRContext.
MLIRContext *getContext() const;
+ /// Returns the target resource limits.
+ ResourceLimitsAttr getResourceLimits() const;
+
+ TargetEnvAttr getAttr() const { return targetAttr; }
+
/// Allows implicity converting to the underlying spirv::TargetEnvAttr.
operator TargetEnvAttr() const { return targetAttr; }
diff --git a/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp b/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
index 0fbea2c1777fb..2f90951fadd4d 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
@@ -288,11 +288,11 @@ spirv::TargetEnvAttr spirv::TargetEnvAttr::get(spirv::VerCapExtAttr triple,
StringRef spirv::TargetEnvAttr::getKindName() { return "target_env"; }
-spirv::VerCapExtAttr spirv::TargetEnvAttr::getTripleAttr() {
+spirv::VerCapExtAttr spirv::TargetEnvAttr::getTripleAttr() const {
return getImpl()->triple.cast<spirv::VerCapExtAttr>();
}
-spirv::Version spirv::TargetEnvAttr::getVersion() {
+spirv::Version spirv::TargetEnvAttr::getVersion() const {
return getTripleAttr().getVersion();
}
@@ -312,17 +312,19 @@ ArrayAttr spirv::TargetEnvAttr::getCapabilitiesAttr() {
return getTripleAttr().getCapabilitiesAttr();
}
-spirv::Vendor spirv::TargetEnvAttr::getVendorID() {
+spirv::Vendor spirv::TargetEnvAttr::getVendorID() const {
return getImpl()->vendorID;
}
-spirv::DeviceType spirv::TargetEnvAttr::getDeviceType() {
+spirv::DeviceType spirv::TargetEnvAttr::getDeviceType() const {
return getImpl()->deviceType;
}
-uint32_t spirv::TargetEnvAttr::getDeviceID() { return getImpl()->deviceID; }
+uint32_t spirv::TargetEnvAttr::getDeviceID() const {
+ return getImpl()->deviceID;
+}
-spirv::ResourceLimitsAttr spirv::TargetEnvAttr::getResourceLimits() {
+spirv::ResourceLimitsAttr spirv::TargetEnvAttr::getResourceLimits() const {
return getImpl()->limits.cast<spirv::ResourceLimitsAttr>();
}
diff --git a/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
index 29a89a30ad4cf..f409f1d14a988 100644
--- a/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
+++ b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp
@@ -38,7 +38,7 @@ spirv::TargetEnv::TargetEnv(spirv::TargetEnvAttr targetAttr)
}
}
-spirv::Version spirv::TargetEnv::getVersion() {
+spirv::Version spirv::TargetEnv::getVersion() const {
return targetAttr.getVersion();
}
@@ -48,7 +48,7 @@ bool spirv::TargetEnv::allows(spirv::Capability capability) const {
Optional<spirv::Capability>
spirv::TargetEnv::allows(ArrayRef<spirv::Capability> caps) const {
- auto chosen = llvm::find_if(caps, [this](spirv::Capability cap) {
+ const auto *chosen = llvm::find_if(caps, [this](spirv::Capability cap) {
return givenCapabilities.count(cap);
});
if (chosen != caps.end())
@@ -62,7 +62,7 @@ bool spirv::TargetEnv::allows(spirv::Extension extension) const {
Optional<spirv::Extension>
spirv::TargetEnv::allows(ArrayRef<spirv::Extension> exts) const {
- auto chosen = llvm::find_if(exts, [this](spirv::Extension ext) {
+ const auto *chosen = llvm::find_if(exts, [this](spirv::Extension ext) {
return givenExtensions.count(ext);
});
if (chosen != exts.end())
@@ -70,6 +70,22 @@ spirv::TargetEnv::allows(ArrayRef<spirv::Extension> exts) const {
return llvm::None;
}
+spirv::Vendor spirv::TargetEnv::getVendorID() const {
+ return targetAttr.getVendorID();
+}
+
+spirv::DeviceType spirv::TargetEnv::getDeviceType() const {
+ return targetAttr.getDeviceType();
+}
+
+uint32_t spirv::TargetEnv::getDeviceID() const {
+ return targetAttr.getDeviceID();
+}
+
+spirv::ResourceLimitsAttr spirv::TargetEnv::getResourceLimits() const {
+ return targetAttr.getResourceLimits();
+}
+
MLIRContext *spirv::TargetEnv::getContext() const {
return targetAttr.getContext();
}
More information about the Mlir-commits
mailing list