diff options
| author | Denis Khalikov <dennis.khalikov@gmail.com> | 2019-08-27 10:41:07 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-08-27 10:41:42 -0700 |
| commit | 8f2dfb51d4a448754f0c76a8f4d97643d73add3c (patch) | |
| tree | 49d3ccb723ce5807331508fe3bb2959e0f670774 /mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp | |
| parent | 2f59f7687636d7140298bdc5fbbb5911e0d223ef (diff) | |
| download | bcm5719-llvm-8f2dfb51d4a448754f0c76a8f4d97643d73add3c.tar.gz bcm5719-llvm-8f2dfb51d4a448754f0c76a8f4d97643d73add3c.zip | |
[spirv] Add Block decoration for spv.struct.
Add Block decoration for top-level spv.struct.
Closes tensorflow/mlir#102
PiperOrigin-RevId: 265716241
Diffstat (limited to 'mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp')
| -rw-r--r-- | mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp index 3f1b01372c9..03973db0d95 100644 --- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp @@ -174,6 +174,10 @@ private: bool isVoidType(Type type) const { return type.isa<NoneType>(); } + /// Returns true if the given type is a pointer type to a struct in Uniform or + /// StorageBuffer storage class. + bool isInterfaceStructPtrType(Type type) const; + /// Main dispatch method for serializing a type. The result <id> of the /// serialized type will be returned as `typeID`. LogicalResult processType(Location loc, Type type, uint32_t &typeID); @@ -558,6 +562,22 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) { if (failed(processType(varOp.getLoc(), varOp.type(), resultTypeID))) { return failure(); } + + if (isInterfaceStructPtrType(varOp.type())) { + auto structType = varOp.type() + .cast<spirv::PointerType>() + .getPointeeType() + .cast<spirv::StructType>(); + SmallVector<uint32_t, 2> args{ + findTypeID(structType), + static_cast<uint32_t>(spirv::Decoration::Block)}; + if (failed(encodeInstructionInto(decorations, spirv::Opcode::OpDecorate, + args))) { + return varOp.emitError("cannot decorate ") + << structType << " with Block decoration"; + } + } + elidedAttrs.push_back("type"); SmallVector<uint32_t, 4> operands; operands.push_back(resultTypeID); @@ -609,6 +629,17 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) { // Type //===----------------------------------------------------------------------===// +bool Serializer::isInterfaceStructPtrType(Type type) const { + if (auto ptrType = type.dyn_cast<spirv::PointerType>()) { + auto storageClass = ptrType.getStorageClass(); + if (storageClass == spirv::StorageClass::Uniform || + storageClass == spirv::StorageClass::StorageBuffer) { + return ptrType.getPointeeType().isa<spirv::StructType>(); + } + } + return false; +} + LogicalResult Serializer::processType(Location loc, Type type, uint32_t &typeID) { typeID = findTypeID(type); |

