Skip to content

Commit ef27289

Browse files
author
SahilPatidar
committed
[mlir][spirv] Replace hardcoded attribute strings with op methods
1 parent fcb6737 commit ef27289

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -708,33 +708,37 @@ Serializer::processOp<spirv::CopyMemoryOp>(spirv::CopyMemoryOp op) {
708708
operands.push_back(id);
709709
}
710710

711-
if (auto attr = op->getAttr("memory_access")) {
711+
StringRef memory_access = op.getMemoryAccessAttrName().strref();
712+
if (auto attr = op->getAttr(memory_access)) {
712713
operands.push_back(
713714
static_cast<uint32_t>(cast<spirv::MemoryAccessAttr>(attr).getValue()));
714715
}
715716

716-
elidedAttrs.push_back("memory_access");
717+
elidedAttrs.push_back(memory_access);
717718

718-
if (auto attr = op->getAttr("alignment")) {
719+
StringRef alignment = op.getAlignmentAttrName().strref();
720+
if (auto attr = op->getAttr(alignment)) {
719721
operands.push_back(static_cast<uint32_t>(
720722
cast<IntegerAttr>(attr).getValue().getZExtValue()));
721723
}
722724

723-
elidedAttrs.push_back("alignment");
725+
elidedAttrs.push_back(alignment);
724726

725-
if (auto attr = op->getAttr("source_memory_access")) {
727+
StringRef source_memory_access = op.getSourceMemoryAccessAttrName().strref();
728+
if (auto attr = op->getAttr(source_memory_access)) {
726729
operands.push_back(
727730
static_cast<uint32_t>(cast<spirv::MemoryAccessAttr>(attr).getValue()));
728731
}
729732

730-
elidedAttrs.push_back("source_memory_access");
733+
elidedAttrs.push_back(source_memory_access);
731734

732-
if (auto attr = op->getAttr("source_alignment")) {
735+
StringRef source_alignment = op.getSourceAlignmentAttrName().strref();
736+
if (auto attr = op->getAttr(source_alignment)) {
733737
operands.push_back(static_cast<uint32_t>(
734738
cast<IntegerAttr>(attr).getValue().getZExtValue()));
735739
}
736740

737-
elidedAttrs.push_back("source_alignment");
741+
elidedAttrs.push_back(source_alignment);
738742
if (failed(emitDebugLine(functionBody, op.getLoc())))
739743
return failure();
740744
encodeInstructionInto(functionBody, spirv::Opcode::OpCopyMemory, operands);

0 commit comments

Comments
 (0)