This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add fallback support for parsing/printing unknown external resources
ClosedPublic

Authored by rriddle on Sep 7 2022, 3:51 PM.

Details

Summary

This is necessary/useful for building generic tooling that can roundtrip external
resources without needing to explicitly handle them. For example, this allows
for viewing the resources encoded within a bytecode file without having to
explicitly know how to process them (e.g. making it easier to interact with a
reproducer encoded in bytecode).

Diff Detail

Event Timeline

rriddle created this revision.Sep 7 2022, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2022, 3:51 PM
rriddle requested review of this revision.Sep 7 2022, 3:51 PM
rriddle updated this revision to Diff 458591.Sep 7 2022, 3:58 PM
rriddle edited the summary of this revision. (Show Details)
jpienaar accepted this revision.Sep 12 2022, 8:42 PM

Nice, thanks

mlir/lib/IR/AsmPrinter.cpp
1311

We could now use c++17 if initializer form:

if (FailureOr<AsmResourceBlob> blob = entry.parseAsBlob(); succeeded(blob)) 
  resources.emplace_back(entry.getKey(), std::move(*blob));
else return failure();
break;

(unsure if more readable yet, so just an aside)

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
1303

And I think per discussion this may be WAI.

mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
69–71

I'd expand on passthroughs here to make behavior clearer.

This revision is now accepted and ready to land.Sep 12 2022, 8:42 PM
rriddle marked 2 inline comments as done.Sep 13 2022, 1:06 AM
rriddle added inline comments.
mlir/lib/IR/AsmPrinter.cpp
1311

I'm not sure it adds much here (it's the same amount of lines), but thanks for the reminder. I think this will come in handy a lot moving forward.

bondhugula added inline comments.
mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
1327–1329

Just update the ctor to optionally take this resource map and avoid the attach call here and in MlirOptMain.cpp?

This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.