summaryrefslogtreecommitdiff
path: root/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@google.com>2022-08-09 14:03:54 -0400
committerLei Zhang <antiagainst@google.com>2022-08-09 14:14:54 -0400
commita29fffc4752a10494a74bb9f8db9b885c8aa5af1 (patch)
treeec774786586c179e21184d004d148e9e500e430d /mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
parentb09f6b471fd251d1827e9478b944ef15927e5526 (diff)
[mlir][spirv] Migrate to use specalized enum attributes
Previously we are using IntegerAttr to back all SPIR-V enum attributes. Therefore we all such attributes are showed like IntegerAttr in IRs, which is barely readable and breaks roundtripability of the IR. This commit changes to use `EnumAttr` as the base directly so that we can have separate attribute definitions and better IR printing. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D131311
Diffstat (limited to 'mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp')
-rw-r--r--mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp53
1 files changed, 7 insertions, 46 deletions
diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
index ad1724f9269f..22fff8044004 100644
--- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
+++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
@@ -13,6 +13,7 @@
#include "Serializer.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h"
#include "mlir/IR/RegionGraphTraits.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Target/SPIRV/SPIRVBinaryUtils.h"
@@ -277,8 +278,8 @@ LogicalResult Serializer::processVariableOp(spirv::VariableOp op) {
operands.push_back(resultID);
auto attr = op->getAttr(spirv::attributeName<spirv::StorageClass>());
if (attr) {
- operands.push_back(static_cast<uint32_t>(
- attr.cast<IntegerAttr>().getValue().getZExtValue()));
+ operands.push_back(
+ static_cast<uint32_t>(attr.cast<spirv::StorageClassAttr>().getValue()));
}
elidedAttrs.push_back(spirv::attributeName<spirv::StorageClass>());
for (auto arg : op.getODSOperands(0)) {
@@ -567,27 +568,6 @@ Serializer::processOp<spirv::EntryPointOp>(spirv::EntryPointOp op) {
template <>
LogicalResult
-Serializer::processOp<spirv::ControlBarrierOp>(spirv::ControlBarrierOp op) {
- StringRef argNames[] = {"execution_scope", "memory_scope",
- "memory_semantics"};
- SmallVector<uint32_t, 3> operands;
-
- for (auto argName : argNames) {
- auto argIntAttr = op->getAttrOfType<IntegerAttr>(argName);
- auto operand = prepareConstantInt(op.getLoc(), argIntAttr);
- if (!operand) {
- return failure();
- }
- operands.push_back(operand);
- }
-
- encodeInstructionInto(functionBody, spirv::Opcode::OpControlBarrier,
- operands);
- return success();
-}
-
-template <>
-LogicalResult
Serializer::processOp<spirv::ExecutionModeOp>(spirv::ExecutionModeOp op) {
SmallVector<uint32_t, 4> operands;
// Add the function <id>.
@@ -617,25 +597,6 @@ Serializer::processOp<spirv::ExecutionModeOp>(spirv::ExecutionModeOp op) {
template <>
LogicalResult
-Serializer::processOp<spirv::MemoryBarrierOp>(spirv::MemoryBarrierOp op) {
- StringRef argNames[] = {"memory_scope", "memory_semantics"};
- SmallVector<uint32_t, 2> operands;
-
- for (auto argName : argNames) {
- auto argIntAttr = op->getAttrOfType<IntegerAttr>(argName);
- auto operand = prepareConstantInt(op.getLoc(), argIntAttr);
- if (!operand) {
- return failure();
- }
- operands.push_back(operand);
- }
-
- encodeInstructionInto(functionBody, spirv::Opcode::OpMemoryBarrier, operands);
- return success();
-}
-
-template <>
-LogicalResult
Serializer::processOp<spirv::FunctionCallOp>(spirv::FunctionCallOp op) {
auto funcName = op.callee();
uint32_t resTypeID = 0;
@@ -674,8 +635,8 @@ Serializer::processOp<spirv::CopyMemoryOp>(spirv::CopyMemoryOp op) {
}
if (auto attr = op->getAttr("memory_access")) {
- operands.push_back(static_cast<uint32_t>(
- attr.cast<IntegerAttr>().getValue().getZExtValue()));
+ operands.push_back(
+ static_cast<uint32_t>(attr.cast<spirv::MemoryAccessAttr>().getValue()));
}
elidedAttrs.push_back("memory_access");
@@ -688,8 +649,8 @@ Serializer::processOp<spirv::CopyMemoryOp>(spirv::CopyMemoryOp op) {
elidedAttrs.push_back("alignment");
if (auto attr = op->getAttr("source_memory_access")) {
- operands.push_back(static_cast<uint32_t>(
- attr.cast<IntegerAttr>().getValue().getZExtValue()));
+ operands.push_back(
+ static_cast<uint32_t>(attr.cast<spirv::MemoryAccessAttr>().getValue()));
}
elidedAttrs.push_back("source_memory_access");