aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
diff options
context:
space:
mode:
authorMehdi Amini <joker.eph@gmail.com>2023-07-20 22:51:35 -0700
committerMehdi Amini <joker.eph@gmail.com>2023-07-24 11:37:57 -0700
commit20b93abca6516bbb23689c3777536fea04e46e14 (patch)
treec9a60d5bc6c6c96b6a4944b57c6e4d34b251d753 /mlir/lib/Bytecode/Reader/BytecodeReader.cpp
parent705fb08be1eb723994edae31aa49ff3b8fa15669 (diff)
downloadllvm-20b93abca6516bbb23689c3777536fea04e46e14.zip
llvm-20b93abca6516bbb23689c3777536fea04e46e14.tar.gz
llvm-20b93abca6516bbb23689c3777536fea04e46e14.tar.bz2
Update ODS variadic segments "magic" attributes to use native Properties
The operand_segment_sizes and result_segment_sizes Attributes are now inlined in the operation as native propertie. We continue to support building an Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the property from an attribute with `setAttr("operand_segment_sizes", attr)`. A new bytecode version is introduced to support backward compatibility and backdeployments. Differential Revision: https://reviews.llvm.org/D155919
Diffstat (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp')
-rw-r--r--mlir/lib/Bytecode/Reader/BytecodeReader.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index 8269546..0639baf 100644
--- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -796,9 +796,10 @@ class AttrTypeReader {
public:
AttrTypeReader(StringSectionReader &stringReader,
- ResourceSectionReader &resourceReader, Location fileLoc)
+ ResourceSectionReader &resourceReader, Location fileLoc,
+ uint64_t &bytecodeVersion)
: stringReader(stringReader), resourceReader(resourceReader),
- fileLoc(fileLoc) {}
+ fileLoc(fileLoc), bytecodeVersion(bytecodeVersion) {}
/// Initialize the attribute and type information within the reader.
LogicalResult initialize(MutableArrayRef<BytecodeDialect> dialects,
@@ -883,23 +884,30 @@ private:
/// A location used for error emission.
Location fileLoc;
+
+ /// Current bytecode version being used.
+ uint64_t &bytecodeVersion;
};
class DialectReader : public DialectBytecodeReader {
public:
DialectReader(AttrTypeReader &attrTypeReader,
StringSectionReader &stringReader,
- ResourceSectionReader &resourceReader, EncodingReader &reader)
+ ResourceSectionReader &resourceReader, EncodingReader &reader,
+ uint64_t &bytecodeVersion)
: attrTypeReader(attrTypeReader), stringReader(stringReader),
- resourceReader(resourceReader), reader(reader) {}
+ resourceReader(resourceReader), reader(reader),
+ bytecodeVersion(bytecodeVersion) {}
InFlightDiagnostic emitError(const Twine &msg) override {
return reader.emitError(msg);
}
+ uint64_t getBytecodeVersion() const override { return bytecodeVersion; }
+
DialectReader withEncodingReader(EncodingReader &encReader) {
return DialectReader(attrTypeReader, stringReader, resourceReader,
- encReader);
+ encReader, bytecodeVersion);
}
Location getLoc() const { return reader.getLoc(); }
@@ -1003,6 +1011,7 @@ private:
StringSectionReader &stringReader;
ResourceSectionReader &resourceReader;
EncodingReader &reader;
+ uint64_t &bytecodeVersion;
};
/// Wraps the properties section and handles reading properties out of it.
@@ -1207,7 +1216,8 @@ template <typename T>
LogicalResult AttrTypeReader::parseCustomEntry(Entry<T> &entry,
EncodingReader &reader,
StringRef entryType) {
- DialectReader dialectReader(*this, stringReader, resourceReader, reader);
+ DialectReader dialectReader(*this, stringReader, resourceReader, reader,
+ bytecodeVersion);
if (failed(entry.dialect->load(dialectReader, fileLoc.getContext())))
return failure();
// Ensure that the dialect implements the bytecode interface.
@@ -1252,7 +1262,7 @@ public:
llvm::MemoryBufferRef buffer,
const std::shared_ptr<llvm::SourceMgr> &bufferOwnerRef)
: config(config), fileLoc(fileLoc), lazyLoading(lazyLoading),
- attrTypeReader(stringReader, resourceReader, fileLoc),
+ attrTypeReader(stringReader, resourceReader, fileLoc, version),
// Use the builtin unrealized conversion cast operation to represent
// forward references to values that aren't yet defined.
forwardRefOpState(UnknownLoc::get(config.getContext()),
@@ -1782,7 +1792,7 @@ BytecodeReader::Impl::parseOpName(EncodingReader &reader,
if (!opName->opName) {
// Load the dialect and its version.
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
- reader);
+ reader, version);
if (failed(opName->dialect->load(dialectReader, getContext())))
return failure();
// If the opName is empty, this is because we use to accept names such as
@@ -1825,7 +1835,7 @@ LogicalResult BytecodeReader::Impl::parseResourceSection(
// Initialize the resource reader with the resource sections.
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
- reader);
+ reader, version);
return resourceReader.initialize(fileLoc, config, dialects, stringReader,
*resourceData, *resourceOffsetData,
dialectReader, bufferOwnerRef);
@@ -2186,7 +2196,7 @@ BytecodeReader::Impl::parseOpWithoutRegions(EncodingReader &reader,
// interface and control the serialization.
if (wasRegistered) {
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
- reader);
+ reader, version);
if (failed(
propertiesReader.read(fileLoc, dialectReader, &*opName, opState)))
return failure();