summaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode
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
parent705fb08be1eb723994edae31aa49ff3b8fa15669 (diff)
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')
-rw-r--r--mlir/lib/Bytecode/Reader/BytecodeReader.cpp30
-rw-r--r--mlir/lib/Bytecode/Writer/IRNumbering.cpp6
-rw-r--r--mlir/lib/Bytecode/Writer/IRNumbering.h3
3 files changed, 28 insertions, 11 deletions
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index 8269546d9836..0639baf10b0b 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();
diff --git a/mlir/lib/Bytecode/Writer/IRNumbering.cpp b/mlir/lib/Bytecode/Writer/IRNumbering.cpp
index 2547d815c12b..284b3c02f1f2 100644
--- a/mlir/lib/Bytecode/Writer/IRNumbering.cpp
+++ b/mlir/lib/Bytecode/Writer/IRNumbering.cpp
@@ -48,7 +48,7 @@ struct IRNumberingState::NumberingDialectWriter : public DialectBytecodeWriter {
void writeOwnedBool(bool value) override {}
int64_t getBytecodeVersion() const override {
- llvm_unreachable("unexpected querying of version in IRNumbering");
+ return state.getDesiredBytecodeVersion();
}
/// The parent numbering state that is populated by this writer.
@@ -391,6 +391,10 @@ void IRNumberingState::number(Dialect *dialect,
}
}
+int64_t IRNumberingState::getDesiredBytecodeVersion() const {
+ return config.getDesiredBytecodeVersion();
+}
+
namespace {
/// A dummy resource builder used to number dialect resources.
struct NumberingResourceBuilder : public AsmResourceBuilder {
diff --git a/mlir/lib/Bytecode/Writer/IRNumbering.h b/mlir/lib/Bytecode/Writer/IRNumbering.h
index c10e09ade6e4..ca30078f3468 100644
--- a/mlir/lib/Bytecode/Writer/IRNumbering.h
+++ b/mlir/lib/Bytecode/Writer/IRNumbering.h
@@ -186,6 +186,9 @@ public:
return blockOperationCounts[block];
}
+ /// Get the set desired bytecode version to emit.
+ int64_t getDesiredBytecodeVersion() const;
+
private:
/// This class is used to provide a fake dialect writer for numbering nested
/// attributes and types.