Search in sources :

Example 71 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList in project J2ME-Loader by nikita36078.

the class RegisterAllocator method insertMoveBefore.

/**
 * Inserts a move instruction for a specified SSA register before a
 * specified instruction, creating a new SSA register and adjusting the
 * interference graph in the process. The insn currently must be the
 * last insn in a block.
 *
 * @param insn {@code non-null;} insn to insert move before, must
 * be last insn in block
 * @param reg {@code non-null;} SSA register to duplicate
 * @return {@code non-null;} spec of new SSA register created by move
 */
protected final RegisterSpec insertMoveBefore(SsaInsn insn, RegisterSpec reg) {
    SsaBasicBlock block = insn.getBlock();
    ArrayList<SsaInsn> insns = block.getInsns();
    int insnIndex = insns.indexOf(insn);
    if (insnIndex < 0) {
        throw new IllegalArgumentException("specified insn is not in this block");
    }
    if (insnIndex != insns.size() - 1) {
        /*
             * Presently, the interference updater only works when
             * adding before the last insn, and the last insn must have no
             * result
             */
        throw new IllegalArgumentException("Adding move here not supported:" + insn.toHuman());
    }
    /*
         * Get new register and make new move instruction.
         */
    // The new result must not have an associated local variable.
    RegisterSpec newRegSpec = RegisterSpec.make(ssaMeth.makeNewSsaReg(), reg.getTypeBearer());
    SsaInsn toAdd = SsaInsn.makeFromRop(new PlainInsn(Rops.opMove(newRegSpec.getType()), SourcePosition.NO_INFO, newRegSpec, RegisterSpecList.make(reg)), block);
    insns.add(insnIndex, toAdd);
    int newReg = newRegSpec.getReg();
    /*
         * Adjust interference graph based on what's live out of the current
         * block and what's used by the final instruction.
         */
    IntSet liveOut = block.getLiveOutRegs();
    IntIterator liveOutIter = liveOut.iterator();
    while (liveOutIter.hasNext()) {
        interference.add(newReg, liveOutIter.next());
    }
    // Everything that's a source in the last insn interferes.
    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    for (int i = 0; i < szSources; i++) {
        interference.add(newReg, sources.get(i).getReg());
    }
    ssaMeth.onInsnsChanged();
    return newRegSpec;
}
Also used : PlainInsn(com.android.dx.rop.code.PlainInsn) IntIterator(com.android.dx.util.IntIterator) IntSet(com.android.dx.util.IntSet) SsaBasicBlock(com.android.dx.ssa.SsaBasicBlock) NormalSsaInsn(com.android.dx.ssa.NormalSsaInsn) SsaInsn(com.android.dx.ssa.SsaInsn) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 72 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList in project J2ME-Loader by nikita36078.

the class OutputFinisher method align64bits.

private void align64bits(Dop[] opcodes) {
    while (true) {
        int notAligned64bitRegAccess = 0;
        int aligned64bitRegAccess = 0;
        int notAligned64bitParamAccess = 0;
        int aligned64bitParamAccess = 0;
        int lastParameter = unreservedRegCount + reservedCount + reservedParameterCount;
        int firstParameter = lastParameter - paramSize;
        // Collects the number of time that 64-bit registers are accessed aligned or not.
        for (DalvInsn insn : insns) {
            RegisterSpecList regs = insn.getRegisters();
            for (int usedRegIdx = 0; usedRegIdx < regs.size(); usedRegIdx++) {
                RegisterSpec reg = regs.get(usedRegIdx);
                if (reg.isCategory2()) {
                    boolean isParameter = reg.getReg() >= firstParameter;
                    if (reg.isEvenRegister()) {
                        if (isParameter) {
                            aligned64bitParamAccess++;
                        } else {
                            aligned64bitRegAccess++;
                        }
                    } else {
                        if (isParameter) {
                            notAligned64bitParamAccess++;
                        } else {
                            notAligned64bitRegAccess++;
                        }
                    }
                }
            }
        }
        if (notAligned64bitParamAccess > aligned64bitParamAccess && notAligned64bitRegAccess > aligned64bitRegAccess) {
            addReservedRegisters(1);
        } else if (notAligned64bitParamAccess > aligned64bitParamAccess) {
            addReservedParameters(1);
        } else if (notAligned64bitRegAccess > aligned64bitRegAccess) {
            addReservedRegisters(1);
            // so the number of aligned become the number of unaligned.
            if (paramSize != 0 && aligned64bitParamAccess > notAligned64bitParamAccess) {
                addReservedParameters(1);
            }
        } else {
            break;
        }
        if (!reserveRegisters(opcodes)) {
            break;
        }
    }
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 73 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList in project J2ME-Loader by nikita36078.

the class Form11n method writeTo.

/**
 * {@inheritDoc}
 */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value = ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();
    write(out, opcodeUnit(insn, makeByte(regs.get(0).getReg(), value & 0xf)));
}
Also used : CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 74 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList in project J2ME-Loader by nikita36078.

the class Form11n method compatibleRegs.

/**
 * {@inheritDoc}
 */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);
    bits.set(0, unsignedFitsInNibble(regs.get(0).getReg()));
    return bits;
}
Also used : BitSet(java.util.BitSet) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 75 with RegisterSpecList

use of com.android.dx.rop.code.RegisterSpecList in project J2ME-Loader by nikita36078.

the class Form11n 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.android.dx.rop.cst.CstLiteralBits) 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