Search in sources :

Example 6 with Rop

use of com.android.dx.rop.code.Rop in project buck by facebook.

the class EscapeAnalysis method insertPlainInsnBefore.

/**
     * Inserts a new PlainInsn before the given instruction.
     * TODO: move this somewhere more appropriate
     *
     * @param insn {@code non-null;} instruction to insert before
     * @param newSources {@code non-null;} sources of new instruction
     * @param newResult {@code non-null;} result of new instruction
     * @param newOpcode opcode of new instruction
     * @param cst {@code null-ok;} constant for new instruction, if any
     */
private void insertPlainInsnBefore(SsaInsn insn, RegisterSpecList newSources, RegisterSpec newResult, int newOpcode, Constant cst) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop newRop;
    if (newOpcode == RegOps.MOVE_RESULT_PSEUDO) {
        newRop = Rops.opMoveResultPseudo(newResult.getType());
    } else {
        newRop = Rops.ropFor(newOpcode, newResult, newSources, cst);
    }
    Insn newRopInsn;
    if (cst == null) {
        newRopInsn = new PlainInsn(newRop, originalRopInsn.getPosition(), newResult, newSources);
    } else {
        newRopInsn = new PlainCstInsn(newRop, originalRopInsn.getPosition(), newResult, newSources, cst);
    }
    NormalSsaInsn newInsn = new NormalSsaInsn(newRopInsn, insn.getBlock());
    List<SsaInsn> insns = insn.getBlock().getInsns();
    insns.add(insns.lastIndexOf(insn), newInsn);
    ssaMeth.onInsnAdded(newInsn);
}
Also used : PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) FillArrayDataInsn(com.android.dx.rop.code.FillArrayDataInsn) Insn(com.android.dx.rop.code.Insn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Rop(com.android.dx.rop.code.Rop)

Example 7 with Rop

use of com.android.dx.rop.code.Rop in project buck by facebook.

the class LiteralOpUpgrader method replacePlainInsn.

/**
     * Replaces an SsaInsn containing a PlainInsn with a new PlainInsn. The
     * new PlainInsn is constructed with a new RegOp and new sources.
     *
     * TODO move this somewhere else.
     *
     * @param insn {@code non-null;} an SsaInsn containing a PlainInsn
     * @param newSources {@code non-null;} new sources list for new insn
     * @param newOpcode A RegOp from {@link RegOps}
     * @param cst {@code null-ok;} constant for new instruction, if any
     */
private void replacePlainInsn(NormalSsaInsn insn, RegisterSpecList newSources, int newOpcode, Constant cst) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop newRop = Rops.ropFor(newOpcode, insn.getResult(), newSources, cst);
    Insn newRopInsn;
    if (cst == null) {
        newRopInsn = new PlainInsn(newRop, originalRopInsn.getPosition(), insn.getResult(), newSources);
    } else {
        newRopInsn = new PlainCstInsn(newRop, originalRopInsn.getPosition(), insn.getResult(), newSources, cst);
    }
    NormalSsaInsn newInsn = new NormalSsaInsn(newRopInsn, insn.getBlock());
    List<SsaInsn> insns = insn.getBlock().getInsns();
    ssaMeth.onInsnRemoved(insn);
    insns.set(insns.lastIndexOf(insn), newInsn);
    ssaMeth.onInsnAdded(newInsn);
}
Also used : PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Insn(com.android.dx.rop.code.Insn) PlainInsn(com.android.dx.rop.code.PlainInsn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Rop(com.android.dx.rop.code.Rop)

Example 8 with Rop

use of com.android.dx.rop.code.Rop in project buck by facebook.

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 9 with Rop

use of com.android.dx.rop.code.Rop in project buck by facebook.

the class NormalSsaInsn method hasSideEffect.

/**
     * {@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;
    }
}
Also used : Rop(com.android.dx.rop.code.Rop)

Example 10 with Rop

use of com.android.dx.rop.code.Rop in project J2ME-Loader by nikita36078.

the class LiteralOpUpgrader method replacePlainInsn.

/**
 * Replaces an SsaInsn containing a PlainInsn with a new PlainInsn. The
 * new PlainInsn is constructed with a new RegOp and new sources.
 *
 * TODO move this somewhere else.
 *
 * @param insn {@code non-null;} an SsaInsn containing a PlainInsn
 * @param newSources {@code non-null;} new sources list for new insn
 * @param newOpcode A RegOp from {@link RegOps}
 * @param cst {@code null-ok;} constant for new instruction, if any
 */
private void replacePlainInsn(NormalSsaInsn insn, RegisterSpecList newSources, int newOpcode, Constant cst) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop newRop = Rops.ropFor(newOpcode, insn.getResult(), newSources, cst);
    Insn newRopInsn;
    if (cst == null) {
        newRopInsn = new PlainInsn(newRop, originalRopInsn.getPosition(), insn.getResult(), newSources);
    } else {
        newRopInsn = new PlainCstInsn(newRop, originalRopInsn.getPosition(), insn.getResult(), newSources, cst);
    }
    NormalSsaInsn newInsn = new NormalSsaInsn(newRopInsn, insn.getBlock());
    List<SsaInsn> insns = insn.getBlock().getInsns();
    ssaMeth.onInsnRemoved(insn);
    insns.set(insns.lastIndexOf(insn), newInsn);
    ssaMeth.onInsnAdded(newInsn);
}
Also used : PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Insn(com.android.dx.rop.code.Insn) PlainInsn(com.android.dx.rop.code.PlainInsn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Rop(com.android.dx.rop.code.Rop)

Aggregations

Rop (com.android.dx.rop.code.Rop)36 PlainInsn (com.android.dx.rop.code.PlainInsn)23 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)19 Insn (com.android.dx.rop.code.Insn)16 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)15 RegisterSpec (com.android.dx.rop.code.RegisterSpec)14 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)11 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)9 FillArrayDataInsn (com.android.dx.rop.code.FillArrayDataInsn)8 Constant (com.android.dx.rop.cst.Constant)6 CstInteger (com.android.dx.rop.cst.CstInteger)6 SourcePosition (com.android.dx.rop.code.SourcePosition)4 SwitchInsn (com.android.dx.rop.code.SwitchInsn)4 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)4 CstType (com.android.dx.rop.cst.CstType)4 TypedConstant (com.android.dx.rop.cst.TypedConstant)4 TypeBearer (com.android.dx.rop.type.TypeBearer)4 SsaInsn (com.android.dx.ssa.SsaInsn)4 BasicBlock (com.android.dx.rop.code.BasicBlock)2 CstInsn (com.android.dx.rop.code.CstInsn)2