diff --git a/src/edu/purdue/cs/bloat/trans/Peephole.java b/src/edu/purdue/cs/bloat/trans/Peephole.java index c1be0a6..129f82d 100644 --- a/src/edu/purdue/cs/bloat/trans/Peephole.java +++ b/src/edu/purdue/cs/bloat/trans/Peephole.java @@ -54,9 +54,10 @@ import java.util.*; */ public class Peephole implements Optimization { + public static boolean DEBUG = false; - public String traceMessage(String dateString) { + public String traceMessage(String dateString) { return null; } @@ -447,74 +448,75 @@ public class Peephole implements Optimization { blockIter = blockIter.getNext(); Instruction inst = blockIter.getInstruction(); - if (!FlowGraph.label(blockIter)) { - if (inst instanceof ReturnInstruction - || inst instanceof ATHROW) { - // We've reached the end of the block, but we don't know - // which block will be executed next. - break; + // BCEL - BLOAT means jumps can also be Labels. + if (FlowGraph.label(blockIter)) { + label = blockIter; + visited.add(label); + } - } else if (inst instanceof IfInstruction - || inst instanceof JsrInstruction) { - // We've reached the end of the block, add the Label of - // the next block to be executed to the list. It's a - // conditional jump, so don't break. The rest of the - // code in the block is not necessarily dead. + if (inst instanceof ReturnInstruction || inst instanceof ATHROW) { + // We've reached the end of the block, but we don't know + // which block will be executed next. + break; - label = ((BranchInstruction) inst).getTarget(); + } else if (inst instanceof IfInstruction + || inst instanceof JsrInstruction) { + // We've reached the end of the block, add the Label of + // the next block to be executed to the list. It's a + // conditional jump, so don't break. The rest of the + // code in the block is not necessarily dead. - if (!visited.contains(label)) { - visited.add(label); - stack.push(label); - } + label = ((BranchInstruction) inst).getTarget(); - // Fall through. + if (!visited.contains(label)) { + visited.add(label); + stack.push(label); + } - } else if (inst instanceof GotoInstruction) { - // Add next block to work list. + // Fall through. - label = ((GotoInstruction) inst).getTarget(); + } else if (inst instanceof GotoInstruction) { + // Add next block to work list. - if (!visited.contains(label)) { - visited.add(label); - stack.push(label); - } + label = ((GotoInstruction) inst).getTarget(); - break; + if (!visited.contains(label)) { + visited.add(label); + stack.push(label); + } - } else if (inst instanceof RET) { - // The ret targets were handled by the jsr. - break; + break; - } else if (inst instanceof Select) { - // A switch. Add all possible targets of the switch to - // the worklist. + } else if (inst instanceof RET) { + // The ret targets were handled by the jsr. + break; - Select sw = (Select) inst; + } else if (inst instanceof Select) { + // A switch. Add all possible targets of the switch to + // the worklist. - label = sw.getTarget(); - if (!visited.contains(label)) { - visited.add(label); - stack.push(label); - } + Select sw = (Select) inst; - InstructionHandle[] targets = sw.getTargets(); + label = sw.getTarget(); + if (!visited.contains(label)) { + visited.add(label); + stack.push(label); + } - for (int j = 0; j < targets.length; j++) { - label = targets[j]; + InstructionHandle[] targets = sw.getTargets(); - if (!visited.contains(label)) { - visited.add(label); - stack.push(label); - } - } + for (int j = 0; j < targets.length; j++) { + label = targets[j]; - break; + if (!visited.contains(label)) { + visited.add(label); + stack.push(label); + } } - } else if (FlowGraph.label(blockIter)) { - label = blockIter; - visited.add(label); + + break; } + } } if (DEBUG) { @@ -538,7 +540,12 @@ public class Peephole implements Optimization { if (Peephole.DEBUG) { System.out.println("Removing unreachable " + ce); } - iter.remove(); + try { + code.delete(ce); + } catch (TargetLostException lte) { + // do nothing if this is dead code there shouldn't be a + // targeter. + } } } }