com.android.dx.rop.code.CstInsn Java Examples

The following examples show how to use com.android.dx.rop.code.CstInsn. 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: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter index for SSA registers that are method parameters.
 * {@code -1} is returned for non-parameter registers.
 *
 * @param ssaReg {@code >=0;} SSA register to look up
 * @return parameter index or {@code -1} if not a parameter
 */
private int getParameterIndexForReg(int ssaReg) {
    SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg);
    if (defInsn == null) {
        return -1;
    }

    Rop opcode = defInsn.getOpcode();

    // opcode == null for phi insns.
    if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) {
        CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn();
        return  ((CstInteger) origInsn.getConstant()).getValue();
    }

    return -1;
}
 
Example #2
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter index for SSA registers that are method parameters.
 * {@code -1} is returned for non-parameter registers.
 *
 * @param ssaReg {@code >=0;} SSA register to look up
 * @return parameter index or {@code -1} if not a parameter
 */
private int getParameterIndexForReg(int ssaReg) {
    SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg);
    if (defInsn == null) {
        return -1;
    }

    Rop opcode = defInsn.getOpcode();

    // opcode == null for phi insns.
    if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) {
        CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn();
        return  ((CstInteger) origInsn.getConstant()).getValue();
    }

    return -1;
}
 
Example #3
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter index for SSA registers that are method parameters.
 * {@code -1} is returned for non-parameter registers.
 *
 * @param ssaReg {@code >=0;} SSA register to look up
 * @return parameter index or {@code -1} if not a parameter
 */
private int getParameterIndexForReg(int ssaReg) {
    SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg);
    if (defInsn == null) {
        return -1;
    }

    Rop opcode = defInsn.getOpcode();

    // opcode == null for phi insns.
    if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) {
        CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn();
        return  ((CstInteger) origInsn.getConstant()).getValue();
    }

    return -1;
}
 
Example #4
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter index for SSA registers that are method parameters.
 * {@code -1} is returned for non-parameter registers.
 *
 * @param ssaReg {@code >=0;} SSA register to look up
 * @return parameter index or {@code -1} if not a parameter
 */
private int getParameterIndexForReg(int ssaReg) {
    SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg);
    if (defInsn == null) {
        return -1;
    }

    Rop opcode = defInsn.getOpcode();

    // opcode == null for phi insns.
    if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) {
        CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn();
        return  ((CstInteger) origInsn.getConstant()).getValue();
    }

    return -1;
}
 
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: FirstFitAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the parameter number that this move-param insn refers to
 * @param ndefInsn a move-param insn (otherwise, exceptions will be thrown)
 * @return parameter number (offset in the total parameter width)
 */
private int paramNumberFromMoveParam(NormalSsaInsn ndefInsn) {
    CstInsn origInsn = (CstInsn) ndefInsn.getOriginalRopInsn();

    return ((CstInteger) origInsn.getConstant()).getValue();
}
 
Example #7
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 #8
Source File: FirstFitAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the parameter number that this move-param insn refers to
 * @param ndefInsn a move-param insn (otherwise, exceptions will be thrown)
 * @return parameter number (offset in the total parameter width)
 */
private int paramNumberFromMoveParam(NormalSsaInsn ndefInsn) {
    CstInsn origInsn = (CstInsn) ndefInsn.getOriginalRopInsn();

    return ((CstInteger) origInsn.getConstant()).getValue();
}
 
Example #9
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 #10
Source File: FirstFitAllocator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the parameter number that this move-param insn refers to
 * @param ndefInsn a move-param insn (otherwise, exceptions will be thrown)
 * @return parameter number (offset in the total parameter width)
 */
private int paramNumberFromMoveParam(NormalSsaInsn ndefInsn) {
    CstInsn origInsn = (CstInsn) ndefInsn.getOriginalRopInsn();

    return ((CstInteger) origInsn.getConstant()).getValue();
}
 
Example #11
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 #12
Source File: FirstFitAllocator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the parameter number that this move-param insn refers to
 * @param ndefInsn a move-param insn (otherwise, exceptions will be thrown)
 * @return parameter number (offset in the total parameter width)
 */
private int paramNumberFromMoveParam(NormalSsaInsn ndefInsn) {
    CstInsn origInsn = (CstInsn) ndefInsn.getOriginalRopInsn();

    return ((CstInteger) origInsn.getConstant()).getValue();
}
 
Example #13
Source File: MoveParamCombiner.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the parameter index associated with a move-param insn. Does
 * not verify that the insn is a move-param insn.
 *
 * @param insn {@code non-null;} a move-param insn
 * @return {@code >=0;} parameter index
 */
private int getParamIndex(NormalSsaInsn insn) {
    CstInsn cstInsn = (CstInsn)(insn.getOriginalRopInsn());

    int param = ((CstInteger)cstInsn.getConstant()).getValue();
    return param;
}
 
Example #14
Source File: MoveParamCombiner.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the parameter index associated with a move-param insn. Does
 * not verify that the insn is a move-param insn.
 *
 * @param insn {@code non-null;} a move-param insn
 * @return {@code >=0;} parameter index
 */
private int getParamIndex(NormalSsaInsn insn) {
    CstInsn cstInsn = (CstInsn)(insn.getOriginalRopInsn());

    int param = ((CstInteger)cstInsn.getConstant()).getValue();
    return param;
}
 
Example #15
Source File: MoveParamCombiner.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the parameter index associated with a move-param insn. Does
 * not verify that the insn is a move-param insn.
 *
 * @param insn {@code non-null;} a move-param insn
 * @return {@code >=0;} parameter index
 */
private int getParamIndex(NormalSsaInsn insn) {
    CstInsn cstInsn = (CstInsn)(insn.getOriginalRopInsn());

    int param = ((CstInteger)cstInsn.getConstant()).getValue();
    return param;
}
 
Example #16
Source File: MoveParamCombiner.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the parameter index associated with a move-param insn. Does
 * not verify that the insn is a move-param insn.
 *
 * @param insn {@code non-null;} a move-param insn
 * @return {@code >=0;} parameter index
 */
private int getParamIndex(NormalSsaInsn insn) {
    CstInsn cstInsn = (CstInsn)(insn.getOriginalRopInsn());

    int param = ((CstInteger)cstInsn.getConstant()).getValue();
    return param;
}