Search in sources :

Example 1 with LocalItem

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

the class SsaRenamer method setNameForSsaReg.

/**
     * Records a debug (local variable) name for a specified register.
     *
     * @param ssaReg non-null named register spec in SSA name space
     */
private void setNameForSsaReg(RegisterSpec ssaReg) {
    int reg = ssaReg.getReg();
    LocalItem local = ssaReg.getLocalItem();
    ssaRegToLocalItems.ensureCapacity(reg + 1);
    while (ssaRegToLocalItems.size() <= reg) {
        ssaRegToLocalItems.add(null);
    }
    ssaRegToLocalItems.set(reg, local);
}
Also used : LocalItem(com.taobao.android.dx.rop.code.LocalItem)

Example 2 with LocalItem

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

the class FirstFitLocalCombiningAllocator method printLocalVars.

/**
     * Dumps local variable table to stdout for debugging.
     */
private void printLocalVars() {
    System.out.println("Printing local vars");
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> e : localVariables.entrySet()) {
        StringBuilder regs = new StringBuilder();
        regs.append('{');
        regs.append(' ');
        for (RegisterSpec reg : e.getValue()) {
            regs.append('v');
            regs.append(reg.getReg());
            regs.append(' ');
        }
        regs.append('}');
        System.out.printf("Local: %s Registers: %s\n", e.getKey(), regs);
    }
}
Also used : ArrayList(java.util.ArrayList) LocalItem(com.taobao.android.dx.rop.code.LocalItem) TreeMap(java.util.TreeMap) Map(java.util.Map) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 3 with LocalItem

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

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

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

the class ConstCollector method fixLocalAssignment.

/**
     * Inserts mark-locals if necessary when changing a register. If
     * the definition of {@code origReg} is associated with a local
     * variable, then insert a mark-local for {@code newReg} just below
     * it. We expect the definition of  {@code origReg} to ultimately
     * be removed by the dead code eliminator
     *
     * @param origReg {@code non-null;} original register
     * @param newReg {@code non-null;} new register that will replace
     * {@code origReg}
     */
private void fixLocalAssignment(RegisterSpec origReg, RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }
        if (use.getResult() == null) {
            /*
                 * This is a mark-local. it will be updated when all uses
                 * are updated.
                 */
            continue;
        }
        LocalItem local = localAssignment.getLocalItem();
        // Un-associate original use.
        use.setResultLocal(null);
        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);
        SsaInsn newInsn = SsaInsn.makeFromRop(new PlainInsn(Rops.opMarkLocal(newReg), SourcePosition.NO_INFO, null, RegisterSpecList.make(newReg)), use.getBlock());
        ArrayList<SsaInsn> insns = use.getBlock().getInsns();
        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
Also used : PlainInsn(com.taobao.android.dx.rop.code.PlainInsn) LocalItem(com.taobao.android.dx.rop.code.LocalItem) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Aggregations

LocalItem (com.taobao.android.dx.rop.code.LocalItem)7 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)5 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)2 Type (com.taobao.android.dx.rop.type.Type)2 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)1 CstString (com.taobao.android.dx.rop.cst.CstString)1 CstType (com.taobao.android.dx.rop.cst.CstType)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1