diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -271,6 +271,8 @@ return parseBytes(static_cast(length), sectionData); } + Location getLoc() const { return fileLoc; } + private: /// Parse a variable length encoded integer from the byte stream. This method /// is a fallback when the number of bytes used to encode the value is greater @@ -835,6 +837,13 @@ return reader.emitError(msg); } + DialectReader withEncodingReader(EncodingReader &encReader) { + return DialectReader(attrTypeReader, stringReader, resourceReader, + encReader); + } + + Location getLoc() const { return reader.getLoc(); } + //===--------------------------------------------------------------------===// // IR //===--------------------------------------------------------------------===// @@ -1054,7 +1063,6 @@ DialectReader dialectReader(*this, stringReader, resourceReader, reader); if (failed(entry.dialect->load(dialectReader, fileLoc.getContext()))) return failure(); - // Ensure that the dialect implements the bytecode interface. if (!entry.dialect->interface) { return reader.emitError("dialect '", entry.dialect->name, @@ -1378,7 +1386,9 @@ << name << "' does not implement the bytecode interface, " "but found a version entry"; - loadedVersion = interface->readVersion(reader); + EncodingReader encReader(versionBuffer, reader.getLoc()); + DialectReader versionReader = reader.withEncodingReader(encReader); + loadedVersion = interface->readVersion(versionReader); if (!loadedVersion) return failure(); } @@ -1448,9 +1458,8 @@ // haven't, load the dialect and build the operation name. if (!opName->opName) { // Load the dialect and its version. - EncodingReader versionReader(opName->dialect->versionBuffer, fileLoc); DialectReader dialectReader(attrTypeReader, stringReader, resourceReader, - versionReader); + reader); if (failed(opName->dialect->load(dialectReader, getContext()))) return failure(); opName->opName.emplace((opName->dialect->name + "." + opName->name).str(), diff --git a/mlir/test/Bytecode/general.mlir b/mlir/test/Bytecode/general.mlir --- a/mlir/test/Bytecode/general.mlir +++ b/mlir/test/Bytecode/general.mlir @@ -4,6 +4,7 @@ // UNSUPPORTED: target=s390x-{{.*}} // CHECK-LABEL: "bytecode.test1" +// CHECK-NEXT: "unregistered.op"() {test_attr = #test.dynamic_singleton} : () -> () // CHECK-NEXT: "bytecode.empty"() : () -> () // CHECK-NEXT: "bytecode.attributes"() {attra = 10 : i64, attrb = #bytecode.attr} : () -> () // CHECK-NEXT{LITERAL}: "bytecode.sparse"() {value = sparse<[[2, 1], [1, 1], [1, 2]], [1. @@ -21,6 +22,7 @@ // CHECK-NEXT: }) : () -> () "bytecode.test1"() ({ + "unregistered.op"() {test_attr = #test.dynamic_singleton} : () -> () "bytecode.empty"() : () -> () "bytecode.attributes"() {attra = 10, attrb = #bytecode.attr} : () -> () %cst = "bytecode.sparse"() {value = sparse<[[2, 1], [1, 1], [1, 2]], [1.0, 5.0, 6.0]> : tensor<8x7xf32>} : () -> (tensor<8x7xf32>) diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -128,8 +128,7 @@ writer.writeVarInt(concreteAttr.getV1()); return success(); } - writer.writeAttribute(attr); - return success(); + return failure(); } Attribute readAttribute(DialectBytecodeReader &reader,