Java Code Examples for com.android.dx.rop.code.Rop#BRANCH_NONE

The following examples show how to use com.android.dx.rop.code.Rop#BRANCH_NONE . 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: RopTranslator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
      @Override
public void visitFillArrayDataInsn(FillArrayDataInsn insn) {
          SourcePosition pos = insn.getPosition();
          Constant cst = insn.getConstant();
          ArrayList<Constant> values = insn.getInitValues();
          Rop rop = insn.getOpcode();

          if (rop.getBranchingness() != Rop.BRANCH_NONE) {
              throw new RuntimeException("shouldn't happen");
          }
          CodeAddress dataAddress = new CodeAddress(pos);
          ArrayData dataInsn =
              new ArrayData(pos, lastAddress, values, cst);

          TargetInsn fillArrayDataInsn =
              new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
                      dataAddress);

          addOutput(lastAddress);
          addOutput(fillArrayDataInsn);

          addOutputSuffix(new OddSpacer(pos));
          addOutputSuffix(dataAddress);
          addOutputSuffix(dataInsn);
      }
 
Example 2
Source File: RopTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitFillArrayDataInsn(FillArrayDataInsn insn) {
    SourcePosition pos = insn.getPosition();
    Constant cst = insn.getConstant();
    ArrayList<Constant> values = insn.getInitValues();
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_NONE) {
        throw new RuntimeException("shouldn't happen");
    }
    CodeAddress dataAddress = new CodeAddress(pos);
    ArrayData dataInsn =
        new ArrayData(pos, lastAddress, values, cst);

    TargetInsn fillArrayDataInsn =
        new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
                dataAddress);

    addOutput(lastAddress);
    addOutput(fillArrayDataInsn);

    addOutputSuffix(new OddSpacer(pos));
    addOutputSuffix(dataAddress);
    addOutputSuffix(dataInsn);
}
 
Example 3
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 4
Source File: RopTranslator.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void visitFillArrayDataInsn(FillArrayDataInsn insn) {
    SourcePosition pos = insn.getPosition();
    Constant cst = insn.getConstant();
    ArrayList<Constant> values = insn.getInitValues();
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_NONE) {
        throw new RuntimeException("shouldn't happen");
    }
    CodeAddress dataAddress = new CodeAddress(pos);
    ArrayData dataInsn =
        new ArrayData(pos, lastAddress, values, cst);

    TargetInsn fillArrayDataInsn =
        new TargetInsn(Dops.FILL_ARRAY_DATA, pos, getRegs(insn),
                dataAddress);

    addOutput(lastAddress);
    addOutput(fillArrayDataInsn);

    addOutputSuffix(new OddSpacer(pos));
    addOutputSuffix(dataAddress);
    addOutputSuffix(dataInsn);
}
 
Example 5
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 6
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 7
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 8
Source File: RopTranslator.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitPlainCstInsn(PlainCstInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();
    int ropOpcode = rop.getOpcode();
    DalvInsn di;

    if (rop.getBranchingness() != Rop.BRANCH_NONE) {
        throw new RuntimeException("shouldn't happen");
    }

    if (ropOpcode == RegOps.MOVE_PARAM) {
        if (!paramsAreInOrder) {
            /*
             * Parameters are not in order at the top of the reg space.
             * We need to add moves.
             */

            RegisterSpec dest = insn.getResult();
            int param =
                ((CstInteger) insn.getConstant()).getValue();
            RegisterSpec source =
                RegisterSpec.make(regCount - paramSize + param,
                        dest.getType());
            di = new SimpleInsn(opcode, pos,
                                RegisterSpecList.make(dest, source));
            addOutput(di);
        }
    } else {
        // No moves required for the parameters
        RegisterSpecList regs = getRegs(insn);
        di = new CstInsn(opcode, pos, regs, insn.getConstant());
        addOutput(di);
    }
}
 
Example 9
Source File: RopTranslator.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void visitPlainCstInsn(PlainCstInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();
    int ropOpcode = rop.getOpcode();
    DalvInsn di;

    if (rop.getBranchingness() != Rop.BRANCH_NONE) {
        throw new RuntimeException("shouldn't happen");
    }

    if (ropOpcode == RegOps.MOVE_PARAM) {
        if (!paramsAreInOrder) {
            /*
             * Parameters are not in order at the top of the reg space.
             * We need to add moves.
             */

            RegisterSpec dest = insn.getResult();
            int param =
                ((CstInteger) insn.getConstant()).getValue();
            RegisterSpec source =
                RegisterSpec.make(regCount - paramSize + param,
                        dest.getType());
            di = new SimpleInsn(opcode, pos,
                                RegisterSpecList.make(dest, source));
            addOutput(di);
        }
    } else {
        // No moves required for the parameters
        RegisterSpecList regs = getRegs(insn);
        di = new CstInsn(opcode, pos, regs, insn.getConstant());
        addOutput(di);
    }
}
 
Example 10
Source File: SsaBasicBlock.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the last insn in this block. The provided insn must have
 * some branchingness.
 *
 * @param insn {@code non-null;} rop-form insn to add, which must branch.
 */
public void replaceLastInsn(Insn insn) {
    if (insn.getOpcode().getBranchingness() == Rop.BRANCH_NONE) {
        throw new IllegalArgumentException("last insn must branch");
    }

    SsaInsn oldInsn = insns.get(insns.size() - 1);
    SsaInsn newInsn = SsaInsn.makeFromRop(insn, this);

    insns.set(insns.size() - 1, newInsn);

    parent.onInsnRemoved(oldInsn);
    parent.onInsnAdded(newInsn);
}
 
Example 11
Source File: SsaMethod.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes all insns in the set from this method.
 *
 * @param deletedInsns {@code non-null;} insns to delete
 */
public void deleteInsns(Set<SsaInsn> deletedInsns) {
    for (SsaBasicBlock block : getBlocks()) {
        ArrayList<SsaInsn> insns = block.getInsns();

        for (int i = insns.size() - 1; i >= 0; i--) {
            SsaInsn insn = insns.get(i);

            if (deletedInsns.contains(insn)) {
                onInsnRemoved(insn);
                insns.remove(i);
            }
        }

        // Check to see if we need to add a GOTO

        int insnsSz = insns.size();
        SsaInsn lastInsn = (insnsSz == 0) ? null : insns.get(insnsSz - 1);

        if (block != getExitBlock() && (insnsSz == 0
                || lastInsn.getOriginalRopInsn() == null
                || lastInsn.getOriginalRopInsn().getOpcode()
                    .getBranchingness() == Rop.BRANCH_NONE)) {
            // We managed to eat a throwable insn

            Insn gotoInsn = new PlainInsn(Rops.GOTO,
                    SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY);
            insns.add(SsaInsn.makeFromRop(gotoInsn, block));

            // Remove secondary successors from this block
            BitSet succs = block.getSuccessors();
            for (int i = succs.nextSetBit(0); i >= 0;
                     i = succs.nextSetBit(i + 1)) {
                if (i != block.getPrimarySuccessorIndex()) {
                    block.removeSuccessor(i);
                }
            }
        }
    }
}
 
Example 12
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 13
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitPlainInsn(PlainInsn insn) {
    Rop rop = insn.getOpcode();
    if (rop.getOpcode() == RegOps.MARK_LOCAL) {
        /*
         * Ignore these. They're dealt with by
         * the LocalVariableAwareTranslationVisitor
         */
        return;
    }
    if (rop.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
        // These get skipped
        return;
    }

    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    DalvInsn di;

    switch (rop.getBranchingness()) {
        case Rop.BRANCH_NONE:
        case Rop.BRANCH_RETURN:
        case Rop.BRANCH_THROW: {
            di = new SimpleInsn(opcode, pos, getRegs(insn));
            break;
        }
        case Rop.BRANCH_GOTO: {
            /*
             * Code in the main translation loop will emit a
             * goto if necessary (if the branch isn't to the
             * immediately subsequent block).
             */
            return;
        }
        case Rop.BRANCH_IF: {
            int target = block.getSuccessors().get(1);
            di = new TargetInsn(opcode, pos, getRegs(insn),
                                addresses.getStart(target));
            break;
        }
        default: {
            throw new RuntimeException("shouldn't happen");
        }
    }

    addOutput(di);
}
 
Example 14
Source File: ConstCollector.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the optimization.
 */
private void run() {
    int regSz = ssaMeth.getRegCount();

    ArrayList<TypedConstant> constantList
            = getConstsSortedByCountUse();

    int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS);

    SsaBasicBlock start = ssaMeth.getEntryBlock();

    // Constant to new register containing the constant
    HashMap<TypedConstant, RegisterSpec> newRegs
            = new HashMap<TypedConstant, RegisterSpec> (toCollect);

    for (int i = 0; i < toCollect; i++) {
        TypedConstant cst = constantList.get(i);
        RegisterSpec result
                = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst);

        Rop constRop = Rops.opConst(cst);

        if (constRop.getBranchingness() == Rop.BRANCH_NONE) {
            start.addInsnToHead(
                    new PlainCstInsn(Rops.opConst(cst),
                            SourcePosition.NO_INFO, result,
                            RegisterSpecList.EMPTY, cst));
        } else {
            // We need two new basic blocks along with the new insn
            SsaBasicBlock entryBlock = ssaMeth.getEntryBlock();
            SsaBasicBlock successorBlock
                    = entryBlock.getPrimarySuccessor();

            // Insert a block containing the const insn.
            SsaBasicBlock constBlock
                    = entryBlock.insertNewSuccessor(successorBlock);

            constBlock.replaceLastInsn(
                    new ThrowingCstInsn(constRop, SourcePosition.NO_INFO,
                            RegisterSpecList.EMPTY,
                            StdTypeList.EMPTY, cst));

            // Insert a block containing the move-result-pseudo insn.

            SsaBasicBlock resultBlock
                    = constBlock.insertNewSuccessor(successorBlock);
            PlainInsn insn
                = new PlainInsn(
                        Rops.opMoveResultPseudo(result.getTypeBearer()),
                        SourcePosition.NO_INFO,
                        result, RegisterSpecList.EMPTY);

            resultBlock.addInsnToHead(insn);
        }

        newRegs.put(cst, result);
    }

    updateConstUses(newRegs, regSz);
}
 
Example 15
Source File: SsaMethod.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes all insns in the set from this method.
 *
 * @param deletedInsns {@code non-null;} insns to delete
 */
public void deleteInsns(Set<SsaInsn> deletedInsns) {
    for (SsaInsn deletedInsn : deletedInsns) {
        SsaBasicBlock block = deletedInsn.getBlock();
        ArrayList<SsaInsn> insns = block.getInsns();

        for (int i = insns.size() - 1; i >= 0; i--) {
            SsaInsn insn = insns.get(i);

            if (deletedInsn == insn) {
                onInsnRemoved(insn);
                insns.remove(i);
                break;
            }
        }

        // Check to see if we need to add a GOTO

        int insnsSz = insns.size();
        SsaInsn lastInsn = (insnsSz == 0) ? null : insns.get(insnsSz - 1);

        if (block != getExitBlock() && (insnsSz == 0
                || lastInsn.getOriginalRopInsn() == null
                || lastInsn.getOriginalRopInsn().getOpcode()
                    .getBranchingness() == Rop.BRANCH_NONE)) {
            // We managed to eat a throwable insn

            Insn gotoInsn = new PlainInsn(Rops.GOTO,
                    SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY);
            insns.add(SsaInsn.makeFromRop(gotoInsn, block));

            // Remove secondary successors from this block
            BitSet succs = block.getSuccessors();
            for (int i = succs.nextSetBit(0); i >= 0;
                     i = succs.nextSetBit(i + 1)) {
                if (i != block.getPrimarySuccessorIndex()) {
                    block.removeSuccessor(i);
                }
            }
        }
    }
}
 
Example 16
Source File: SsaMethod.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes all insns in the set from this method.
 *
 * @param deletedInsns {@code non-null;} insns to delete
 */
public void deleteInsns(Set<SsaInsn> deletedInsns) {
    for (SsaInsn deletedInsn : deletedInsns) {
        SsaBasicBlock block = deletedInsn.getBlock();
        ArrayList<SsaInsn> insns = block.getInsns();

        for (int i = insns.size() - 1; i >= 0; i--) {
            SsaInsn insn = insns.get(i);

            if (deletedInsn == insn) {
                onInsnRemoved(insn);
                insns.remove(i);
                break;
            }
        }

        // Check to see if we need to add a GOTO

        int insnsSz = insns.size();
        SsaInsn lastInsn = (insnsSz == 0) ? null : insns.get(insnsSz - 1);

        if (block != getExitBlock() && (insnsSz == 0
                || lastInsn.getOriginalRopInsn() == null
                || lastInsn.getOriginalRopInsn().getOpcode()
                    .getBranchingness() == Rop.BRANCH_NONE)) {
            // We managed to eat a throwable insn

            Insn gotoInsn = new PlainInsn(Rops.GOTO,
                    SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY);
            insns.add(SsaInsn.makeFromRop(gotoInsn, block));

            // Remove secondary successors from this block
            BitSet succs = block.getSuccessors();
            for (int i = succs.nextSetBit(0); i >= 0;
                     i = succs.nextSetBit(i + 1)) {
                if (i != block.getPrimarySuccessorIndex()) {
                    block.removeSuccessor(i);
                }
            }
        }
    }
}
 
Example 17
Source File: ConstCollector.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Applies the optimization.
 */
private void run() {
    int regSz = ssaMeth.getRegCount();

    ArrayList<TypedConstant> constantList
            = getConstsSortedByCountUse();

    int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS);

    SsaBasicBlock start = ssaMeth.getEntryBlock();

    // Constant to new register containing the constant
    HashMap<TypedConstant, RegisterSpec> newRegs
            = new HashMap<TypedConstant, RegisterSpec> (toCollect);

    for (int i = 0; i < toCollect; i++) {
        TypedConstant cst = constantList.get(i);
        RegisterSpec result
                = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst);

        Rop constRop = Rops.opConst(cst);

        if (constRop.getBranchingness() == Rop.BRANCH_NONE) {
            start.addInsnToHead(
                    new PlainCstInsn(Rops.opConst(cst),
                            SourcePosition.NO_INFO, result,
                            RegisterSpecList.EMPTY, cst));
        } else {
            // We need two new basic blocks along with the new insn
            SsaBasicBlock entryBlock = ssaMeth.getEntryBlock();
            SsaBasicBlock successorBlock
                    = entryBlock.getPrimarySuccessor();

            // Insert a block containing the const insn.
            SsaBasicBlock constBlock
                    = entryBlock.insertNewSuccessor(successorBlock);

            constBlock.replaceLastInsn(
                    new ThrowingCstInsn(constRop, SourcePosition.NO_INFO,
                            RegisterSpecList.EMPTY,
                            StdTypeList.EMPTY, cst));

            // Insert a block containing the move-result-pseudo insn.

            SsaBasicBlock resultBlock
                    = constBlock.insertNewSuccessor(successorBlock);
            PlainInsn insn
                = new PlainInsn(
                        Rops.opMoveResultPseudo(result.getTypeBearer()),
                        SourcePosition.NO_INFO,
                        result, RegisterSpecList.EMPTY);

            resultBlock.addInsnToHead(insn);
        }

        newRegs.put(cst, result);
    }

    updateConstUses(newRegs, regSz);
}
 
Example 18
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 19
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitPlainInsn(PlainInsn insn) {
    Rop rop = insn.getOpcode();
    if (rop.getOpcode() == RegOps.MARK_LOCAL) {
        /*
         * Ignore these. They're dealt with by
         * the LocalVariableAwareTranslationVisitor
         */
        return;
    }
    if (rop.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
        // These get skipped
        return;
    }

    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    DalvInsn di;

    switch (rop.getBranchingness()) {
        case Rop.BRANCH_NONE:
        case Rop.BRANCH_RETURN:
        case Rop.BRANCH_THROW: {
            di = new SimpleInsn(opcode, pos, getRegs(insn));
            break;
        }
        case Rop.BRANCH_GOTO: {
            /*
             * Code in the main translation loop will emit a
             * goto if necessary (if the branch isn't to the
             * immediately subsequent block).
             */
            return;
        }
        case Rop.BRANCH_IF: {
            int target = block.getSuccessors().get(1);
            di = new TargetInsn(opcode, pos, getRegs(insn),
                                addresses.getStart(target));
            break;
        }
        default: {
            throw new RuntimeException("shouldn't happen");
        }
    }

    addOutput(di);
}
 
Example 20
Source File: RopTranslator.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void visitPlainInsn(PlainInsn insn) {
    Rop rop = insn.getOpcode();
    if (rop.getOpcode() == RegOps.MARK_LOCAL) {
        /*
         * Ignore these. They're dealt with by
         * the LocalVariableAwareTranslationVisitor
         */
        return;
    }
    if (rop.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
        // These get skipped
        return;
    }

    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    DalvInsn di;

    switch (rop.getBranchingness()) {
        case Rop.BRANCH_NONE:
        case Rop.BRANCH_RETURN:
        case Rop.BRANCH_THROW: {
            di = new SimpleInsn(opcode, pos, getRegs(insn));
            break;
        }
        case Rop.BRANCH_GOTO: {
            /*
             * Code in the main translation loop will emit a
             * goto if necessary (if the branch isn't to the
             * immediately subsequent block).
             */
            return;
        }
        case Rop.BRANCH_IF: {
            int target = block.getSuccessors().get(1);
            di = new TargetInsn(opcode, pos, getRegs(insn),
                                addresses.getStart(target));
            break;
        }
        default: {
            throw new RuntimeException("shouldn't happen");
        }
    }

    addOutput(di);
}