Search in sources :

Example 21 with RegisterSpec

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

the class LiteralOpUpgrader method tryReplacingWithConstant.

/**
     * Tries to replace an instruction with a const instruction. The given
     * instruction must have a constant result for it to be replaced.
     *
     * @param insn {@code non-null;} instruction to try to replace
     * @return true if the instruction was replaced
     */
private boolean tryReplacingWithConstant(NormalSsaInsn insn) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop opcode = originalRopInsn.getOpcode();
    RegisterSpec result = insn.getResult();
    if (result != null && !ssaMeth.isRegALocal(result) && opcode.getOpcode() != RegOps.CONST) {
        TypeBearer type = insn.getResult().getTypeBearer();
        if (type.isConstant() && type.getBasicType() == Type.BT_INT) {
            // Replace the instruction with a constant
            replacePlainInsn(insn, RegisterSpecList.EMPTY, RegOps.CONST, (Constant) type);
            // Remove the source as well if this is a move-result-pseudo
            if (opcode.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
                int pred = insn.getBlock().getPredecessors().nextSetBit(0);
                ArrayList<SsaInsn> predInsns = ssaMeth.getBlocks().get(pred).getInsns();
                NormalSsaInsn sourceInsn = (NormalSsaInsn) predInsns.get(predInsns.size() - 1);
                replacePlainInsn(sourceInsn, RegisterSpecList.EMPTY, RegOps.GOTO, null);
            }
            return true;
        }
    }
    return false;
}
Also used : Insn(com.taobao.android.dx.rop.code.Insn) PlainCstInsn(com.taobao.android.dx.rop.code.PlainCstInsn) PlainInsn(com.taobao.android.dx.rop.code.PlainInsn) Rop(com.taobao.android.dx.rop.code.Rop) TypeBearer(com.taobao.android.dx.rop.type.TypeBearer) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 22 with RegisterSpec

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

the class NormalSsaInsn method getLocalAssignment.

/** {@inheritDoc} */
@Override
public RegisterSpec getLocalAssignment() {
    RegisterSpec assignment;
    if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
        assignment = insn.getSources().get(0);
    } else {
        assignment = getResult();
    }
    if (assignment == null) {
        return null;
    }
    LocalItem local = assignment.getLocalItem();
    if (local == null) {
        return null;
    }
    return assignment;
}
Also used : LocalItem(com.taobao.android.dx.rop.code.LocalItem) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 23 with RegisterSpec

use of com.taobao.android.dx.rop.code.RegisterSpec 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 24 with RegisterSpec

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

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

Example 25 with RegisterSpec

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

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

Aggregations

RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)66 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)24 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)12 Constant (com.taobao.android.dx.rop.cst.Constant)10 TypedConstant (com.taobao.android.dx.rop.cst.TypedConstant)8 ArrayList (java.util.ArrayList)8 Insn (com.taobao.android.dx.rop.code.Insn)7 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)7 Rop (com.taobao.android.dx.rop.code.Rop)7 ThrowingCstInsn (com.taobao.android.dx.rop.code.ThrowingCstInsn)7 CstType (com.taobao.android.dx.rop.cst.CstType)7 TypeBearer (com.taobao.android.dx.rop.type.TypeBearer)7 LocalItem (com.taobao.android.dx.rop.code.LocalItem)5 RegisterSpecSet (com.taobao.android.dx.rop.code.RegisterSpecSet)5 ThrowingInsn (com.taobao.android.dx.rop.code.ThrowingInsn)5 CstString (com.taobao.android.dx.rop.cst.CstString)5 BitSet (java.util.BitSet)5 HashSet (java.util.HashSet)5 SourcePosition (com.taobao.android.dx.rop.code.SourcePosition)4 CstFieldRef (com.taobao.android.dx.rop.cst.CstFieldRef)4