mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Reuse the temp variable of a DUP operation for further DUP operations
This commit is contained in:
parent
7a9750afdd
commit
f95b21a1f8
@ -19,7 +19,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
@ -258,7 +257,7 @@ public abstract class WasmCodeBuilder {
|
||||
*/
|
||||
protected void addLoadStoreInstruction( AnyType valueType, boolean load, @Nonnegative int javaIdx, int javaCodePos, int lineNumber ) {
|
||||
localVariables.use( valueType, javaIdx, javaCodePos );
|
||||
instructions.add( new WasmLoadStoreInstruction( load, javaIdx, localVariables, javaCodePos, lineNumber ) );
|
||||
instructions.add( new WasmLoadStoreInstruction( load ? VariableOperator.get : VariableOperator.set, javaIdx, localVariables, javaCodePos, lineNumber ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,7 +304,8 @@ public abstract class WasmCodeBuilder {
|
||||
//alternate we need to create a new locale variable
|
||||
if( varIndex < 0 ) {
|
||||
varIndex = getTempVariable( type, javaCodePos, javaCodePos + 1 );
|
||||
instructions.add( new WasmDupInstruction( varIndex, type, localVariables, javaCodePos, lineNumber ) );
|
||||
instructions.add( new WasmLoadStoreInstruction( VariableOperator.tee, varIndex, localVariables, javaCodePos, lineNumber ) );
|
||||
instructions.add( new WasmLoadStoreInstruction( VariableOperator.get, varIndex, localVariables, javaCodePos, lineNumber ) );
|
||||
// an alternative solution can be a function call with multiple return values but this seems to be slower
|
||||
// new SyntheticFunctionName( "dup" + storeType, "local.get 0 local.get 0 return", storeType, null, storeType, storeType ), codePos, lineNumber )
|
||||
} else {
|
||||
@ -473,9 +473,9 @@ public abstract class WasmCodeBuilder {
|
||||
if( struct.getOperator() == StructOperator.NEW_DEFAULT ) {
|
||||
instructions.set( i, new WasmNopInstruction( struct.getCodePosition(), struct.getLineNumber() ) ); // replace NEW_DEFAULT with Nop, Nop because the code position can be needed for the branch manager
|
||||
instr = instructions.get( ++i );
|
||||
if( instr.getType() == Type.Dup ) {
|
||||
instructions.remove( i ); // dup of the instance reference if it is later assign, missing if the object after the constructor is never assign
|
||||
}
|
||||
// if( instr.getType() == Type.Dup ) {
|
||||
// instructions.remove( i ); // dup of the instance reference if it is later assign, missing if the object after the constructor is never assign
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ abstract class WasmInstruction {
|
||||
* Type of instruction to faster differ as with instanceof.
|
||||
*/
|
||||
static enum Type {
|
||||
Const, Convert, Local, Global, Table, Memory, Block, Numeric, Nop, Jump, Call, CallVirtual, CallInterface, Array, Struct, Dup, DupThis;
|
||||
Const, Convert, Local, Global, Table, Memory, Block, Numeric, Nop, Jump, Call, CallVirtual, CallInterface, Array, Struct, DupThis;
|
||||
}
|
||||
|
||||
private int javaCodePos;
|
||||
|
@ -21,7 +21,7 @@ import static de.inetsoftware.jwebassembly.wasm.VariableOperator.set;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.VariableOperator;
|
||||
|
||||
/**
|
||||
* WasmInstruction for load and store local variables.
|
||||
@ -34,8 +34,8 @@ class WasmLoadStoreInstruction extends WasmLocalInstruction {
|
||||
/**
|
||||
* Create an instance of a load/store instruction
|
||||
*
|
||||
* @param load
|
||||
* true: if load
|
||||
* @param op
|
||||
* the operation
|
||||
* @param idx
|
||||
* the memory/slot idx of the variable
|
||||
* @param localVariables
|
||||
@ -45,8 +45,8 @@ class WasmLoadStoreInstruction extends WasmLocalInstruction {
|
||||
* @param lineNumber
|
||||
* the line number in the Java source code
|
||||
*/
|
||||
WasmLoadStoreInstruction( boolean load, @Nonnegative int idx, LocaleVariableManager localVariables, int javaCodePos, int lineNumber ) {
|
||||
super( load ? get : set, idx, localVariables, javaCodePos, lineNumber );
|
||||
WasmLoadStoreInstruction( VariableOperator op, @Nonnegative int idx, LocaleVariableManager localVariables, int javaCodePos, int lineNumber ) {
|
||||
super( op, idx, localVariables, javaCodePos, lineNumber );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +112,7 @@ class WasmLocalInstruction extends WasmInstruction {
|
||||
*/
|
||||
@Override
|
||||
AnyType getPushValueType() {
|
||||
return op == get ? localVariables.getValueType( getIndex() ) : null;
|
||||
return op != set ? localVariables.getValueType( getIndex() ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user