Skip to content

Commit 3b0106f

Browse files
committed
Fix MLIR bytecode reader for unregistered dialects
At the moment we accept (in tests) unregistered dialects and in particular: "new_processor_id_and_range"() where there is no `.` separator. We probably will remove support for this from the parser, but for now we're adding compatibility support in the reader. Differential Revision: https://reviews.llvm.org/D151386
1 parent c0261eb commit 3b0106f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mlir/Bytecode/Encoding.h"
1515
#include "mlir/IR/BuiltinDialect.h"
1616
#include "mlir/IR/BuiltinOps.h"
17+
#include "mlir/IR/Diagnostics.h"
1718
#include "mlir/IR/OpImplementation.h"
1819
#include "mlir/IR/Verifier.h"
1920
#include "mlir/IR/Visitors.h"
@@ -1609,8 +1610,20 @@ BytecodeReader::Impl::parseOpName(EncodingReader &reader) {
16091610
reader);
16101611
if (failed(opName->dialect->load(dialectReader, getContext())))
16111612
return failure();
1612-
opName->opName.emplace((opName->dialect->name + "." + opName->name).str(),
1613-
getContext());
1613+
// If the opName is empty, this is because we use to accept names such as
1614+
// `foo` without any `.` separator. We shouldn't tolerate this in textual
1615+
// format anymore but for now we'll be backward compatible. This can only
1616+
// happen with unregistered dialects.
1617+
if (opName->name.empty()) {
1618+
if (opName->dialect->getLoadedDialect())
1619+
return emitError(fileLoc) << "has an empty opname for dialect '"
1620+
<< opName->dialect->name << "'\n";
1621+
1622+
opName->opName.emplace(opName->dialect->name, getContext());
1623+
} else {
1624+
opName->opName.emplace((opName->dialect->name + "." + opName->name).str(),
1625+
getContext());
1626+
}
16141627
}
16151628
return *opName->opName;
16161629
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: mlir-opt -emit-bytecode -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect | FileCheck %s
2+
3+
// verify that we round-trip an op without a dialect name (as long as we support this)
4+
func.func @map1d(%lb: index, %ub: index, %step: index) {
5+
// CHECK: "new_processor_id_and_range"
6+
%0:2 = "new_processor_id_and_range"() : () -> (index, index)
7+
return
8+
}

0 commit comments

Comments
 (0)