[Mlir-commits] [mlir] [mlirbc] Serialize dense elements attr i1 using packed (PR #182233)
Matthias Springer
llvmlistbot at llvm.org
Thu Feb 19 00:17:43 PST 2026
================
@@ -412,6 +414,59 @@ struct TestBytecodeRoundtripPass
doRoundtripWithConfigs(op, writeConfig, parseConfig);
}
+ // Test7: When writing bytecode, we override the encoding of TestI32Type with
+ // the encoding of builtin IntegerType, but we also write an unowned blob.
+ // We can natively parse this without the use of a callback, relying on the
+ // existing builtin reader mechanism.
+ void runTest7(Operation *op) {
+ auto *builtin = op->getContext()->getLoadedDialect<mlir::BuiltinDialect>();
+ BytecodeDialectInterface *iface =
+ builtin->getRegisteredInterface<BytecodeDialectInterface>();
+ BytecodeWriterConfig writeConfig;
+ writeConfig.attachTypeCallback(
+ [&](Type entryValue, std::optional<StringRef> &dialectGroupName,
+ DialectBytecodeWriter &writer) -> LogicalResult {
+ // Emit TestIntegerType using the builtin dialect encoding.
+ if (llvm::isa<test::TestI32Type>(entryValue)) {
+ auto builtinI32Type =
+ IntegerType::get(op->getContext(), 32,
+ IntegerType::SignednessSemantics::Signless);
+ // Specify that this type will need to be written as part of the
+ // builtin group. This will override the default dialect group of
+ // the attribute (test).
+ dialectGroupName = StringLiteral("builtin");
+ if (succeeded(iface->writeType(builtinI32Type, writer))) {
+ char dummyBlob[] = "test_blob";
+ llvm::outs() << "Writing unowned blob...\n";
+ writer.writeUnownedBlob(ArrayRef<char>(dummyBlob, 9));
+ return success();
+ }
+ }
+ return failure();
+ });
+ ParserConfig parseConfig(op->getContext(), /*verifyAfterParse=*/true);
+ parseConfig.getBytecodeReaderConfig().attachTypeCallback(
+ [&](DialectBytecodeReader &reader, StringRef dialectName,
----------------
matthias-springer wrote:
This lambda never returns "failure". Is that on purpose?
https://github.com/llvm/llvm-project/pull/182233
More information about the Mlir-commits
mailing list