Search in sources :

Example 6 with CstLiteralBits

use of com.taobao.android.dx.rop.cst.CstLiteralBits in project atlas by alibaba.

the class Form22s method insnArgString.

/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();
    return regs.get(0).regString() + ", " + regs.get(1).regString() + ", " + literalBitsString(value);
}
Also used : CstLiteralBits(com.taobao.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList)

Example 7 with CstLiteralBits

use of com.taobao.android.dx.rop.cst.CstLiteralBits in project atlas by alibaba.

the class ClassDataItem method makeStaticValuesConstant.

/**
     * Gets a {@link CstArray} corresponding to {@link #staticValues} if
     * it contains any non-zero non-{@code null} values.
     *
     * @return {@code null-ok;} the corresponding constant or {@code null} if
     * there are no values to encode
     */
private CstArray makeStaticValuesConstant() {
    // First sort the statics into their final order.
    Collections.sort(staticFields);
    /*
         * Get the size of staticValues minus any trailing zeros/nulls (both
         * nulls per se as well as instances of CstKnownNull).
         */
    int size = staticFields.size();
    while (size > 0) {
        EncodedField field = staticFields.get(size - 1);
        Constant cst = staticValues.get(field);
        if (cst instanceof CstLiteralBits) {
            // Note: CstKnownNull extends CstLiteralBits.
            if (((CstLiteralBits) cst).getLongBits() != 0) {
                break;
            }
        } else if (cst != null) {
            break;
        }
        size--;
    }
    if (size == 0) {
        return null;
    }
    // There is something worth encoding, so build up a result.
    CstArray.List list = new CstArray.List(size);
    for (int i = 0; i < size; i++) {
        EncodedField field = staticFields.get(i);
        Constant cst = staticValues.get(field);
        if (cst == null) {
            cst = Zeroes.zeroFor(field.getRef().getType());
        }
        list.set(i, cst);
    }
    list.setImmutable();
    return new CstArray(list);
}
Also used : CstArray(com.taobao.android.dx.rop.cst.CstArray) CstLiteralBits(com.taobao.android.dx.rop.cst.CstLiteralBits) Constant(com.taobao.android.dx.rop.cst.Constant) ArrayList(java.util.ArrayList)

Example 8 with CstLiteralBits

use of com.taobao.android.dx.rop.cst.CstLiteralBits in project atlas by alibaba.

the class Form31i method isCompatible.

/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) && (regs.size() == 1) && unsignedFitsInByte(regs.get(0).getReg()))) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    Constant cst = ci.getConstant();
    if (!(cst instanceof CstLiteralBits)) {
        return false;
    }
    return ((CstLiteralBits) cst).fitsInInt();
}
Also used : CstInsn(com.taobao.android.dx.dex.code.CstInsn) CstLiteralBits(com.taobao.android.dx.rop.cst.CstLiteralBits) Constant(com.taobao.android.dx.rop.cst.Constant) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList)

Example 9 with CstLiteralBits

use of com.taobao.android.dx.rop.cst.CstLiteralBits in project atlas by alibaba.

the class Form31i method insnArgString.

/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();
    return regs.get(0).regString() + ", " + literalBitsString(value);
}
Also used : CstLiteralBits(com.taobao.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList)

Example 10 with CstLiteralBits

use of com.taobao.android.dx.rop.cst.CstLiteralBits in project atlas by alibaba.

the class EscapeAnalysis method scalarReplacement.

/**
     * Performs scalar replacement on all eligible arrays.
     */
private void scalarReplacement() {
    // Iterate through lattice, looking for non-escaping replaceable arrays
    for (EscapeSet escSet : latticeValues) {
        if (!escSet.replaceableArray || escSet.escape != EscapeState.NONE) {
            continue;
        }
        // Get the instructions for the definition and move of the array
        int e = escSet.regSet.nextSetBit(0);
        SsaInsn def = ssaMeth.getDefinitionForRegister(e);
        SsaInsn prev = getInsnForMove(def);
        // Create a map for the new registers that will be created
        TypeBearer lengthReg = prev.getSources().get(0).getTypeBearer();
        int length = ((CstLiteralBits) lengthReg).getIntBits();
        ArrayList<RegisterSpec> newRegs = new ArrayList<RegisterSpec>(length);
        HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>();
        // Replace the definition of the array with registers
        replaceDef(def, prev, length, newRegs);
        // Mark definition instructions for deletion
        deletedInsns.add(prev);
        deletedInsns.add(def);
        // Go through all uses of the array
        List<SsaInsn> useList = ssaMeth.getUseListForRegister(e);
        for (SsaInsn use : useList) {
            // Replace the use with scalars and then mark it for deletion
            replaceUse(use, prev, newRegs, deletedInsns);
            deletedInsns.add(use);
        }
        // Delete all marked instructions
        ssaMeth.deleteInsns(deletedInsns);
        ssaMeth.onInsnsChanged();
        // Convert the method back to SSA form
        SsaConverter.updateSsaMethod(optimizer, ssaMeth, regCount);
        // Propagate and remove extra moves added by scalar replacement
        movePropagate();
    }
}
Also used : CstLiteralBits(com.taobao.android.dx.rop.cst.CstLiteralBits) ArrayList(java.util.ArrayList) TypeBearer(com.taobao.android.dx.rop.type.TypeBearer) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec) HashSet(java.util.HashSet)

Aggregations

CstLiteralBits (com.taobao.android.dx.rop.cst.CstLiteralBits)24 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)21 Constant (com.taobao.android.dx.rop.cst.Constant)9 CstInsn (com.taobao.android.dx.dex.code.CstInsn)6 ArrayList (java.util.ArrayList)3 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)2 TypeBearer (com.taobao.android.dx.rop.type.TypeBearer)2 FillArrayDataInsn (com.taobao.android.dx.rop.code.FillArrayDataInsn)1 Insn (com.taobao.android.dx.rop.code.Insn)1 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)1 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)1 ThrowingCstInsn (com.taobao.android.dx.rop.code.ThrowingCstInsn)1 ThrowingInsn (com.taobao.android.dx.rop.code.ThrowingInsn)1 CstArray (com.taobao.android.dx.rop.cst.CstArray)1 CstInteger (com.taobao.android.dx.rop.cst.CstInteger)1 CstType (com.taobao.android.dx.rop.cst.CstType)1 TypedConstant (com.taobao.android.dx.rop.cst.TypedConstant)1 HashSet (java.util.HashSet)1