diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -14,6 +14,7 @@ #include "mlir/Bytecode/Encoding.h" #include "mlir/IR/BuiltinDialect.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/Diagnostics.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/Verifier.h" #include "mlir/IR/Visitors.h" @@ -1609,8 +1610,20 @@ reader); if (failed(opName->dialect->load(dialectReader, getContext()))) return failure(); - opName->opName.emplace((opName->dialect->name + "." + opName->name).str(), - getContext()); + // If the opName is empty, this is because we use to accept names such as + // `foo` without any `.` separator. We shouldn't tolerate this in textual + // format anymore but for now we'll be backward compatible. This can only + // happen with unregistered dialects. + if (opName->name.empty()) { + if (opName->dialect->getLoadedDialect()) + return emitError(fileLoc) << "has an empty opname for dialect '" + << opName->dialect->name << "'\n"; + + opName->opName.emplace(opName->dialect->name, getContext()); + } else { + opName->opName.emplace((opName->dialect->name + "." + opName->name).str(), + getContext()); + } } return *opName->opName; } diff --git a/mlir/test/Bytecode/unregistered_dialect.mlir b/mlir/test/Bytecode/unregistered_dialect.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Bytecode/unregistered_dialect.mlir @@ -0,0 +1,8 @@ +// RUN: mlir-opt -emit-bytecode -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect | FileCheck %s + +// verify that we round-trip an op without a dialect name (as long as we support this) +func.func @map1d(%lb: index, %ub: index, %step: index) { +// CHECK: "new_processor_id_and_range" + %0:2 = "new_processor_id_and_range"() : () -> (index, index) + return +}