[mlir] fix bytecode writer after c1eab57673

The change in c1eab57 fixed the
behavior of `getDiscardableAttrDictionary` for ops that are not using
properties to only return discardable attributes. Bytecode writer was
relying on the wrong behavior and would assume all attributes are
discardable, without appropriate testing. Fix that and add a test.
This commit is contained in:
Alex Zinenko
2024-01-04 09:45:30 +00:00
parent 26993f6167
commit 985bb3a20a
3 changed files with 68 additions and 5 deletions

View File

@@ -962,9 +962,12 @@ LogicalResult BytecodeWriter::writeOp(EncodingEmitter &emitter, Operation *op) {
DictionaryAttr attrs = op->getDiscardableAttrDictionary();
// Allow deployment to version <kNativePropertiesEncoding by merging inherent
// attribute with the discardable ones. We should fail if there are any
// conflicts.
if (config.bytecodeVersion < bytecode::kNativePropertiesEncoding)
// conflicts. When properties are not used by the op, also store everything as
// attributes.
if (config.bytecodeVersion < bytecode::kNativePropertiesEncoding ||
!op->getPropertiesStorage()) {
attrs = op->getAttrDictionary();
}
if (!attrs.empty()) {
opEncodingMask |= bytecode::OpEncodingMask::kHasAttrs;
emitter.emitVarInt(numberingState.getNumber(attrs));

View File

@@ -425,9 +425,10 @@ void IRNumberingState::number(Operation &op) {
// Only number the operation's dictionary if it isn't empty.
DictionaryAttr dictAttr = op.getDiscardableAttrDictionary();
// Prior to version 5 we need to number also the merged dictionnary
// containing both the inherent and discardable attribute.
if (config.getDesiredBytecodeVersion() < 5)
// Prior to version 5, or when properties are not used, we need to number also
// the merged dictionary containing both the inherent and discardable
// attribute.
if (config.getDesiredBytecodeVersion() < 5 || !op.getPropertiesStorage())
dictAttr = op.getAttrDictionary();
if (!dictAttr.empty())
number(dictAttr);