Files
clang-p2996/mlir/test/Bytecode/bytecode_callback_with_custom_attribute.mlir
Matteo Franciolini bff6a4292f Expose callbacks for encoding of types/attributes
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode.

Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect.

Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D153383
2023-07-28 16:45:42 -07:00

15 lines
693 B
MLIR

// RUN: mlir-opt %s -split-input-file --test-bytecode-callback="callback-test=3" | FileCheck %s --check-prefix=TEST_3
// RUN: mlir-opt %s -split-input-file --test-bytecode-callback="callback-test=4" | FileCheck %s --check-prefix=TEST_4
"test.versionedC"() <{attribute = #test.attr_params<42, 24>}> : () -> ()
// TEST_3: Overriding TestAttrParamsAttr encoding...
// TEST_3: "test.versionedC"() <{attribute = dense<[42, 24]> : tensor<2xi32>}> : () -> ()
// -----
"test.versionedC"() <{attribute = dense<[42, 24]> : tensor<2xi32>}> : () -> ()
// TEST_4: Overriding parsing of TestAttrParamsAttr encoding...
// TEST_4: "test.versionedC"() <{attribute = #test.attr_params<42, 24>}> : () -> ()