@@ -1415,8 +1415,8 @@ class mlir::BytecodeReader::Impl {
14151415 // / Parse an operation name reference using the given reader, and set the
14161416 // / `wasRegistered` flag that indicates if the bytecode was produced by a
14171417 // / context where opName was registered.
1418- FailureOr<OperationName> parseOpName (EncodingReader &reader,
1419- std::optional<bool > &wasRegistered);
1418+ FailureOr<BytecodeOperationName *>
1419+ parseOpName (EncodingReader &reader, std::optional<bool > &wasRegistered);
14201420
14211421 // ===--------------------------------------------------------------------===//
14221422 // Attribute/Type Section
@@ -1848,7 +1848,7 @@ BytecodeReader::Impl::parseDialectSection(ArrayRef<uint8_t> sectionData) {
18481848 return success ();
18491849}
18501850
1851- FailureOr<OperationName >
1851+ FailureOr<BytecodeOperationName * >
18521852BytecodeReader::Impl::parseOpName (EncodingReader &reader,
18531853 std::optional<bool > &wasRegistered) {
18541854 BytecodeOperationName *opName = nullptr ;
@@ -1868,21 +1868,28 @@ BytecodeReader::Impl::parseOpName(EncodingReader &reader,
18681868 // Load the dialect and its version.
18691869 DialectReader dialectReader (attrTypeReader, stringReader, resourceReader,
18701870 dialectsMap, reader, version);
1871- if (succeeded (opName->dialect ->load (dialectReader, getContext ()))) {
1872- opName->opName .emplace (
1873- (opName->dialect ->name + " ." + opName->name ).str (), getContext ());
1874- } else if (auto fallbackOp =
1875- opName->dialect ->interface ->getFallbackOperationName ();
1876- succeeded (fallbackOp)) {
1877- // If the dialect's bytecode interface specifies a fallback op, we want
1878- // to use that instead of an unregistered op.
1879- opName->opName .emplace (*fallbackOp);
1880- } else {
1871+ if (failed (opName->dialect ->load (dialectReader, getContext ())))
18811872 return failure ();
1873+
1874+ opName->opName .emplace ((opName->dialect ->name + " ." + opName->name ).str (),
1875+ getContext ());
1876+
1877+ // If the op is unregistered now, but was not marked as unregistered, try
1878+ // to parse it as a fallback op if the dialect's bytecode interface
1879+ // specifies one.
1880+ // We don't treat this condition as an error because we may still be able
1881+ // to parse the op as an unregistered op if it doesn't use custom
1882+ // properties encoding.
1883+ if (wasRegistered && !opName->opName ->isRegistered ()) {
1884+ if (auto fallbackOp =
1885+ opName->dialect ->interface ->getFallbackOperationName ();
1886+ succeeded (fallbackOp)) {
1887+ opName->opName .emplace (*fallbackOp);
1888+ }
18821889 }
18831890 }
18841891 }
1885- return *opName-> opName ;
1892+ return opName;
18861893}
18871894
18881895// ===----------------------------------------------------------------------===//
@@ -2227,8 +2234,12 @@ BytecodeReader::Impl::parseOpWithoutRegions(EncodingReader &reader,
22272234 bool &isIsolatedFromAbove) {
22282235 // Parse the name of the operation.
22292236 std::optional<bool > wasRegistered;
2230- FailureOr<OperationName> opName = parseOpName (reader, wasRegistered);
2231- if (failed (opName))
2237+ FailureOr<BytecodeOperationName *> bytecodeOp =
2238+ parseOpName (reader, wasRegistered);
2239+ if (failed (bytecodeOp))
2240+ return failure ();
2241+ auto opName = (*bytecodeOp)->opName ;
2242+ if (!opName)
22322243 return failure ();
22332244
22342245 // Parse the operation mask, which indicates which components of the operation
@@ -2245,6 +2256,9 @@ BytecodeReader::Impl::parseOpWithoutRegions(EncodingReader &reader,
22452256 // With the location and name resolved, we can start building the operation
22462257 // state.
22472258 OperationState opState (opLoc, *opName);
2259+ // If this is a fallback op, provide the original name of the operation.
2260+ if (auto *iface = opName->getInterface <FallbackBytecodeOpInterface>())
2261+ iface->setOriginalOperationName ((*bytecodeOp)->name , opState);
22482262
22492263 // Parse the attributes of the operation.
22502264 if (opMask & bytecode::OpEncodingMask::kHasAttrs ) {
0 commit comments