Search in sources :

Example 16 with CstInteger

use of com.android.dx.rop.cst.CstInteger in project J2ME-Loader by nikita36078.

the class MoveParamCombiner method getParamIndex.

/**
 * 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;
}
Also used : CstInsn(com.android.dx.rop.code.CstInsn) CstInteger(com.android.dx.rop.cst.CstInteger)

Example 17 with CstInteger

use of com.android.dx.rop.cst.CstInteger in project J2ME-Loader by nikita36078.

the class SCCP method simulateBranch.

/**
 * Simulates branch insns, if possible. Adds reachable successor blocks
 * to the CFG worklists.
 * @param insn branch to simulate
 */
private void simulateBranch(SsaInsn insn) {
    Rop opcode = insn.getOpcode();
    RegisterSpecList sources = insn.getSources();
    boolean constantBranch = false;
    boolean constantSuccessor = false;
    // Check if the insn is a branch with a constant condition
    if (opcode.getBranchingness() == Rop.BRANCH_IF) {
        Constant cA = null;
        Constant cB = null;
        RegisterSpec specA = sources.get(0);
        int regA = specA.getReg();
        if (!ssaMeth.isRegALocal(specA) && latticeValues[regA] == CONSTANT) {
            cA = latticeConstants[regA];
        }
        if (sources.size() == 2) {
            RegisterSpec specB = sources.get(1);
            int regB = specB.getReg();
            if (!ssaMeth.isRegALocal(specB) && latticeValues[regB] == CONSTANT) {
                cB = latticeConstants[regB];
            }
        }
        // Calculate the result of the condition
        if (cA != null && sources.size() == 1) {
            switch(((TypedConstant) cA).getBasicType()) {
                case Type.BT_INT:
                    constantBranch = true;
                    int vA = ((CstInteger) cA).getValue();
                    switch(opcode.getOpcode()) {
                        case RegOps.IF_EQ:
                            constantSuccessor = (vA == 0);
                            break;
                        case RegOps.IF_NE:
                            constantSuccessor = (vA != 0);
                            break;
                        case RegOps.IF_LT:
                            constantSuccessor = (vA < 0);
                            break;
                        case RegOps.IF_GE:
                            constantSuccessor = (vA >= 0);
                            break;
                        case RegOps.IF_LE:
                            constantSuccessor = (vA <= 0);
                            break;
                        case RegOps.IF_GT:
                            constantSuccessor = (vA > 0);
                            break;
                        default:
                            throw new RuntimeException("Unexpected op");
                    }
                    break;
                default:
            }
        } else if (cA != null && cB != null) {
            switch(((TypedConstant) cA).getBasicType()) {
                case Type.BT_INT:
                    constantBranch = true;
                    int vA = ((CstInteger) cA).getValue();
                    int vB = ((CstInteger) cB).getValue();
                    switch(opcode.getOpcode()) {
                        case RegOps.IF_EQ:
                            constantSuccessor = (vA == vB);
                            break;
                        case RegOps.IF_NE:
                            constantSuccessor = (vA != vB);
                            break;
                        case RegOps.IF_LT:
                            constantSuccessor = (vA < vB);
                            break;
                        case RegOps.IF_GE:
                            constantSuccessor = (vA >= vB);
                            break;
                        case RegOps.IF_LE:
                            constantSuccessor = (vA <= vB);
                            break;
                        case RegOps.IF_GT:
                            constantSuccessor = (vA > vB);
                            break;
                        default:
                            throw new RuntimeException("Unexpected op");
                    }
                    break;
                default:
            }
        }
    }
    /*
         * If condition is constant, add only the target block to the
         * worklist. Otherwise, add all successors to the worklist.
         */
    SsaBasicBlock block = insn.getBlock();
    if (constantBranch) {
        int successorBlock;
        if (constantSuccessor) {
            successorBlock = block.getSuccessorList().get(1);
        } else {
            successorBlock = block.getSuccessorList().get(0);
        }
        addBlockToWorklist(ssaMeth.getBlocks().get(successorBlock));
        branchWorklist.add(insn);
    } else {
        for (int i = 0; i < block.getSuccessorList().size(); i++) {
            int successorBlock = block.getSuccessorList().get(i);
            addBlockToWorklist(ssaMeth.getBlocks().get(successorBlock));
        }
    }
}
Also used : Rop(com.android.dx.rop.code.Rop) TypedConstant(com.android.dx.rop.cst.TypedConstant) Constant(com.android.dx.rop.cst.Constant) TypedConstant(com.android.dx.rop.cst.TypedConstant) CstInteger(com.android.dx.rop.cst.CstInteger) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 18 with CstInteger

use of com.android.dx.rop.cst.CstInteger in project J2ME-Loader by nikita36078.

the class FirstFitLocalCombiningAllocator method getParameterIndexForReg.

/**
 * 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;
}
Also used : CstInsn(com.android.dx.rop.code.CstInsn) Rop(com.android.dx.rop.code.Rop) CstInteger(com.android.dx.rop.cst.CstInteger) NormalSsaInsn(com.android.dx.ssa.NormalSsaInsn) SsaInsn(com.android.dx.ssa.SsaInsn)

Example 19 with CstInteger

use of com.android.dx.rop.cst.CstInteger in project dexmaker by linkedin.

the class Code method initializeLocals.

/**
 * Assigns registers to locals. From the spec:
 *  "the N arguments to a method land in the last N registers of the
 *   method's invocation frame, in order. Wide arguments consume two
 *   registers. Instance methods are passed a this reference as their
 *   first argument."
 *
 * In addition to assigning registers to each of the locals, this creates
 * instructions to move parameters into their initial registers. These
 * instructions are inserted before the code's first real instruction.
 */
void initializeLocals() {
    if (localsInitialized) {
        throw new AssertionError();
    }
    localsInitialized = true;
    int reg = 0;
    for (Local<?> local : locals) {
        reg += local.initialize(reg);
    }
    int firstParamReg = reg;
    List<Insn> moveParameterInstructions = new ArrayList<Insn>();
    for (Local<?> local : parameters) {
        CstInteger paramConstant = CstInteger.make(reg - firstParamReg);
        reg += local.initialize(reg);
        moveParameterInstructions.add(new PlainCstInsn(Rops.opMoveParam(local.type.ropType), sourcePosition, local.spec(), RegisterSpecList.EMPTY, paramConstant));
    }
    labels.get(0).instructions.addAll(0, moveParameterInstructions);
}
Also used : PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) Insn(com.android.dx.rop.code.Insn) PlainInsn(com.android.dx.rop.code.PlainInsn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) CstInteger(com.android.dx.rop.cst.CstInteger) ArrayList(java.util.ArrayList)

Aggregations

CstInteger (com.android.dx.rop.cst.CstInteger)19 Constant (com.android.dx.rop.cst.Constant)12 CstInsn (com.android.dx.rop.code.CstInsn)6 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)6 Rop (com.android.dx.rop.code.Rop)6 CstType (com.android.dx.rop.cst.CstType)6 Insn (com.android.dx.rop.code.Insn)5 PlainInsn (com.android.dx.rop.code.PlainInsn)5 ParseException (com.android.dx.cf.iface.ParseException)4 RegisterSpec (com.android.dx.rop.code.RegisterSpec)4 TypedConstant (com.android.dx.rop.cst.TypedConstant)4 Type (com.android.dx.rop.type.Type)4 TypeBearer (com.android.dx.rop.type.TypeBearer)4 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)3 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)3 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)3 ArrayList (java.util.ArrayList)3 Annotation (com.android.dx.rop.annotation.Annotation)2 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)2 FillArrayDataInsn (com.android.dx.rop.code.FillArrayDataInsn)2