[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
This commit is contained in:
George Mitenkov 2020-07-29 08:47:22 +03:00
parent b1e398920f
commit 8a66bb7a75
2 changed files with 14 additions and 2 deletions

View File

@ -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)) {

View File

@ -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}}