Search in sources :

Example 51 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList 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 52 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList 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 53 with RegisterSpecList

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

the class NormalSsaInsn method setNewSources.

/**
     * Changes the source list of the insn. New source list should be the
     * same size and consist of sources of identical types.
     *
     * @param newSources non-null new sources list.
     */
public final void setNewSources(RegisterSpecList newSources) {
    RegisterSpecList origSources = insn.getSources();
    if (origSources.size() != newSources.size()) {
        throw new RuntimeException("Sources counts don't match");
    }
    insn = insn.withNewRegisters(getResult(), newSources);
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 54 with RegisterSpecList

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

the class NormalSsaInsn method mapSourceRegisters.

/** {@inheritDoc} */
@Override
public final void mapSourceRegisters(RegisterMapper mapper) {
    RegisterSpecList oldSources = insn.getSources();
    RegisterSpecList newSources = mapper.map(oldSources);
    if (newSources != oldSources) {
        insn = insn.withNewRegisters(getResult(), newSources);
        getBlock().getParent().onSourcesChanged(this, oldSources);
    }
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 55 with RegisterSpecList

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

the class PhiInsn method getSources.

/**
     * Gets sources. Constructed lazily from phi operand data structures and
     * then cached.
     *
     * @return {@code non-null;} sources list
     */
@Override
public RegisterSpecList getSources() {
    if (sources != null) {
        return sources;
    }
    if (operands.size() == 0) {
        // How'd this happen? A phi insn with no operand?
        return RegisterSpecList.EMPTY;
    }
    int szSources = operands.size();
    sources = new RegisterSpecList(szSources);
    for (int i = 0; i < szSources; i++) {
        Operand o = operands.get(i);
        sources.set(i, o.regSpec);
    }
    sources.setImmutable();
    return sources;
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Aggregations

RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)202 RegisterSpec (com.android.dx.rop.code.RegisterSpec)50 BitSet (java.util.BitSet)45 CstLiteralBits (com.android.dx.rop.cst.CstLiteralBits)42 Constant (com.android.dx.rop.cst.Constant)36 CstInsn (com.android.dx.dex.code.CstInsn)34 PlainInsn (com.android.dx.rop.code.PlainInsn)18 CstType (com.android.dx.rop.cst.CstType)12 TargetInsn (com.android.dx.dex.code.TargetInsn)10 Insn (com.android.dx.rop.code.Insn)10 TypedConstant (com.android.dx.rop.cst.TypedConstant)10 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)8 Rop (com.android.dx.rop.code.Rop)8 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)8 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)8 TypeBearer (com.android.dx.rop.type.TypeBearer)8 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)6 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)6 CstInteger (com.android.dx.rop.cst.CstInteger)6 MultiCstInsn (com.android.dx.dex.code.MultiCstInsn)4