com.android.dx.rop.code.RegisterSpecList Java Examples

The following examples show how to use com.android.dx.rop.code.RegisterSpecList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RopTranslator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the complete register list (result and sources) out of a
 * given rop instruction. For insns that are commutative, have
 * two register sources, and have a source equal to the result,
 * place that source first.
 *
 * @param insn {@code non-null;} instruction in question
 * @param resultReg {@code null-ok;} the real result to use (ignore the insn's)
 * @return {@code non-null;} the instruction's complete register list
 */
private static RegisterSpecList getRegs(Insn insn,
        RegisterSpec resultReg) {
    RegisterSpecList regs = insn.getSources();

    if (insn.getOpcode().isCommutative()
            && (regs.size() == 2)
            && (resultReg.getReg() == regs.get(1).getReg())) {

        /*
         * For commutative ops which have two register sources,
         * if the second source is the same register as the result,
         * swap the sources so that an opcode of form 12x can be selected
         * instead of one of form 23x
         */

        regs = RegisterSpecList.make(regs.get(1), regs.get(0));
    }

    if (resultReg == null) {
        return regs;
    }

    return regs.withFirst(resultReg);
}
 
Example #2
Source File: InsnFormat.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to return a register list string.
 *
 * @param list {@code non-null;} the list of registers
 * @return {@code non-null;} the string form
 */
protected static String regListString(RegisterSpecList list) {
    int sz = list.size();
    StringBuilder sb = new StringBuilder(sz * 5 + 2);

    sb.append('{');

    for (int i = 0; i < sz; i++) {
        if (i != 0) {
            sb.append(", ");
        }
        sb.append(list.get(i).regString());
    }

    sb.append('}');

    return sb.toString();
}
 
Example #3
Source File: HighRegisterPrefix.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected String listingString0(boolean noteIndices) {
    RegisterSpecList registers = getRegisters();
    int sz = registers.size();
    StringBuilder sb = new StringBuilder(100);

    for (int i = 0, outAt = 0; i < sz; i++) {
        RegisterSpec src = registers.get(i);
        SimpleInsn insn = moveInsnFor(src, outAt);

        if (i != 0) {
            sb.append('\n');
        }

        sb.append(insn.listingString0(noteIndices));

        outAt += src.getCategory();
    }

    return sb.toString();
}
 
Example #4
Source File: SsaMethod.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the use list for a source list change.
 *
 * @param insn {@code insn non-null;} insn being changed.
 * {@code insn.getSources()} must return the new source list.
 * @param oldSources {@code null-ok;} list of sources that were
 * previously used
 */
/*package*/ void onSourcesChanged(SsaInsn insn,
        RegisterSpecList oldSources) {
    if (useList == null) return;

    if (oldSources != null) {
        removeFromUseList(insn, oldSources);
    }

    RegisterSpecList sources = insn.getSources();
    int szNew = sources.size();

    for (int i = 0; i < szNew; i++) {
        int reg = sources.get(i).getReg();
        useList[reg].add(insn);
    }
}
 
Example #5
Source File: Form12x.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();

    /*
     * The (sz - 2) and (sz - 1) below makes this code work for
     * both the two- and three-register ops. (See "case 3" in
     * isCompatible(), above.)
     */

    write(out, opcodeUnit(insn,
                          makeByte(regs.get(sz - 2).getReg(),
                                   regs.get(sz - 1).getReg())));
}
 
Example #6
Source File: NormalSsaInsn.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Changes one of the insn's sources. New source should be of same type
 * and category.
 *
 * @param index {@code >=0;} index of source to change
 * @param newSpec spec for new source
 */
public final void changeOneSource(int index, RegisterSpec newSpec) {
    RegisterSpecList origSources = insn.getSources();
    int sz = origSources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);

    for (int i = 0; i < sz; i++) {
        newSources.set(i, i == index ? newSpec : origSources.get(i));
    }

    newSources.setImmutable();

    RegisterSpec origSpec = origSources.get(index);
    if (origSpec.getReg() != newSpec.getReg()) {
        /*
         * If the register remains unchanged, we're only changing
         * the type or local var name so don't update use list
         */
        getBlock().getParent().onSourceChanged(this, origSpec, newSpec);
    }

    insn = insn.withNewRegisters(getResult(), newSources);
}
 
Example #7
Source File: EscapeAnalysis.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the instructions that define an array with equivalent registers.
 * For each entry in the array, a register is created, initialized to zero.
 * A mapping between this register and the corresponding array index is
 * added.
 *
 * @param def {@code non-null;} move result instruction for array
 * @param prev {@code non-null;} instruction for instantiating new array
 * @param length size of the new array
 * @param newRegs {@code non-null;} mapping of array indices to new
 * registers to be populated
 */
private void replaceDef(SsaInsn def, SsaInsn prev, int length,
                            ArrayList<RegisterSpec> newRegs) {
    Type resultType = def.getResult().getType();

    // Create new zeroed out registers for each element in the array
    for (int i = 0; i < length; i++) {
        Constant newZero = Zeroes.zeroFor(resultType.getComponentType());
        TypedConstant typedZero = (TypedConstant) newZero;
        RegisterSpec newReg =
            RegisterSpec.make(ssaMeth.makeNewSsaReg(), typedZero);
        newRegs.add(newReg);
        insertPlainInsnBefore(def, RegisterSpecList.EMPTY, newReg,
                                  RegOps.CONST, newZero);
    }
}
 
Example #8
Source File: Form35c.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);

    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        bits.set(i, unsignedFitsInNibble(reg.getReg() +
                                         reg.getCategory() - 1));
    }

    return bits;
}
 
Example #9
Source File: RopTranslator.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitInvokePolymorphicInsn(InvokePolymorphicInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_THROW) {
        throw new RuntimeException("Expected BRANCH_THROW got " + rop.getBranchingness());
    } else if (!rop.isCallLike()) {
        throw new RuntimeException("Expected call-like operation");
    }

    addOutput(lastAddress);

    RegisterSpecList regs = insn.getSources();
    Constant[] constants = new Constant[] {
        insn.getPolymorphicMethod(),
        insn.getCallSiteProto()
        };
    DalvInsn di = new MultiCstInsn(opcode, pos, regs, constants);

    addOutput(di);
}
 
Example #10
Source File: Form31c.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);
    boolean compat = unsignedFitsInByte(regs.get(0).getReg());

    if (sz == 1) {
        bits.set(0, compat);
    } else {
        if (regs.get(0).getReg() == regs.get(1).getReg()) {
            bits.set(0, compat);
            bits.set(1, compat);
        }
    }

    return bits;
}
 
Example #11
Source File: CstInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public DalvInsn withRegisters(RegisterSpecList registers) {
    CstInsn result =
        new CstInsn(getOpcode(), getPosition(), registers, constant);

    if (index >= 0) {
        result.setIndex(index);
    }

    if (classIndex >= 0) {
        result.setClassIndex(classIndex);
    }

    return result;
}
 
Example #12
Source File: Form22c.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example #13
Source File: Form22c.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(2);

    bits.set(0, unsignedFitsInNibble(regs.get(0).getReg()));
    bits.set(1, unsignedFitsInNibble(regs.get(1).getReg()));
    return bits;
}
 
Example #14
Source File: Form22b.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(2);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    bits.set(1, unsignedFitsInByte(regs.get(1).getReg()));
    return bits;
}
 
Example #15
Source File: Form21c.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int cpi = ((CstInsn) insn).getIndex();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) cpi);
}
 
Example #16
Source File: Form51l.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();

    return regs.get(0).regString() + ", " + literalBitsString(value);
}
 
Example #17
Source File: Form11n.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();

    return regs.get(0).regString() + ", " + literalBitsString(value);
}
 
Example #18
Source File: SsaBasicBlock.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a move instruction after the phi insn block.
 *
 * @param result move destination
 * @param source move source
 */
public void addMoveToBeginning (RegisterSpec result, RegisterSpec source) {
    if (result.getReg() == source.getReg()) {
        // Sometimes we end up with no-op moves. Ignore them here.
        return;
    }

    RegisterSpecList sources = RegisterSpecList.make(source);
    NormalSsaInsn toAdd = new NormalSsaInsn(
            new PlainInsn(Rops.opMove(result.getType()),
                    SourcePosition.NO_INFO, result, sources), this);

    insns.add(getCountPhiInsns(), toAdd);
    movesFromPhisAtBeginning++;
}
 
Example #19
Source File: Form22t.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    return regs.get(0).regString() + ", " + regs.get(1).regString() +
        ", " + branchString(insn);
}
 
Example #20
Source File: Form22t.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int offset = ((TargetInsn) insn).getTargetOffset();

    write(out,
          opcodeUnit(insn,
                     makeByte(regs.get(0).getReg(), regs.get(1).getReg())),
          (short) offset);
}
 
Example #21
Source File: Form21c.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int cpi = ((CstInsn) insn).getIndex();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) cpi);
}
 
Example #22
Source File: CstInsn.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. The output address of this instance is
 * initially unknown ({@code -1}) as is the constant pool index.
 *
 * @param opcode the opcode; one of the constants from {@link Dops}
 * @param position {@code non-null;} source position
 * @param registers {@code non-null;} register list, including a
 * result register if appropriate (that is, registers may be either
 * ins or outs)
 * @param constant {@code non-null;} constant argument
 */
public CstInsn(Dop opcode, SourcePosition position,
               RegisterSpecList registers, Constant constant) {
    super(opcode, position, registers);

    if (constant == null) {
        throw new NullPointerException("constant == null");
    }

    this.constant = constant;
    this.index = -1;
    this.classIndex = -1;
}
 
Example #23
Source File: RegisterMapper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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;
}
 
Example #24
Source File: RegisterMapper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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;
}
 
Example #25
Source File: Form21h.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #26
Source File: Form31i.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value =
        ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();

    write(out, opcodeUnit(insn, regs.get(0).getReg()), value);
}
 
Example #27
Source File: Form31t.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    if (!((insn instanceof TargetInsn) &&
          (regs.size() == 1) &&
          unsignedFitsInByte(regs.get(0).getReg()))) {
        return false;
    }

    return true;
}
 
Example #28
Source File: Form32x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    write(out,
          opcodeUnit(insn, 0),
          (short) regs.get(0).getReg(),
          (short) regs.get(1).getReg());
}
 
Example #29
Source File: Form21s.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value =
        ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) value);
}
 
Example #30
Source File: Form23x.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    return regs.get(0).regString() + ", " + regs.get(1).regString() +
        ", " + regs.get(2).regString();
}