sway
sway copied to clipboard
Create an IR optimisation pass manager.
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.
I put something into the opt binary (sway-ir/src/bin/opt.rs) which resembles something we might at least start with.
More TODOs:
- Allow specifying individual passes on the command line. So if no opt level is specified, but
-dceis specified, then only DCE must be run. - 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
- 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.
Design discussion: https://github.com/FuelLabs/sway/discussions/3596 (since GH hasn't added an auto-link).