mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
detect some optimization of GOTO jumps
This commit is contained in:
parent
c29d19178a
commit
40375316e2
@ -186,6 +186,14 @@ class BranchManger {
|
||||
convertToLoop( parsedBlock, conditionStart, conditionEnd );
|
||||
allParsedOperations.remove( n );
|
||||
((IfParsedBlock)nextBlock).negateCompare();
|
||||
|
||||
// if conditions that point at the end of the loop for optimization must now point at start.
|
||||
for( n = b - 1; n >= 0; n-- ) {
|
||||
ParsedBlock prevBlock = allParsedOperations.get( n );
|
||||
if( prevBlock.op == JavaBlockOperator.IF && prevBlock.endPosition == conditionStart ) {
|
||||
prevBlock.endPosition = parsedBlock.startPosition;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if( nextBlock.op == JavaBlockOperator.GOTO && nextBlock.endPosition == nextPos && n > 1 ) { // Eclipse loop with wide goto_w
|
||||
|
@ -70,6 +70,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
addParam( list, script, "ifAndOr4" );
|
||||
addParam( list, script, "ifAndOr6" );
|
||||
addParam( list, script, "ifAndOr8" );
|
||||
addParam( list, script, "ifWithoutElseAndLoop" );
|
||||
}
|
||||
rule.setTestParameters( list );
|
||||
return list;
|
||||
@ -449,5 +450,20 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int ifWithoutElseAndLoop;
|
||||
|
||||
@Export
|
||||
static int ifWithoutElseAndLoop() {
|
||||
int n = 1;
|
||||
// because some compiler (Eclipse) move the loop condition to the end of the loop. Then there can be an optimization that the if jump to the end of the loop.
|
||||
if( ifWithoutElseAndLoop != 1 ) {
|
||||
ifWithoutElseAndLoop = 1;
|
||||
}
|
||||
while( n < 10 ) {
|
||||
ifWithoutElseAndLoop *= n++;
|
||||
}
|
||||
return ifWithoutElseAndLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user