Java Code Examples for com.android.dx.rop.code.RegOps#MOVE

The following examples show how to use com.android.dx.rop.code.RegOps#MOVE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * TODO: Increase the scope of this.
 */
@Override
public boolean hasSideEffect() {
    Rop opcode = getOpcode();

    if (opcode.getBranchingness() != Rop.BRANCH_NONE) {
        return true;
    }

    boolean hasLocalSideEffect
        = Optimizer.getPreserveLocals() && getLocalAssignment() != null;

    switch (opcode.getOpcode()) {
        case RegOps.MOVE_RESULT:
        case RegOps.MOVE:
        case RegOps.CONST:
            return hasLocalSideEffect;
        default:
            return true;
    }
}
 
Example 2
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * TODO: Increase the scope of this.
 */
@Override
public boolean hasSideEffect() {
    Rop opcode = getOpcode();

    if (opcode.getBranchingness() != Rop.BRANCH_NONE) {
        return true;
    }

    boolean hasLocalSideEffect
        = Optimizer.getPreserveLocals() && getLocalAssignment() != null;

    switch (opcode.getOpcode()) {
        case RegOps.MOVE_RESULT:
        case RegOps.MOVE:
        case RegOps.CONST:
            return hasLocalSideEffect;
        default:
            return true;
    }
}
 
Example 3
Source File: NormalSsaInsn.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * TODO: Increase the scope of this.
 */
@Override
public boolean hasSideEffect() {
    Rop opcode = getOpcode();

    if (opcode.getBranchingness() != Rop.BRANCH_NONE) {
        return true;
    }

    boolean hasLocalSideEffect
        = Optimizer.getPreserveLocals() && getLocalAssignment() != null;

    switch (opcode.getOpcode()) {
        case RegOps.MOVE_RESULT:
        case RegOps.MOVE:
        case RegOps.CONST:
            return hasLocalSideEffect;
        default:
            return true;
    }
}
 
Example 4
Source File: NormalSsaInsn.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * TODO: Increase the scope of this.
 */
@Override
public boolean hasSideEffect() {
    Rop opcode = getOpcode();

    if (opcode.getBranchingness() != Rop.BRANCH_NONE) {
        return true;
    }

    boolean hasLocalSideEffect
        = Optimizer.getPreserveLocals() && getLocalAssignment() != null;

    switch (opcode.getOpcode()) {
        case RegOps.MOVE_RESULT:
        case RegOps.MOVE:
        case RegOps.CONST:
            return hasLocalSideEffect;
        default:
            return true;
    }
}
 
Example 5
Source File: SCCP.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Simulates a statement and set the result lattice value.
 * @param insn instruction to simulate
 */
private void simulateStmt(SsaInsn insn) {
    Insn ropInsn = insn.getOriginalRopInsn();
    if (ropInsn.getOpcode().getBranchingness() != Rop.BRANCH_NONE
            || ropInsn.getOpcode().isCallLike()) {
        simulateBranch(insn);
    }

    int opcode = insn.getOpcode().getOpcode();
    RegisterSpec result = insn.getResult();

    if (result == null) {
        // Find move-result-pseudo result for int div and int rem
        if (opcode == RegOps.DIV || opcode == RegOps.REM) {
            SsaBasicBlock succ = insn.getBlock().getPrimarySuccessor();
            result = succ.getInsns().get(0).getResult();
        } else {
            return;
        }
    }

    int resultReg = result.getReg();
    int resultValue = VARYING;
    Constant resultConstant = null;

    switch (opcode) {
        case RegOps.CONST: {
            CstInsn cstInsn = (CstInsn)ropInsn;
            resultValue = CONSTANT;
            resultConstant = cstInsn.getConstant();
            break;
        }
        case RegOps.MOVE: {
            if (insn.getSources().size() == 1) {
                int sourceReg = insn.getSources().get(0).getReg();
                resultValue = latticeValues[sourceReg];
                resultConstant = latticeConstants[sourceReg];
            }
            break;
        }
        case RegOps.ADD:
        case RegOps.SUB:
        case RegOps.MUL:
        case RegOps.DIV:
        case RegOps.AND:
        case RegOps.OR:
        case RegOps.XOR:
        case RegOps.SHL:
        case RegOps.SHR:
        case RegOps.USHR:
        case RegOps.REM: {
            resultConstant = simulateMath(insn, result.getBasicType());
            if (resultConstant != null) {
                resultValue = CONSTANT;
            }
            break;
        }
        case RegOps.MOVE_RESULT_PSEUDO: {
            if (latticeValues[resultReg] == CONSTANT) {
                resultValue = latticeValues[resultReg];
                resultConstant = latticeConstants[resultReg];
            }
            break;
        }
        // TODO: Handle non-int arithmetic.
        // TODO: Eliminate check casts that we can prove the type of.
        default: {}
    }
    if (setLatticeValueTo(resultReg, resultValue, resultConstant)) {
        addUsersToWorklist(resultReg, resultValue);
    }
}
 
Example 6
Source File: EscapeAnalysis.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Identifies extra moves added by scalar replacement and propagates the
 * source of the move to any users of the result.
 */
private void movePropagate() {
    for (int i = 0; i < ssaMeth.getRegCount(); i++) {
        SsaInsn insn = ssaMeth.getDefinitionForRegister(i);

        // Look for move instructions only
        if (insn == null || insn.getOpcode() == null ||
            insn.getOpcode().getOpcode() != RegOps.MOVE) {
            continue;
        }

        final ArrayList<SsaInsn>[] useList = ssaMeth.getUseListCopy();
        final RegisterSpec source = insn.getSources().get(0);
        final RegisterSpec result = insn.getResult();

        // Ignore moves that weren't added due to scalar replacement
        if (source.getReg() < regCount && result.getReg() < regCount) {
            continue;
        }

        // Create a mapping from source to result
        RegisterMapper mapper = new RegisterMapper() {
            @Override
            public int getNewRegisterCount() {
                return ssaMeth.getRegCount();
            }

            @Override
            public RegisterSpec map(RegisterSpec registerSpec) {
                if (registerSpec.getReg() == result.getReg()) {
                    return source;
                }

                return registerSpec;
            }
        };

        // Modify all uses of the move to use the source of the move instead
        for (SsaInsn use : useList[result.getReg()]) {
            use.mapSourceRegisters(mapper);
        }
    }
}
 
Example 7
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if this is a move (but not a move-operand) instruction
 */
@Override
public boolean isNormalMoveInsn() {
    return insn.getOpcode().getOpcode() == RegOps.MOVE;
}
 
Example 8
Source File: SCCP.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Simulates a statement and set the result lattice value.
 * @param insn instruction to simulate
 */
private void simulateStmt(SsaInsn insn) {
    Insn ropInsn = insn.getOriginalRopInsn();
    if (ropInsn.getOpcode().getBranchingness() != Rop.BRANCH_NONE
            || ropInsn.getOpcode().isCallLike()) {
        simulateBranch(insn);
    }

    int opcode = insn.getOpcode().getOpcode();
    RegisterSpec result = insn.getResult();

    if (result == null) {
        // Find move-result-pseudo result for int div and int rem
        if (opcode == RegOps.DIV || opcode == RegOps.REM) {
            SsaBasicBlock succ = insn.getBlock().getPrimarySuccessor();
            result = succ.getInsns().get(0).getResult();
        } else {
            return;
        }
    }

    int resultReg = result.getReg();
    int resultValue = VARYING;
    Constant resultConstant = null;

    switch (opcode) {
        case RegOps.CONST: {
            CstInsn cstInsn = (CstInsn)ropInsn;
            resultValue = CONSTANT;
            resultConstant = cstInsn.getConstant();
            break;
        }
        case RegOps.MOVE: {
            if (insn.getSources().size() == 1) {
                int sourceReg = insn.getSources().get(0).getReg();
                resultValue = latticeValues[sourceReg];
                resultConstant = latticeConstants[sourceReg];
            }
            break;
        }
        case RegOps.ADD:
        case RegOps.SUB:
        case RegOps.MUL:
        case RegOps.DIV:
        case RegOps.AND:
        case RegOps.OR:
        case RegOps.XOR:
        case RegOps.SHL:
        case RegOps.SHR:
        case RegOps.USHR:
        case RegOps.REM: {
            resultConstant = simulateMath(insn, result.getBasicType());
            if (resultConstant != null) {
                resultValue = CONSTANT;
            }
            break;
        }
        case RegOps.MOVE_RESULT_PSEUDO: {
            if (latticeValues[resultReg] == CONSTANT) {
                resultValue = latticeValues[resultReg];
                resultConstant = latticeConstants[resultReg];
            }
            break;
        }
        // TODO: Handle non-int arithmetic.
        // TODO: Eliminate check casts that we can prove the type of.
        default: {}
    }
    if (setLatticeValueTo(resultReg, resultValue, resultConstant)) {
        addUsersToWorklist(resultReg, resultValue);
    }
}
 
Example 9
Source File: EscapeAnalysis.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Identifies extra moves added by scalar replacement and propagates the
 * source of the move to any users of the result.
 */
private void movePropagate() {
    for (int i = 0; i < ssaMeth.getRegCount(); i++) {
        SsaInsn insn = ssaMeth.getDefinitionForRegister(i);

        // Look for move instructions only
        if (insn == null || insn.getOpcode() == null ||
            insn.getOpcode().getOpcode() != RegOps.MOVE) {
            continue;
        }

        final ArrayList<SsaInsn>[] useList = ssaMeth.getUseListCopy();
        final RegisterSpec source = insn.getSources().get(0);
        final RegisterSpec result = insn.getResult();

        // Ignore moves that weren't added due to scalar replacement
        if (source.getReg() < regCount && result.getReg() < regCount) {
            continue;
        }

        // Create a mapping from source to result
        RegisterMapper mapper = new RegisterMapper() {
            @Override
            public int getNewRegisterCount() {
                return ssaMeth.getRegCount();
            }

            @Override
            public RegisterSpec map(RegisterSpec registerSpec) {
                if (registerSpec.getReg() == result.getReg()) {
                    return source;
                }

                return registerSpec;
            }
        };

        // Modify all uses of the move to use the source of the move instead
        for (SsaInsn use : useList[result.getReg()]) {
            use.mapSourceRegisters(mapper);
        }
    }
}
 
Example 10
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if this is a move (but not a move-operand) instruction
 */
@Override
public boolean isNormalMoveInsn() {
    return insn.getOpcode().getOpcode() == RegOps.MOVE;
}
 
Example 11
Source File: SCCP.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Simulates a statement and set the result lattice value.
 * @param insn instruction to simulate
 */
private void simulateStmt(SsaInsn insn) {
    Insn ropInsn = insn.getOriginalRopInsn();
    if (ropInsn.getOpcode().getBranchingness() != Rop.BRANCH_NONE
            || ropInsn.getOpcode().isCallLike()) {
        simulateBranch(insn);
    }

    int opcode = insn.getOpcode().getOpcode();
    RegisterSpec result = insn.getResult();

    if (result == null) {
        // Find move-result-pseudo result for int div and int rem
        if (opcode == RegOps.DIV || opcode == RegOps.REM) {
            SsaBasicBlock succ = insn.getBlock().getPrimarySuccessor();
            result = succ.getInsns().get(0).getResult();
        } else {
            return;
        }
    }

    int resultReg = result.getReg();
    int resultValue = VARYING;
    Constant resultConstant = null;

    switch (opcode) {
        case RegOps.CONST: {
            CstInsn cstInsn = (CstInsn)ropInsn;
            resultValue = CONSTANT;
            resultConstant = cstInsn.getConstant();
            break;
        }
        case RegOps.MOVE: {
            if (insn.getSources().size() == 1) {
                int sourceReg = insn.getSources().get(0).getReg();
                resultValue = latticeValues[sourceReg];
                resultConstant = latticeConstants[sourceReg];
            }
            break;
        }
        case RegOps.ADD:
        case RegOps.SUB:
        case RegOps.MUL:
        case RegOps.DIV:
        case RegOps.AND:
        case RegOps.OR:
        case RegOps.XOR:
        case RegOps.SHL:
        case RegOps.SHR:
        case RegOps.USHR:
        case RegOps.REM: {
            resultConstant = simulateMath(insn, result.getBasicType());
            if (resultConstant != null) {
                resultValue = CONSTANT;
            }
            break;
        }
        case RegOps.MOVE_RESULT_PSEUDO: {
            if (latticeValues[resultReg] == CONSTANT) {
                resultValue = latticeValues[resultReg];
                resultConstant = latticeConstants[resultReg];
            }
            break;
        }
        // TODO: Handle non-int arithmetic.
        // TODO: Eliminate check casts that we can prove the type of.
        default: {}
    }
    if (setLatticeValueTo(resultReg, resultValue, resultConstant)) {
        addUsersToWorklist(resultReg, resultValue);
    }
}
 
Example 12
Source File: EscapeAnalysis.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Identifies extra moves added by scalar replacement and propagates the
 * source of the move to any users of the result.
 */
private void movePropagate() {
    for (int i = 0; i < ssaMeth.getRegCount(); i++) {
        SsaInsn insn = ssaMeth.getDefinitionForRegister(i);

        // Look for move instructions only
        if (insn == null || insn.getOpcode() == null ||
            insn.getOpcode().getOpcode() != RegOps.MOVE) {
            continue;
        }

        final ArrayList<SsaInsn>[] useList = ssaMeth.getUseListCopy();
        final RegisterSpec source = insn.getSources().get(0);
        final RegisterSpec result = insn.getResult();

        // Ignore moves that weren't added due to scalar replacement
        if (source.getReg() < regCount && result.getReg() < regCount) {
            continue;
        }

        // Create a mapping from source to result
        RegisterMapper mapper = new RegisterMapper() {
            @Override
            public int getNewRegisterCount() {
                return ssaMeth.getRegCount();
            }

            @Override
            public RegisterSpec map(RegisterSpec registerSpec) {
                if (registerSpec.getReg() == result.getReg()) {
                    return source;
                }

                return registerSpec;
            }
        };

        // Modify all uses of the move to use the source of the move instead
        for (SsaInsn use : useList[result.getReg()]) {
            use.mapSourceRegisters(mapper);
        }
    }
}
 
Example 13
Source File: NormalSsaInsn.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if this is a move (but not a move-operand) instruction
 */
@Override
public boolean isNormalMoveInsn() {
    return insn.getOpcode().getOpcode() == RegOps.MOVE;
}
 
Example 14
Source File: SCCP.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Simulates a statement and set the result lattice value.
 * @param insn instruction to simulate
 */
private void simulateStmt(SsaInsn insn) {
    Insn ropInsn = insn.getOriginalRopInsn();
    if (ropInsn.getOpcode().getBranchingness() != Rop.BRANCH_NONE
            || ropInsn.getOpcode().isCallLike()) {
        simulateBranch(insn);
    }

    int opcode = insn.getOpcode().getOpcode();
    RegisterSpec result = insn.getResult();

    if (result == null) {
        // Find move-result-pseudo result for int div and int rem
        if (opcode == RegOps.DIV || opcode == RegOps.REM) {
            SsaBasicBlock succ = insn.getBlock().getPrimarySuccessor();
            result = succ.getInsns().get(0).getResult();
        } else {
            return;
        }
    }

    int resultReg = result.getReg();
    int resultValue = VARYING;
    Constant resultConstant = null;

    switch (opcode) {
        case RegOps.CONST: {
            CstInsn cstInsn = (CstInsn)ropInsn;
            resultValue = CONSTANT;
            resultConstant = cstInsn.getConstant();
            break;
        }
        case RegOps.MOVE: {
            if (insn.getSources().size() == 1) {
                int sourceReg = insn.getSources().get(0).getReg();
                resultValue = latticeValues[sourceReg];
                resultConstant = latticeConstants[sourceReg];
            }
            break;
        }
        case RegOps.ADD:
        case RegOps.SUB:
        case RegOps.MUL:
        case RegOps.DIV:
        case RegOps.AND:
        case RegOps.OR:
        case RegOps.XOR:
        case RegOps.SHL:
        case RegOps.SHR:
        case RegOps.USHR:
        case RegOps.REM: {
            resultConstant = simulateMath(insn, result.getBasicType());
            if (resultConstant != null) {
                resultValue = CONSTANT;
            }
            break;
        }
        case RegOps.MOVE_RESULT_PSEUDO: {
            if (latticeValues[resultReg] == CONSTANT) {
                resultValue = latticeValues[resultReg];
                resultConstant = latticeConstants[resultReg];
            }
            break;
        }
        // TODO: Handle non-int arithmetic.
        // TODO: Eliminate check casts that we can prove the type of.
        default: {}
    }
    if (setLatticeValueTo(resultReg, resultValue, resultConstant)) {
        addUsersToWorklist(resultReg, resultValue);
    }
}
 
Example 15
Source File: EscapeAnalysis.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Identifies extra moves added by scalar replacement and propagates the
 * source of the move to any users of the result.
 */
private void movePropagate() {
    for (int i = 0; i < ssaMeth.getRegCount(); i++) {
        SsaInsn insn = ssaMeth.getDefinitionForRegister(i);

        // Look for move instructions only
        if (insn == null || insn.getOpcode() == null ||
            insn.getOpcode().getOpcode() != RegOps.MOVE) {
            continue;
        }

        final ArrayList<SsaInsn>[] useList = ssaMeth.getUseListCopy();
        final RegisterSpec source = insn.getSources().get(0);
        final RegisterSpec result = insn.getResult();

        // Ignore moves that weren't added due to scalar replacement
        if (source.getReg() < regCount && result.getReg() < regCount) {
            continue;
        }

        // Create a mapping from source to result
        RegisterMapper mapper = new RegisterMapper() {
            @Override
            public int getNewRegisterCount() {
                return ssaMeth.getRegCount();
            }

            @Override
            public RegisterSpec map(RegisterSpec registerSpec) {
                if (registerSpec.getReg() == result.getReg()) {
                    return source;
                }

                return registerSpec;
            }
        };

        // Modify all uses of the move to use the source of the move instead
        for (SsaInsn use : useList[result.getReg()]) {
            use.mapSourceRegisters(mapper);
        }
    }
}
 
Example 16
Source File: NormalSsaInsn.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if this is a move (but not a move-operand) instruction
 */
@Override
public boolean isNormalMoveInsn() {
    return insn.getOpcode().getOpcode() == RegOps.MOVE;
}