Search in sources :

Example 41 with RegisterSpecList

use of com.taobao.android.dx.rop.code.RegisterSpecList in project atlas by alibaba.

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.taobao.android.dx.rop.code.RegisterSpecList)

Example 42 with RegisterSpecList

use of com.taobao.android.dx.rop.code.RegisterSpecList in project atlas by alibaba.

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.taobao.android.dx.rop.code.RegisterSpecList)

Example 43 with RegisterSpecList

use of com.taobao.android.dx.rop.code.RegisterSpecList in project atlas by alibaba.

the class FirstFitLocalCombiningAllocator method adjustAndMapSourceRangeRange.

/**
     * Maps the source registers of the specified instruction such that they
     * will fall in a contiguous range in rop form. Moves are inserted as
     * necessary to allow the range to be allocated.
     *
     * @param insn {@code non-null;} insn whos sources to process
     */
private void adjustAndMapSourceRangeRange(NormalSsaInsn insn) {
    int newRegStart = findRangeAndAdjust(insn);
    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    int nextRopReg = newRegStart;
    for (int i = 0; i < szSources; i++) {
        RegisterSpec source = sources.get(i);
        int sourceReg = source.getReg();
        int category = source.getCategory();
        int curRopReg = nextRopReg;
        nextRopReg += category;
        if (ssaRegsMapped.get(sourceReg)) {
            continue;
        }
        LocalItem localItem = getLocalItemForReg(sourceReg);
        addMapping(source, curRopReg);
        if (localItem != null) {
            markReserved(curRopReg, category);
            ArrayList<RegisterSpec> similarRegisters = localVariables.get(localItem);
            int szSimilar = similarRegisters.size();
            /*
                 * Try to map all SSA registers also associated with
                 * this local.
                 */
            for (int j = 0; j < szSimilar; j++) {
                RegisterSpec similarSpec = similarRegisters.get(j);
                int similarReg = similarSpec.getReg();
                // Don't map anything that's also a source.
                if (-1 != sources.indexOfRegister(similarReg)) {
                    continue;
                }
                // Registers left unmapped will get handled later.
                tryMapReg(similarSpec, curRopReg, category);
            }
        }
    }
}
Also used : LocalItem(com.taobao.android.dx.rop.code.LocalItem) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 44 with RegisterSpecList

use of com.taobao.android.dx.rop.code.RegisterSpecList in project atlas by alibaba.

the class RegisterMapper method map.

/**
     *
     * @param sources old register list
     * @return new mapped register list, or old if nothing has changed.
     */
public final RegisterSpecList map(RegisterSpecList sources) {
    int sz = sources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);
    for (int i = 0; i < sz; i++) {
        newSources.set(i, map(sources.get(i)));
    }
    newSources.setImmutable();
    // Return the old sources if nothing has changed.
    return newSources.equals(sources) ? sources : newSources;
}
Also used : RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList)

Example 45 with RegisterSpecList

use of com.taobao.android.dx.rop.code.RegisterSpecList in project atlas by alibaba.

the class SCCP method simulatePhi.

/**
     * Simulates a PHI node and set the lattice for the result
     * to the appropriate value.
     * Meet values:
     * TOP x anything = TOP
     * VARYING x anything = VARYING
     * CONSTANT x CONSTANT = CONSTANT if equal constants, VARYING otherwise
     * @param insn PHI to simulate.
     */
private void simulatePhi(PhiInsn insn) {
    int phiResultReg = insn.getResult().getReg();
    if (latticeValues[phiResultReg] == VARYING) {
        return;
    }
    RegisterSpecList sources = insn.getSources();
    int phiResultValue = TOP;
    Constant phiConstant = null;
    int sourceSize = sources.size();
    for (int i = 0; i < sourceSize; i++) {
        int predBlockIndex = insn.predBlockIndexForSourcesIndex(i);
        int sourceReg = sources.get(i).getReg();
        int sourceRegValue = latticeValues[sourceReg];
        if (!executableBlocks.get(predBlockIndex)) {
            continue;
        }
        if (sourceRegValue == CONSTANT) {
            if (phiConstant == null) {
                phiConstant = latticeConstants[sourceReg];
                phiResultValue = CONSTANT;
            } else if (!latticeConstants[sourceReg].equals(phiConstant)) {
                phiResultValue = VARYING;
                break;
            }
        } else {
            phiResultValue = sourceRegValue;
            break;
        }
    }
    if (setLatticeValueTo(phiResultReg, phiResultValue, phiConstant)) {
        addUsersToWorklist(phiResultReg, phiResultValue);
    }
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList)

Aggregations

RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)98 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)24 BitSet (java.util.BitSet)22 CstLiteralBits (com.taobao.android.dx.rop.cst.CstLiteralBits)21 CstInsn (com.taobao.android.dx.dex.code.CstInsn)17 Constant (com.taobao.android.dx.rop.cst.Constant)17 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)9 CstType (com.taobao.android.dx.rop.cst.CstType)6 TargetInsn (com.taobao.android.dx.dex.code.TargetInsn)5 Insn (com.taobao.android.dx.rop.code.Insn)5 TypedConstant (com.taobao.android.dx.rop.cst.TypedConstant)5 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)4 Rop (com.taobao.android.dx.rop.code.Rop)4 CstFieldRef (com.taobao.android.dx.rop.cst.CstFieldRef)4 ThrowingCstInsn (com.taobao.android.dx.rop.code.ThrowingCstInsn)3 ThrowingInsn (com.taobao.android.dx.rop.code.ThrowingInsn)3 CstInteger (com.taobao.android.dx.rop.cst.CstInteger)3 CstMethodRef (com.taobao.android.dx.rop.cst.CstMethodRef)3 TypeBearer (com.taobao.android.dx.rop.type.TypeBearer)3 FillArrayDataInsn (com.taobao.android.dx.rop.code.FillArrayDataInsn)2