use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class Form22s method isCompatible.
/** {@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;
Constant cst = ci.getConstant();
if (!(cst instanceof CstLiteralBits)) {
return false;
}
CstLiteralBits cb = (CstLiteralBits) cst;
return cb.fitsInInt() && signedFitsInShort(cb.getIntBits());
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class Form22t method compatibleRegs.
/** {@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;
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class DalvInsn method expandedPrefix.
/**
* Gets the instruction prefix required, if any, to use in an expanded
* version of this instance. Will not generate moves for registers
* marked compatible to the format by the given BitSet.
*
* @see #expandedVersion
*
* @param compatRegs {@code non-null;} set of compatible registers
* @return {@code null-ok;} the prefix, if any
*/
public DalvInsn expandedPrefix(BitSet compatRegs) {
RegisterSpecList regs = registers;
boolean firstBit = compatRegs.get(0);
if (hasResult())
compatRegs.set(0);
regs = regs.subset(compatRegs);
if (hasResult())
compatRegs.set(0, firstBit);
if (regs.size() == 0)
return null;
return new HighRegisterPrefix(position, regs);
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class Ropper method addReturnBlock.
/**
* Constructs and adds the return block, if necessary. The return
* block merely contains an appropriate {@code return}
* instruction.
*/
private void addReturnBlock() {
Rop returnOp = machine.getReturnOp();
if (returnOp == null) {
/*
* The method being converted never returns normally, so there's
* no need for a return block.
*/
return;
}
SourcePosition returnPos = machine.getReturnPosition();
int label = getSpecialLabel(RETURN);
if (isSynchronized()) {
InsnList insns = new InsnList(1);
Insn insn = new ThrowingInsn(Rops.MONITOR_EXIT, returnPos, RegisterSpecList.make(getSynchReg()), StdTypeList.EMPTY);
insns.set(0, insn);
insns.setImmutable();
int nextLabel = getSpecialLabel(SYNCH_RETURN);
BasicBlock bb = new BasicBlock(label, insns, IntList.makeImmutable(nextLabel), nextLabel);
addBlock(bb, IntList.EMPTY);
label = nextLabel;
}
InsnList insns = new InsnList(1);
TypeList sourceTypes = returnOp.getSources();
RegisterSpecList sources;
if (sourceTypes.size() == 0) {
sources = RegisterSpecList.EMPTY;
} else {
RegisterSpec source = RegisterSpec.make(0, sourceTypes.getType(0));
sources = RegisterSpecList.make(source);
}
Insn insn = new PlainInsn(returnOp, returnPos, null, sources);
insns.set(0, insn);
insns.setImmutable();
BasicBlock bb = new BasicBlock(label, insns, IntList.EMPTY, -1);
addBlock(bb, IntList.EMPTY);
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
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;
}
Aggregations