summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp')
-rw-r--r--mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
index 575d995bf45..bc0b706092c 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
@@ -28,6 +28,7 @@
#include "mlir/IR/Builders.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/StringExtras.h"
+#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/bit.h"
#include "llvm/Support/raw_ostream.h"
@@ -148,6 +149,11 @@ private:
return emitError(loc, "unhandled decoraion for type:") << type;
}
+ /// Process member decoration
+ LogicalResult processMemberDecoration(uint32_t structID, uint32_t memberNum,
+ spirv::Decoration decorationType,
+ uint32_t value);
+
//===--------------------------------------------------------------------===//
// Types
//===--------------------------------------------------------------------===//
@@ -411,6 +417,16 @@ LogicalResult Serializer::processTypeDecoration<spirv::ArrayType>(
}
return success();
}
+
+LogicalResult
+Serializer::processMemberDecoration(uint32_t structID, uint32_t memberIndex,
+ spirv::Decoration decorationType,
+ uint32_t value) {
+ SmallVector<uint32_t, 4> args(
+ {structID, memberIndex, static_cast<uint32_t>(decorationType), value});
+ return encodeInstructionInto(decorations, spirv::Opcode::OpMemberDecorate,
+ args);
+}
} // namespace
LogicalResult Serializer::processFuncOp(FuncOp op) {
@@ -618,6 +634,31 @@ Serializer::prepareBasicType(Location loc, Type type, uint32_t resultID,
return success();
}
+ if (auto structType = type.dyn_cast<spirv::StructType>()) {
+ bool hasLayout = structType.hasLayout();
+ for (auto elementIndex :
+ llvm::seq<uint32_t>(0, structType.getNumElements())) {
+ uint32_t elementTypeID = 0;
+ if (failed(processType(loc, structType.getElementType(elementIndex),
+ elementTypeID))) {
+ return failure();
+ }
+ operands.push_back(elementTypeID);
+ if (hasLayout) {
+ // Decorate each struct member with an offset
+ if (failed(processMemberDecoration(
+ resultID, elementIndex, spirv::Decoration::Offset,
+ static_cast<uint32_t>(structType.getOffset(elementIndex))))) {
+ return emitError(loc, "cannot decorate ")
+ << elementIndex << "-th member of : " << structType
+ << "with its offset";
+ }
+ }
+ }
+ typeEnum = spirv::Opcode::OpTypeStruct;
+ return success();
+ }
+
// TODO(ravishankarm) : Handle other types.
return emitError(loc, "unhandled type in serialization: ") << type;
}
OpenPOWER on IntegriCloud