[Mlir-commits] [mlir] [mlir][SPIR-V] Add OpDecorateId support for Id-form decorations (PR #194611)
Igor Wodiany
llvmlistbot at llvm.org
Wed Apr 29 09:47:53 PDT 2026
================
@@ -377,12 +380,69 @@ LogicalResult spirv::Deserializer::processDecoration(ArrayRef<uint32_t> words) {
return res;
break;
}
+ case spirv::Decoration::AlignmentId:
+ case spirv::Decoration::MaxByteOffsetId:
+ case spirv::Decoration::CounterBuffer:
+ if (words.size() != 3) {
+ return emitError(unknownLoc, "OpDecorateId with ")
+ << decorationName << " needs a single <id> operand";
+ }
+ pendingIdDecorations.push_back({words[0],
+ static_cast<spirv::Decoration>(words[1]),
+ words[2], unknownLoc});
+ break;
default:
return emitError(unknownLoc, "unhandled Decoration : '") << decorationName;
}
return success();
}
+LogicalResult spirv::Deserializer::resolveDeferredIdDecorations() {
+ for (const DeferredIdDecoration &entry : pendingIdDecorations) {
+ StringRef decorationName = stringifyDecoration(entry.decoration);
+ StringAttr symbol = getSymbolDecoration(decorationName);
+
+ // Resolve the operand <id> to a symbol name. The operand must reference a
+ // module-scope symbol op (global variable or specialization constant).
+ StringRef operandSymName;
+ if (spirv::GlobalVariableOp varOp =
+ globalVariableMap.lookup(entry.operandID))
+ operandSymName = varOp.getSymName();
+ else if (spirv::SpecConstantOp specOp =
+ specConstMap.lookup(entry.operandID))
+ operandSymName = specOp.getSymName();
+ else
+ return emitError(entry.loc, "OpDecorateId with ")
+ << decorationName << " references <id> " << entry.operandID
+ << " which is not a global variable or specialization constant";
+
+ auto symRef = FlatSymbolRefAttr::get(context, operandSymName);
+
+ // Resolve the decoration target. By the time this method runs, all
+ // instructions have been processed, so every defined <id> must appear in
+ // one of these maps; an unresolved target indicates malformed input.
+ Operation *targetOp = nullptr;
+ if (spirv::GlobalVariableOp varOp =
+ globalVariableMap.lookup(entry.targetID))
+ targetOp = varOp;
+ else if (spirv::SpecConstantOp specOp = specConstMap.lookup(entry.targetID))
+ targetOp = specOp;
+ else if (spirv::FuncOp fnOp = funcMap.lookup(entry.targetID))
+ targetOp = fnOp;
+ else if (Value v = valueMap.lookup(entry.targetID))
+ targetOp = v.getDefiningOp();
+
+ if (!targetOp)
+ return emitError(entry.loc, "OpDecorateId with ")
+ << decorationName << " references unknown target <id> "
+ << entry.targetID;
+
+ targetOp->setAttr(symbol, symRef);
+ }
+ pendingIdDecorations.clear();
----------------
IgWod wrote:
nit: Considering deserialization is almost done, do we need that?
https://github.com/llvm/llvm-project/pull/194611
More information about the Mlir-commits
mailing list