Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Compiler Optimizations #1630

Closed
wants to merge 46 commits into from

Conversation

F-OS
Copy link

@F-OS F-OS commented Jan 22, 2024

This PR adds a couple of basic optimizations for the compiler, alongside a framework for manipulating bytecode before writing, and a bytecode dumper tool:

  1. Label forwarding: Labels followed by labels are compressed into one label, and jumps are edited.
  2. Dead code elimination: This is very naive right now. Jumps followed by jumps are replaced with a single jump.
  3. Peephole optimizations: BooleanNot followed by JumpIfFalse is converted into JumpIfTrue, and similar.
  4. Compacted opcodes: Several opcode sequences common to the code such as PushNull->AssignPop have been joined into single opcodes, e.g. AssignNull. These new opcodes mean fewer fetches and less need for validating state.

This is all very WIP and my code is pretty hacked-together. Haven't done that much coding in C#. I'm hoping to add a CFG generation phase (had to trash the last one because it was something like O(n^3) complexity lmao) and SSA for constant propagation.

Performance stats: -- Cut out, apparently there is minimal difference on the release build. The use of this PR is mainly the framework --

Did not realize renaming branches on git deleted the old branch, sorry @wixoaGit @ike709 @moonheart08

Reagan Fischer and others added 30 commits January 14, 2024 20:58
# Conflicts:
#	DMCompiler/Program.cs
# Conflicts:
#	DMCompiler/Optimizer/CFG/CFGStack.cs
# Conflicts:
#	DMCompiler/DM/DMProc.cs
# Conflicts:
#	DMCompiler/DM/DMProc.cs
… references and and cleans up unneeded spacing changes
… references and and cleans up unneeded spacing changes
… references and and cleans up unneeded spacing changes

Probably don't need this. Removes some unnecessary code for resolving references and and cleans up unneeded spacing changes
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@F-OS
Copy link
Author

F-OS commented Jan 30, 2024

LINQ Removal soon tm

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

…imizations

# Conflicts:
#	DMCompiler/Bytecode/DreamProcOpcode.cs
#	DMCompiler/DM/DMProc.cs
#	DMCompiler/DM/Expressions/Builtins.cs
@boring-cyborg boring-cyborg bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels Feb 22, 2024
@F-OS
Copy link
Author

F-OS commented Feb 25, 2024

Going to redo this entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants