Search in sources :

Example 36 with RegisterSpec

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

the class DeadCodeRemover method run.

/**
     * Runs the dead code remover.
     */
private void run() {
    pruneDeadInstructions();
    HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>();
    ssaMeth.forEachInsn(new NoSideEffectVisitor(worklist));
    int regV;
    while (0 <= (regV = worklist.nextSetBit(0))) {
        worklist.clear(regV);
        if (useList[regV].size() == 0 || isCircularNoSideEffect(regV, null)) {
            SsaInsn insnS = ssaMeth.getDefinitionForRegister(regV);
            // This insn has already been deleted.
            if (deletedInsns.contains(insnS)) {
                continue;
            }
            RegisterSpecList sources = insnS.getSources();
            int sz = sources.size();
            for (int i = 0; i < sz; i++) {
                // Delete this insn from all usage lists.
                RegisterSpec source = sources.get(i);
                useList[source.getReg()].remove(insnS);
                if (!hasSideEffect(ssaMeth.getDefinitionForRegister(source.getReg()))) {
                    /*
                         * Only registers whose definition has no side effect
                         * should be added back to the worklist.
                         */
                    worklist.set(source.getReg());
                }
            }
            // Schedule this insn for later deletion.
            deletedInsns.add(insnS);
        }
    }
    ssaMeth.deleteInsns(deletedInsns);
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec) HashSet(java.util.HashSet)

Example 37 with RegisterSpec

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

the class DeadCodeRemover method pruneDeadInstructions.

/**
     * Removes all instructions from every unreachable block.
     */
private void pruneDeadInstructions() {
    HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>();
    ssaMeth.computeReachability();
    for (SsaBasicBlock block : ssaMeth.getBlocks()) {
        if (block.isReachable())
            continue;
        // Prune instructions from unreachable blocks
        for (int i = 0; i < block.getInsns().size(); i++) {
            SsaInsn insn = block.getInsns().get(i);
            RegisterSpecList sources = insn.getSources();
            int sourcesSize = sources.size();
            // Delete this instruction completely if it has sources
            if (sourcesSize != 0) {
                deletedInsns.add(insn);
            }
            // Delete this instruction from all usage lists.
            for (int j = 0; j < sourcesSize; j++) {
                RegisterSpec source = sources.get(j);
                useList[source.getReg()].remove(insn);
            }
            // Remove this instruction result from the sources of any phis
            RegisterSpec result = insn.getResult();
            if (result == null)
                continue;
            for (SsaInsn use : useList[result.getReg()]) {
                if (use instanceof PhiInsn) {
                    PhiInsn phiUse = (PhiInsn) use;
                    phiUse.removePhiRegister(result);
                }
            }
        }
    }
    ssaMeth.deleteInsns(deletedInsns);
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec) HashSet(java.util.HashSet)

Example 38 with RegisterSpec

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

the class NormalSsaInsn method changeOneSource.

/**
     * Changes one of the insn's sources. New source should be of same type
     * and category.
     *
     * @param index {@code >=0;} index of source to change
     * @param newSpec spec for new source
     */
public final void changeOneSource(int index, RegisterSpec newSpec) {
    RegisterSpecList origSources = insn.getSources();
    int sz = origSources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);
    for (int i = 0; i < sz; i++) {
        newSources.set(i, i == index ? newSpec : origSources.get(i));
    }
    newSources.setImmutable();
    RegisterSpec origSpec = origSources.get(index);
    if (origSpec.getReg() != newSpec.getReg()) {
        /*
             * If the register remains unchanged, we're only changing
             * the type or local var name so don't update use list
             */
        getBlock().getParent().onSourceChanged(this, origSpec, newSpec);
    }
    insn = insn.withNewRegisters(getResult(), newSources);
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 39 with RegisterSpec

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

the class PhiInsn method toHumanWithInline.

/**
     * Returns human-readable string for listing dumps. This method
     * allows sub-classes to specify extra text.
     *
     * @param extra {@code null-ok;} the argument to print after the opcode
     * @return human-readable string for listing dumps
     */
protected final String toHumanWithInline(String extra) {
    StringBuffer sb = new StringBuffer(80);
    sb.append(SourcePosition.NO_INFO);
    sb.append(": phi");
    if (extra != null) {
        sb.append("(");
        sb.append(extra);
        sb.append(")");
    }
    RegisterSpec result = getResult();
    if (result == null) {
        sb.append(" .");
    } else {
        sb.append(" ");
        sb.append(result.toHuman());
    }
    sb.append(" <-");
    int sz = getSources().size();
    if (sz == 0) {
        sb.append(" .");
    } else {
        for (int i = 0; i < sz; i++) {
            sb.append(" ");
            sb.append(sources.get(i).toHuman() + "[b=" + Hex.u2(operands.get(i).ropLabel) + "]");
        }
    }
    return sb.toString();
}
Also used : RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 40 with RegisterSpec

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

the class PhiInsn method mapSourceRegisters.

/** {@inheritDoc} */
@Override
public final void mapSourceRegisters(RegisterMapper mapper) {
    for (Operand o : operands) {
        RegisterSpec old = o.regSpec;
        o.regSpec = mapper.map(old);
        if (old != o.regSpec) {
            getBlock().getParent().onSourceChanged(this, old, o.regSpec);
        }
    }
    sources = null;
}
Also used : RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Aggregations

RegisterSpec (com.android.dx.rop.code.RegisterSpec)135 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)50 PlainInsn (com.android.dx.rop.code.PlainInsn)24 Constant (com.android.dx.rop.cst.Constant)20 TypedConstant (com.android.dx.rop.cst.TypedConstant)16 TypeBearer (com.android.dx.rop.type.TypeBearer)16 ArrayList (java.util.ArrayList)16 Insn (com.android.dx.rop.code.Insn)14 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)14 Rop (com.android.dx.rop.code.Rop)14 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)14 CstType (com.android.dx.rop.cst.CstType)14 BitSet (java.util.BitSet)11 LocalItem (com.android.dx.rop.code.LocalItem)10 RegisterSpecSet (com.android.dx.rop.code.RegisterSpecSet)10 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)10 CstString (com.android.dx.rop.cst.CstString)10 HashSet (java.util.HashSet)10 SourcePosition (com.android.dx.rop.code.SourcePosition)8 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)8