Methods Summary |
---|
private static boolean | hasSideEffect(SsaInsn insn)Returns true if this insn has a side-effect. Returns true
if the insn is null for reasons stated in the code block.
if (insn == null) {
/* while false would seem to make more sense here, true
* prevents us from adding this back to a worklist unnecessarally
*/
return true;
}
return insn.hasSideEffect();
|
private boolean | isCircularNoSideEffect(int regV, java.util.BitSet set)Returns true if the only uses of this register form a circle of
operations with no side effects
if ((set != null) && set.get(regV)) {
return true;
}
for (SsaInsn use: useList[regV]) {
if (hasSideEffect(use)) {
return false;
}
}
if (set == null) {
set = new BitSet(regCount);
}
// This register is only used in operations that have no side effect.
set.set(regV);
for (SsaInsn use: useList[regV]) {
RegisterSpec result = use.getResult();
if (result == null
|| !isCircularNoSideEffect(result.getReg(), set)) {
return false;
}
}
return true;
|
public static void | process(SsaMethod ssaMethod)Process a method with the dead-code remver
DeadCodeRemover dc;
dc = new DeadCodeRemover(ssaMethod);
dc.run();
|
private void | run()Run the dead code remover
HashSet<SsaInsn> deletedInsns = (HashSet<SsaInsn>) new HashSet();
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 who's 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);
|