diff options
| author | Mehdi Amini <joker.eph@gmail.com> | 2023-05-01 08:43:50 -0700 |
|---|---|---|
| committer | Mehdi Amini <joker.eph@gmail.com> | 2023-05-25 15:15:47 -0700 |
| commit | 837d1ce0dc8eec5b17255291b3462e6296cb369b (patch) | |
| tree | 02a2f1982131b75dcafc7ddb577d959f016fc629 /mlir/test/lib/Dialect/Test/TestDialect.cpp | |
| parent | a6d09d4b1ac224ed90ee8ff6c964a2bff39421c7 (diff) | |
[MLIR] Add native Bytecode support for properties
This is adding a new interface (`BytecodeOpInterface`) to allow operations to
opt-in skipping conversion to attribute and serializing properties to native
bytecode.
The scheme relies on a new section where properties are stored in sequence
{ size, serialize_properties }, ...
The operations are storing the index of a properties, a table of offset is
built when loading the properties section the first time.
Back-deployment to version prior to 4 are relying on getAttrDictionnary() which
we intend to deprecate and remove: that is putting a de-factor end-of-support
horizon for supporting deployments to version older than 4.
Differential Revision: https://reviews.llvm.org/D151065
Diffstat (limited to 'mlir/test/lib/Dialect/Test/TestDialect.cpp')
| -rw-r--r-- | mlir/test/lib/Dialect/Test/TestDialect.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index 715c77b9a396..d167d0274aad 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -28,12 +28,14 @@ #include "mlir/IR/Verifier.h" #include "mlir/Interfaces/InferIntRangeInterface.h" #include "mlir/Reducer/ReductionPatternInterface.h" +#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/FoldUtils.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" +#include <cstdint> #include <numeric> #include <optional> @@ -62,6 +64,44 @@ llvm::hash_code MyPropStruct::hash() const { return hash_value(StringRef(content)); } +static LogicalResult readFromMlirBytecode(DialectBytecodeReader &reader, + MyPropStruct &prop) { + StringRef str; + if (failed(reader.readString(str))) + return failure(); + prop.content = str.str(); + return success(); +} + +static void writeToMlirBytecode(::mlir::DialectBytecodeWriter &writer, + MyPropStruct &prop) { + writer.writeOwnedString(prop.content); +} + +static LogicalResult readFromMlirBytecode(DialectBytecodeReader &reader, + MutableArrayRef<int64_t> prop) { + uint64_t size; + if (failed(reader.readVarInt(size))) + return failure(); + if (size != prop.size()) + return reader.emitError("array size mismach when reading properties: ") + << size << " vs expected " << prop.size(); + for (auto &elt : prop) { + uint64_t value; + if (failed(reader.readVarInt(value))) + return failure(); + elt = value; + } + return success(); +} + +static void writeToMlirBytecode(::mlir::DialectBytecodeWriter &writer, + ArrayRef<int64_t> prop) { + writer.writeVarInt(prop.size()); + for (auto elt : prop) + writer.writeVarInt(elt); +} + static LogicalResult setPropertiesFromAttribute(PropertiesWithCustomPrint &prop, Attribute attr, InFlightDiagnostic *diagnostic); |
