use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class DeadCodeRemover method run.
/**
* Runs the dead code remover.
*/
private void run() {
pruneDeadInstructions();
HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>();
ssaMeth.forEachInsn(new NoSideEffectVisitor(worklist));
int regV;
while (0 <= (regV = worklist.nextSetBit(0))) {
worklist.clear(regV);
if (useList[regV].size() == 0 || isCircularNoSideEffect(regV, null)) {
SsaInsn insnS = ssaMeth.getDefinitionForRegister(regV);
// This insn has already been deleted.
if (deletedInsns.contains(insnS)) {
continue;
}
RegisterSpecList sources = insnS.getSources();
int sz = sources.size();
for (int i = 0; i < sz; i++) {
// Delete this insn from all usage lists.
RegisterSpec source = sources.get(i);
useList[source.getReg()].remove(insnS);
if (!hasSideEffect(ssaMeth.getDefinitionForRegister(source.getReg()))) {
/*
* Only registers whose definition has no side effect
* should be added back to the worklist.
*/
worklist.set(source.getReg());
}
}
// Schedule this insn for later deletion.
deletedInsns.add(insnS);
}
}
ssaMeth.deleteInsns(deletedInsns);
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class DeadCodeRemover method pruneDeadInstructions.
/**
* Removes all instructions from every unreachable block.
*/
private void pruneDeadInstructions() {
HashSet<SsaInsn> deletedInsns = new HashSet<SsaInsn>();
ssaMeth.computeReachability();
for (SsaBasicBlock block : ssaMeth.getBlocks()) {
if (block.isReachable())
continue;
// Prune instructions from unreachable blocks
for (int i = 0; i < block.getInsns().size(); i++) {
SsaInsn insn = block.getInsns().get(i);
RegisterSpecList sources = insn.getSources();
int sourcesSize = sources.size();
// Delete this instruction completely if it has sources
if (sourcesSize != 0) {
deletedInsns.add(insn);
}
// Delete this instruction from all usage lists.
for (int j = 0; j < sourcesSize; j++) {
RegisterSpec source = sources.get(j);
useList[source.getReg()].remove(insn);
}
// Remove this instruction result from the sources of any phis
RegisterSpec result = insn.getResult();
if (result == null)
continue;
for (SsaInsn use : useList[result.getReg()]) {
if (use instanceof PhiInsn) {
PhiInsn phiUse = (PhiInsn) use;
phiUse.removePhiRegister(result);
}
}
}
}
ssaMeth.deleteInsns(deletedInsns);
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class NormalSsaInsn method changeOneSource.
/**
* 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);
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class PhiInsn method toHumanWithInline.
/**
* Returns human-readable string for listing dumps. This method
* allows sub-classes to specify extra text.
*
* @param extra {@code null-ok;} the argument to print after the opcode
* @return human-readable string for listing dumps
*/
protected final String toHumanWithInline(String extra) {
StringBuffer sb = new StringBuffer(80);
sb.append(SourcePosition.NO_INFO);
sb.append(": phi");
if (extra != null) {
sb.append("(");
sb.append(extra);
sb.append(")");
}
RegisterSpec result = getResult();
if (result == null) {
sb.append(" .");
} else {
sb.append(" ");
sb.append(result.toHuman());
}
sb.append(" <-");
int sz = getSources().size();
if (sz == 0) {
sb.append(" .");
} else {
for (int i = 0; i < sz; i++) {
sb.append(" ");
sb.append(sources.get(i).toHuman() + "[b=" + Hex.u2(operands.get(i).ropLabel) + "]");
}
}
return sb.toString();
}
use of com.android.dx.rop.code.RegisterSpec in project buck by facebook.
the class PhiInsn method mapSourceRegisters.
/** {@inheritDoc} */
@Override
public final void mapSourceRegisters(RegisterMapper mapper) {
for (Operand o : operands) {
RegisterSpec old = o.regSpec;
o.regSpec = mapper.map(old);
if (old != o.regSpec) {
getBlock().getParent().onSourceChanged(this, old, o.regSpec);
}
}
sources = null;
}
Aggregations