use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class FirstFitLocalCombiningAllocator method tryMapRegs.
/**
* Tries to map a list of SSA registers into the a rop reg, marking
* used rop space as reserved. SSA registers that don't fit are left
* unmapped.
*
* @param specs {@code non-null;} SSA registers to attempt to map
* @param ropReg {@code >=0;} rop register to map to
* @param maxAllowedCategory {@code 1..2;} maximum category
* allowed in mapping.
* @param markReserved do so if {@code true}
* @return {@code true} if all registers were mapped, {@code false}
* if some remain unmapped
*/
private boolean tryMapRegs(ArrayList<RegisterSpec> specs, int ropReg, int maxAllowedCategory, boolean markReserved) {
boolean remaining = false;
for (RegisterSpec spec : specs) {
if (ssaRegsMapped.get(spec.getReg())) {
continue;
}
boolean succeeded;
succeeded = tryMapReg(spec, ropReg, maxAllowedCategory);
remaining = !succeeded || remaining;
if (succeeded && markReserved) {
// This only needs to be called once really with
// the widest category used, but <shrug>
markReserved(ropReg, spec.getCategory());
}
}
return !remaining;
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class LivenessAnalyzer method liveOutAtStatement.
/**
* "v is live-out at s."
*/
private void liveOutAtStatement() {
SsaInsn statement = blockN.getInsns().get(statementIndex);
RegisterSpec rs = statement.getResult();
if (!statement.isResultReg(regV)) {
if (rs != null) {
interference.add(regV, rs.getReg());
}
nextFunction = NextFunction.LIVE_IN_AT_STATEMENT;
}
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class SsaInsn method mapRegisters.
/**
* Map registers after register allocation.
*
* @param mapper {@code non-null;} mapping from old to new registers
*/
public final void mapRegisters(RegisterMapper mapper) {
RegisterSpec oldResult = result;
result = mapper.map(result);
block.getParent().updateOneDefinition(this, oldResult);
mapSourceRegisters(mapper);
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
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);
}
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class ConstCollector method run.
/**
* Applies the optimization.
*/
private void run() {
int regSz = ssaMeth.getRegCount();
ArrayList<TypedConstant> constantList = getConstsSortedByCountUse();
int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS);
SsaBasicBlock start = ssaMeth.getEntryBlock();
// Constant to new register containing the constant
HashMap<TypedConstant, RegisterSpec> newRegs = new HashMap<TypedConstant, RegisterSpec>(toCollect);
for (int i = 0; i < toCollect; i++) {
TypedConstant cst = constantList.get(i);
RegisterSpec result = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst);
Rop constRop = Rops.opConst(cst);
if (constRop.getBranchingness() == Rop.BRANCH_NONE) {
start.addInsnToHead(new PlainCstInsn(Rops.opConst(cst), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY, cst));
} else {
// We need two new basic blocks along with the new insn
SsaBasicBlock entryBlock = ssaMeth.getEntryBlock();
SsaBasicBlock successorBlock = entryBlock.getPrimarySuccessor();
// Insert a block containing the const insn.
SsaBasicBlock constBlock = entryBlock.insertNewSuccessor(successorBlock);
constBlock.replaceLastInsn(new ThrowingCstInsn(constRop, SourcePosition.NO_INFO, RegisterSpecList.EMPTY, StdTypeList.EMPTY, cst));
// Insert a block containing the move-result-pseudo insn.
SsaBasicBlock resultBlock = constBlock.insertNewSuccessor(successorBlock);
PlainInsn insn = new PlainInsn(Rops.opMoveResultPseudo(result.getTypeBearer()), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY);
resultBlock.addInsnToHead(insn);
}
newRegs.put(cst, result);
}
updateConstUses(newRegs, regSz);
}
Aggregations