OpenDream icon indicating copy to clipboard operation
OpenDream copied to clipboard

Refactor the PeepholeOptimizer into arbitrary passes

Open ike709 opened this issue 1 year ago • 0 comments

Changed the peephole optimizer to support arbitrary passes over the bytecode with different optimizations instead of trying (and failing) to do everything in one go, as opts like PushNFloats would break the GetOpcodes() checks of other optimizations.

IPeepholeOptimization has been renamed to IOptimization. Individual optimizer passes are the inheritor interfaces of this parent interface.

Here are the passes in order:

  1. IPeepholeOptimization - Runs pretty much everything not involving PushN opcodes
  2. IBytecodeCompactor - Converts multiple Push opcodes to PushN opcodes
  3. IListCompactor - Converts PushN... CreateList to CreateListN... opcodes

I ran my usual bytecode analysis scripts on TG and confirmed that we're now running const folding optimizations (in the first pass) 100% of the time. I also confirmed that second-pass and third-pass optimizations are also being applied.

I booted TG and confirmed it doesn't explode. I also ran the profiler and confirmed that the performance impact is negligible: image

Closes #2059

ike709 avatar Oct 28 '24 19:10 ike709