This is an archive of the discontinued LLVM Phabricator instance.

[mlir-opt] Delay pass manager creation until after parsing
ClosedPublic

Authored by rkayaith on Sep 10 2022, 11:13 AM.

Details

Summary

Currently the pass manager is created before parsing, which requires an
assumption that the top-level operation will be builtin.module.
Delaying the creation allows for using the parsed top-level operation as
the PassManager operation instead.

A followup change will allow for parsing top-level operations other than
builtin.module.

Diff Detail

Event Timeline

rkayaith created this revision.Sep 10 2022, 11:13 AM
rkayaith published this revision for review.Sep 19 2022, 10:28 PM
mehdi_amini added inline comments.Sep 20 2022, 2:32 PM
mlir/include/mlir/Pass/PassRegistry.h
290

This function is quite tricky in terms of invariant, and in particular the lifetime expectation for enableVerifier and enableThreading. Not the FIXME above, adding enableVerifier isn't going in the right direction here.

rkayaith added inline comments.Sep 20 2022, 7:42 PM
mlir/include/mlir/Pass/PassRegistry.h
290

Agreed it's tricky, though to me it seems like modifying the pass pipeline or context during parsing makes it even harder to follow. The change here moves more towards "do the minimum in the resource handler, and the main work afterwards". If it helps I could hide the individual options with something like:

ReproducerOptions reproOpts;
attachPassReproducerAsmResource(config, &reproOpts);
... parse ...
PassManager pm(...);
reproOpts.applyOptions(pm, context);

Another option would be to include the top-level op in the reproducer pipeline string (I was planning on this anyways) and construct the full pass manager in the resource handler, so something like:

Optional<PassManager> reproPM;
attachPassReproducerAsmResource(config, reproPM, enableThreading);
... parse ...
PassManager pm(...);
if (reproPM)
  pm = std::move(*reproPM)

though this makes it harder to support some edge case, e.g. verify_each is ordered before pipeline, or verify_each is present in the resource but pipeline isn't

rkayaith updated this revision to Diff 461980.Sep 21 2022, 12:14 PM

create a ReproducerOptions class to hold parsed repro config

The options class approach looks nice to me.

mlir/include/mlir/Pass/PassRegistry.h
290

I'd name this PassReproducerOptions.

291–293

Can you move the private section to the bottom of the class?

296–299

Does this need to be a friend? Why not just a non-static method that attaches a parser for the current options config?

mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
86–88
rkayaith added inline comments.Sep 21 2022, 12:22 PM
mlir/include/mlir/Pass/PassRegistry.h
290

I updated the diff to use the first approach, let me know if it seems reasonable. I removed the FIXME's even though I didn't follow their direction; not sure if I should still leave them.

rkayaith updated this revision to Diff 461986.Sep 21 2022, 12:38 PM
rkayaith marked 4 inline comments as done.

address review comments

@rriddle @mehdi_amini any other comments here?

rriddle accepted this revision.Sep 27 2022, 1:07 PM
This revision is now accepted and ready to land.Sep 27 2022, 1:07 PM