Search in sources :

Example 1 with VarInstruction

use of dyvilx.tools.compiler.ast.bytecode.VarInstruction in project Dyvil by Dyvil.

the class InlineIntrinsicData method preProcess.

private void preProcess() {
    final ParameterList parameterList = this.method.getParameters();
    int parameterSlots = 0;
    for (int i = 0, parameterCount = parameterList.size(); i < parameterCount; i++) {
        parameterSlots += parameterList.get(i).getCovariantType().getLocalSlots();
    }
    this.parameterSlots = parameterSlots;
    final int[] accessCounts = new int[this.maxLocals];
    int lastStoredIndex = -1;
    for (int i = 0; i < this.instructionCount; i++) {
        final IInstruction instruction = this.instructions[i];
        final int opcode = instruction.getOpcode();
        if (Opcodes.isLoadOpcode(opcode)) {
            final int varIndex = ((VarInstruction) instruction).getIndex();
            if (accessCounts[varIndex]++ == 0) {
                // Local Variable loaded for the first time -> might not need to store it
                continue;
            }
            // Local Variable loaded at least two times -> need to store it and all parameters before
            if (varIndex > lastStoredIndex && varIndex < parameterSlots) {
                lastStoredIndex = varIndex;
            }
        } else if (Opcodes.isReturnOpcode(opcode)) {
            this.returnIndex = i;
        }
    }
    this.storedParameters = lastStoredIndex + 1;
}
Also used : VarInstruction(dyvilx.tools.compiler.ast.bytecode.VarInstruction) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IInstruction(dyvilx.tools.compiler.ast.bytecode.IInstruction)

Aggregations

IInstruction (dyvilx.tools.compiler.ast.bytecode.IInstruction)1 VarInstruction (dyvilx.tools.compiler.ast.bytecode.VarInstruction)1 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)1