sway icon indicating copy to clipboard operation
sway copied to clipboard

Create an IR optimisation pass manager.

Open otrho opened this issue 3 years ago • 1 comments

As we add new optimisation passes we need a structured way to call them.

Some potential features:

  • Levels of optimisation mimicking -O0, -Os, -O3, etc.
  • Pass categories and metadata:
    • Passes which match a category (e.g., constants) could be requested as a group.
    • Passes which 'request' to be run after a certain operation type. E.g., DCE should always be run after instruction combining since new opportunities may have appeared. Simplify CFG after inlining. This would require a fair bit of design though.
  • Heuristics for deciding what to run:
    • Optimisations could be re-run until their returns have diminished below a certain point, or compile time performance limits are met.

But initially we just need a nice way to say 'optimise this IR at this level' from Sway core.

otrho avatar Jul 28 '22 05:07 otrho

I put something into the opt binary (sway-ir/src/bin/opt.rs) which resembles something we might at least start with.

otrho avatar Aug 03 '22 07:08 otrho

More TODOs:

  1. Allow specifying individual passes on the command line. So if no opt level is specified, but -dce is specified, then only DCE must be run.
  2. Printing the IR must also be treated as a "pass" from a command line perspective, allowing us to print the IR at any point in the pipeline.

Passes which 'request' to be run after a certain operation type. E.g., DCE should always be run after instruction combining

  1. We need to have two kinds of dependences here. A hard dependence X->Y (Y hard depends on X) means that Y cannot run without X having run. Hard dependences must be allowed only when X (in the example here) is an analysis and not an optimization. Soft dependences (which need not be enforced, for correctness) can be b/w optimizations. As far as I know LLVM doesn't have this "soft dependence". They just schedule the passes as needed. But I think it's a nice thing to have if we design it all well.

vaivaswatha avatar Dec 12 '22 05:12 vaivaswatha

Design discussion: https://github.com/FuelLabs/sway/discussions/3596 (since GH hasn't added an auto-link).

vaivaswatha avatar Dec 14 '22 08:12 vaivaswatha