use of com.android.dx.rop.code.RegisterSpecList 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.RegisterSpecList 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.RegisterSpecList in project buck by facebook.
the class NormalSsaInsn method setNewSources.
/**
* Changes the source list of the insn. New source list should be the
* same size and consist of sources of identical types.
*
* @param newSources non-null new sources list.
*/
public final void setNewSources(RegisterSpecList newSources) {
RegisterSpecList origSources = insn.getSources();
if (origSources.size() != newSources.size()) {
throw new RuntimeException("Sources counts don't match");
}
insn = insn.withNewRegisters(getResult(), newSources);
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class NormalSsaInsn method mapSourceRegisters.
/** {@inheritDoc} */
@Override
public final void mapSourceRegisters(RegisterMapper mapper) {
RegisterSpecList oldSources = insn.getSources();
RegisterSpecList newSources = mapper.map(oldSources);
if (newSources != oldSources) {
insn = insn.withNewRegisters(getResult(), newSources);
getBlock().getParent().onSourcesChanged(this, oldSources);
}
}
use of com.android.dx.rop.code.RegisterSpecList in project buck by facebook.
the class PhiInsn method getSources.
/**
* Gets sources. Constructed lazily from phi operand data structures and
* then cached.
*
* @return {@code non-null;} sources list
*/
@Override
public RegisterSpecList getSources() {
if (sources != null) {
return sources;
}
if (operands.size() == 0) {
// How'd this happen? A phi insn with no operand?
return RegisterSpecList.EMPTY;
}
int szSources = operands.size();
sources = new RegisterSpecList(szSources);
for (int i = 0; i < szSources; i++) {
Operand o = operands.get(i);
sources.set(i, o.regSpec);
}
sources.setImmutable();
return sources;
}
Aggregations