This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add callback to provide a pass pipeline to MlirOptMain
ClosedPublic

Authored by panickal-xmos on Nov 3 2021, 2:28 PM.

Details

Summary

The callback can be used to provide a default pass pipeline.

Diff Detail

Event Timeline

panickal-xmos created this revision.Nov 3 2021, 2:28 PM
panickal-xmos retitled this revision from Add callback to apply a pass pipeline to [mlir] Add callback to provide a pass pipeline to MlirOptMain.

Add tag to commit message

panickal-xmos published this revision for review.Nov 3 2021, 3:13 PM
mehdi_amini added inline comments.Nov 3 2021, 4:39 PM
mlir/include/mlir/Support/MlirOptMain.h
39
54–56
57

I suspect we can keep a forwarding API from the old one to the new one, it can just be implemented as:

LogicalResult MlirOptMain(llvm::raw_ostream &outputStream,
                          std::unique_ptr<llvm::MemoryBuffer> buffer,
                          const PassPipelineCLParser &passPipeline,
                          DialectRegistry &registry, bool splitInputFile,
                          bool verifyDiagnostics, bool verifyPasses,
                          bool allowUnregisteredDialects,
                          bool preloadDialectsInContext) {
  auto passManagerSetupFn =  [&](PassManager &pm) {
     auto errorHandler = [&](const Twine &msg) {
       emitError(UnknownLoc::get(pm.getContext())) << msg;
       return failure();
    };
    return passPipeline.addToPipeline(pm, errorHandler);
  };
   return MlirOptMain(outputStream, buffer, passManagerSetupFn,
                          registry, splitInputfile, verifyDiagnostics, verifyPasses,
                          allowUnregisteredDialects, preloadDialectsInContext);
}
mlir/lib/Support/MlirOptMain.cpp
274

I wouldn't pass the errorHandler in the callback, that's hard to justify document: it seems like leaking the passPipeline.addToPipeline API to me.

Instead you should be able to write it above here and capture it:

 [&](PassManager &pm) {
  auto errorHandler = [&](const Twine &msg) {
    emitError(UnknownLoc::get(pm.getContext())) << msg;
    return failure();
  };
  return passPipeline.addToPipeline(pm, errorHandler);
},
``

But I would add this in the header (see the other comment)
panickal-xmos marked 2 inline comments as done.Nov 4 2021, 2:17 AM
panickal-xmos added inline comments.Nov 4 2021, 2:34 AM
mlir/include/mlir/Support/MlirOptMain.h
57

Forwarding it is a good idea. Should we do it in the header?

mehdi_amini added inline comments.Nov 4 2021, 9:33 AM
mlir/include/mlir/Support/MlirOptMain.h
57

If it does not need to include more header, then sure, but I'm not sure it'd work right now.

Forward the current API to the new one

panickal-xmos marked 3 inline comments as done.Nov 4 2021, 10:43 AM
rriddle accepted this revision.Nov 4 2021, 5:02 PM

LGTM (but wait for Mehdi to check again)

mlir/include/mlir/Support/MlirOptMain.h
32

Please document this.

61
This revision is now accepted and ready to land.Nov 4 2021, 5:02 PM
mehdi_amini accepted this revision.Nov 4 2021, 5:11 PM

LG,
I was about to push this (building and running the tests), but I saw River's comment so I'll do as soon as they are addressed

Update comments

panickal-xmos marked 2 inline comments as done.Nov 5 2021, 2:32 AM