summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
diff options
context:
space:
mode:
authorDenis Khalikov <dennis.khalikov@gmail.com>2019-08-16 10:17:47 -0700
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-08-16 10:18:14 -0700
commitcf358017e644c1b35fde151adc444ac058771b45 (patch)
tree14b0efa26f9e4a5b8d3be66c86b78c8edb353350 /mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
parent9c29273ddc4666dd2dc1df53cc2901a59bad0b03 (diff)
downloadbcm5719-llvm-cf358017e644c1b35fde151adc444ac058771b45.tar.gz
bcm5719-llvm-cf358017e644c1b35fde151adc444ac058771b45.zip
[spirv] Extend spv.array with Layoutinfo
Extend spv.array with Layoutinfo to support (de)serialization. Closes tensorflow/mlir#80 PiperOrigin-RevId: 263795304
Diffstat (limited to 'mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp')
-rw-r--r--mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
index 8b55873c5c0..d06363a1a8c 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
@@ -132,6 +132,12 @@ private:
LogicalResult processDecoration(Location loc, uint32_t resultID,
NamedAttribute attr);
+ template <typename DType>
+ LogicalResult processTypeDecoration(Location loc, DType type,
+ uint32_t resultId) {
+ return emitError(loc, "unhandled decoraion for type:") << type;
+ }
+
//===--------------------------------------------------------------------===//
// Types
//===--------------------------------------------------------------------===//
@@ -148,7 +154,7 @@ private:
/// Method for preparing basic SPIR-V type serialization. Returns the type's
/// opcode and operands for the instruction via `typeEnum` and `operands`.
- LogicalResult prepareBasicType(Location loc, Type type,
+ LogicalResult prepareBasicType(Location loc, Type type, uint32_t resultID,
spirv::Opcode &typeEnum,
SmallVectorImpl<uint32_t> &operands);
@@ -366,6 +372,22 @@ LogicalResult Serializer::processDecoration(Location loc, uint32_t resultID,
return encodeInstructionInto(decorations, spirv::Opcode::OpDecorate, args);
}
+namespace {
+template <>
+LogicalResult Serializer::processTypeDecoration<spirv::ArrayType>(
+ Location loc, spirv::ArrayType type, uint32_t resultID) {
+ if (type.hasLayout()) {
+ // OpDecorate %arrayTypeSSA ArrayStride strideLiteral
+ SmallVector<uint32_t, 3> args;
+ args.push_back(resultID);
+ args.push_back(static_cast<uint32_t>(spirv::Decoration::ArrayStride));
+ args.push_back(type.getArrayStride());
+ return encodeInstructionInto(decorations, spirv::Opcode::OpDecorate, args);
+ }
+ return success();
+}
+} // namespace
+
LogicalResult Serializer::processFuncOp(FuncOp op) {
uint32_t fnTypeID = 0;
// Generate type of the function.
@@ -445,7 +467,7 @@ LogicalResult Serializer::processType(Location loc, Type type,
if ((type.isa<FunctionType>() &&
succeeded(prepareFunctionType(loc, type.cast<FunctionType>(), typeEnum,
operands))) ||
- succeeded(prepareBasicType(loc, type, typeEnum, operands))) {
+ succeeded(prepareBasicType(loc, type, typeID, typeEnum, operands))) {
typeIDMap[type] = typeID;
return encodeInstructionInto(typesGlobalValues, typeEnum, operands);
}
@@ -453,7 +475,8 @@ LogicalResult Serializer::processType(Location loc, Type type,
}
LogicalResult
-Serializer::prepareBasicType(Location loc, Type type, spirv::Opcode &typeEnum,
+Serializer::prepareBasicType(Location loc, Type type, uint32_t resultID,
+ spirv::Opcode &typeEnum,
SmallVectorImpl<uint32_t> &operands) {
if (isVoidType(type)) {
typeEnum = spirv::Opcode::OpTypeVoid;
@@ -501,9 +524,8 @@ Serializer::prepareBasicType(Location loc, Type type, spirv::Opcode &typeEnum,
loc, mlirBuilder.getI32IntegerAttr(arrayType.getNumElements()),
/*isSpec=*/false)) {
operands.push_back(elementCountID);
- return success();
}
- return failure();
+ return processTypeDecoration(loc, arrayType, resultID);
}
if (auto ptrType = type.dyn_cast<spirv::PointerType>()) {
OpenPOWER on IntegriCloud