Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,14 @@ spirv::Deserializer::processMemoryModel(ArrayRef<uint32_t> operands) {
if (operands.size() != 2)
return emitError(unknownLoc, "OpMemoryModel must have two operands");

StringRef addressing_model = module->getAddressingModelAttrName().strref();
Copy link
Collaborator

@joker-eph joker-eph Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why StringRef instead of StringAttr?
We'll use string comparison instead of pointer comparison...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I alter this all across the place?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

(*module)->setAttr(
"addressing_model",
addressing_model,
opBuilder.getAttr<spirv::AddressingModelAttr>(
static_cast<spirv::AddressingModel>(operands.front())));
(*module)->setAttr("memory_model",

StringRef memory_model = module->getMemoryModelAttrName().strref();
(*module)->setAttr(memory_model,
opBuilder.getAttr<spirv::MemoryModelAttr>(
static_cast<spirv::MemoryModel>(operands.back())));

Expand Down
20 changes: 12 additions & 8 deletions mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,33 +708,37 @@ Serializer::processOp<spirv::CopyMemoryOp>(spirv::CopyMemoryOp op) {
operands.push_back(id);
}

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

elidedAttrs.push_back("memory_access");
elidedAttrs.push_back(memory_access);

if (auto attr = op->getAttr("alignment")) {
StringRef alignment = op.getAlignmentAttrName().strref();
if (auto attr = op->getAttr(alignment)) {
operands.push_back(static_cast<uint32_t>(
cast<IntegerAttr>(attr).getValue().getZExtValue()));
}

elidedAttrs.push_back("alignment");
elidedAttrs.push_back(alignment);

if (auto attr = op->getAttr("source_memory_access")) {
StringRef source_memory_access = op.getSourceMemoryAccessAttrName().strref();
if (auto attr = op->getAttr(source_memory_access)) {
operands.push_back(
static_cast<uint32_t>(cast<spirv::MemoryAccessAttr>(attr).getValue()));
}

elidedAttrs.push_back("source_memory_access");
elidedAttrs.push_back(source_memory_access);

if (auto attr = op->getAttr("source_alignment")) {
StringRef source_alignment = op.getSourceAlignmentAttrName().strref();
if (auto attr = op->getAttr(source_alignment)) {
operands.push_back(static_cast<uint32_t>(
cast<IntegerAttr>(attr).getValue().getZExtValue()));
}

elidedAttrs.push_back("source_alignment");
elidedAttrs.push_back(source_alignment);
if (failed(emitDebugLine(functionBody, op.getLoc())))
return failure();
encodeInstructionInto(functionBody, spirv::Opcode::OpCopyMemory, operands);
Expand Down
7 changes: 5 additions & 2 deletions mlir/lib/Target/SPIRV/Serialization/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,13 @@ void Serializer::processExtension() {
}

void Serializer::processMemoryModel() {
StringRef memory_model = module.getMemoryModelAttrName().strref();
auto mm = static_cast<uint32_t>(
module->getAttrOfType<spirv::MemoryModelAttr>("memory_model").getValue());
module->getAttrOfType<spirv::MemoryModelAttr>(memory_model).getValue());

StringRef addressing_model = module.getAddressingModelAttrName().strref();
auto am = static_cast<uint32_t>(
module->getAttrOfType<spirv::AddressingModelAttr>("addressing_model")
module->getAttrOfType<spirv::AddressingModelAttr>(addressing_model)
.getValue());

encodeInstructionInto(memoryModel, spirv::Opcode::OpMemoryModel, {am, mm});
Expand Down