mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-02 08:08:20 +00:00
Perform redundant jump elimination in lastpass
This is a first try at redundant jump removal (jumps that target the very next instruction). It's too basic in several ways. - The statement is replaced by a ';' instead of removed. - If the jump was the only statement in an if, when the if becomes empty, it's not folded. - Jumps that are last in the 'then' branch of if+else are not visible. This would need either to track multiple last statements, or to have some means to anticipate what the next statement is at every statement. A Control Flow Graph would help a lot. - When a label is immediately followed by a jump, all jumps to that label should target the destination of that jump if it's in scope. Added to TODO. - It misses some optimizations when not expanding WHILE and FOR into IF/JUMP. Moving everything to an earlier stage would help with some of these, especially with ';' and 'if' folding. Unconditionally expanding WHILE and FOR would also help.
This commit is contained in:
parent
574f92d08e
commit
5bfb218505
4 changed files with 83 additions and 6 deletions
|
@ -22,7 +22,7 @@ default
|
|||
}
|
||||
}
|
||||
{
|
||||
jump ___lbl__00001;
|
||||
;
|
||||
}
|
||||
@___lbl__00001;
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ default
|
|||
{
|
||||
{
|
||||
___ret__00002 = llGetLinkNumber();
|
||||
jump ___rtl__00006;
|
||||
;
|
||||
}
|
||||
}
|
||||
@___rtl__00006;
|
||||
|
@ -43,7 +43,7 @@ default
|
|||
while (___ret__00002);
|
||||
{
|
||||
___ret__00001 = <((float)0), ((float)0), ((float)0)>;
|
||||
jump ___rtl__00004;
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
unit_tests/coverage.suite/jump-opt.lsl
Normal file
13
unit_tests/coverage.suite/jump-opt.lsl
Normal file
|
@ -0,0 +1,13 @@
|
|||
default{state_entry(){
|
||||
|
||||
if (llGetLinkNumber()) jump x1;
|
||||
if (llGetLinkNumber()) jump x1; else jump x3;
|
||||
|
||||
llOwnerSay("ok");
|
||||
@x1;
|
||||
jump x2;
|
||||
@x3;
|
||||
llOwnerSay("blergh");
|
||||
@x2;
|
||||
|
||||
}}
|
1
unit_tests/coverage.suite/jump-opt.skp
Normal file
1
unit_tests/coverage.suite/jump-opt.skp
Normal file
|
@ -0,0 +1 @@
|
|||
This optimization is not implemented.
|
Loading…
Add table
Add a link
Reference in a new issue