[Mlir-commits] [mlir] 8a66bb7 - [MLIR][SPIRV] Added storage class constraint on global variable
George Mitenkov
llvmlistbot at llvm.org
Tue Jul 28 23:15:37 PDT 2020
Author: George Mitenkov
Date: 2020-07-29T09:15:00+03:00
New Revision: 8a66bb7a75f71a749e9ee603c9c5c8d016ed7238
URL: https://github.com/llvm/llvm-project/commit/8a66bb7a75f71a749e9ee603c9c5c8d016ed7238
DIFF: https://github.com/llvm/llvm-project/commit/8a66bb7a75f71a749e9ee603c9c5c8d016ed7238.diff
LOG: [MLIR][SPIRV] Added storage class constraint on global variable
Added a check for 'Function' storage class in `spv.globalVariable`
verifier since it only can be used with `spv.Variable`.
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D84731
Added:
Modified:
mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
mlir/test/Dialect/SPIRV/structure-ops.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
index 9d0570257d42..b0235d419ebe 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
@@ -1955,8 +1955,13 @@ static LogicalResult verify(spirv::GlobalVariableOp varOp) {
// SPIR-V spec: "Storage Class is the Storage Class of the memory holding the
// object. It cannot be Generic. It must be the same as the Storage Class
// operand of the Result Type."
- if (varOp.storageClass() == spirv::StorageClass::Generic)
- return varOp.emitOpError("storage class cannot be 'Generic'");
+ // Also, Function storage class is reserved by spv.Variable.
+ auto storageClass = varOp.storageClass();
+ if (storageClass == spirv::StorageClass::Generic ||
+ storageClass == spirv::StorageClass::Function) {
+ return varOp.emitOpError("storage class cannot be '")
+ << stringifyStorageClass(storageClass) << "'";
+ }
if (auto init =
varOp.getAttrOfType<FlatSymbolRefAttr>(kInitializerAttrName)) {
diff --git a/mlir/test/Dialect/SPIRV/structure-ops.mlir b/mlir/test/Dialect/SPIRV/structure-ops.mlir
index 2d62f64b2479..e20da2e4e6c9 100644
--- a/mlir/test/Dialect/SPIRV/structure-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/structure-ops.mlir
@@ -347,6 +347,13 @@ spv.module Logical GLSL450 {
// -----
+spv.module Logical GLSL450 {
+ // expected-error @+1 {{storage class cannot be 'Function'}}
+ spv.globalVariable @var0 : !spv.ptr<f32, Function>
+}
+
+// -----
+
spv.module Logical GLSL450 {
spv.func @foo() "None" {
// expected-error @+1 {{op must appear in a module-like op's block}}
More information about the Mlir-commits
mailing list