private void optimize() { // SSS FIXME: Can't we not add some of these exception edges in the first place?? // Remove exception edges from blocks that couldn't possibly thrown an exception! List<Edge> toRemove = new ArrayList<Edge>(); for (BasicBlock b : graph.allData()) { boolean noExceptions = true; for (Instr i : b.getInstrs()) { if (i.canRaiseException()) { noExceptions = false; break; } } if (noExceptions) { for (Edge<BasicBlock> e : graph.vertexFor(b).getOutgoingEdgesOfType(EdgeType.EXCEPTION)) { BasicBlock source = e.getSource().getData(); BasicBlock destination = e.getDestination().getData(); toRemove.add(e); if (rescuerMap.get(source) == destination) rescuerMap.remove(source); if (ensurerMap.get(source) == destination) ensurerMap.remove(source); } } } if (!toRemove.isEmpty()) { for (Edge edge : toRemove) { graph.removeEdge(edge); } } deleteOrphanedBlocks(graph); }
private BasicBlock createBB(Label label, Stack<ExceptionRegion> nestedExceptionRegions) { BasicBlock basicBlock = new BasicBlock(this, label); bbMap.put(label, basicBlock); graph.vertexFor(basicBlock); if (!nestedExceptionRegions.empty()) nestedExceptionRegions.peek().addBB(basicBlock); return basicBlock; }
private void deleteOrphanedBlocks(DirectedGraph<BasicBlock> graph) { // System.out.println("\nGraph:\n" + getGraph().toString()); // System.out.println("\nInstructions:\n" + toStringInstrs()); // FIXME: Quick and dirty implementation while (true) { BasicBlock bbToRemove = null; for (BasicBlock b : graph.allData()) { if (b == entryBB) continue; // Skip entry bb! // Every other bb should have at least one incoming edge if (graph.vertexFor(b).getIncomingEdges().isEmpty()) { bbToRemove = b; break; } } if (bbToRemove == null) break; removeBB(bbToRemove); } }
public void addEdge(BasicBlock source, BasicBlock destination, Object type) { graph.vertexFor(source).addEdgeTo(destination, type); }
public Set<Edge<BasicBlock>> getOutgoingEdges(BasicBlock block) { return graph.vertexFor(block).getOutgoingEdges(); }
public Iterable<Edge<BasicBlock>> getOutgoingEdgesNotOfType(BasicBlock block, Object type) { return graph.vertexFor(block).getOutgoingEdgesNotOfType(type); }
public Iterable<BasicBlock> getOutgoingDestinations(BasicBlock block) { return graph.vertexFor(block).getOutgoingDestinationsData(); }
public Iterable<BasicBlock> getOutgoingDestinationsNotOfType(BasicBlock block, Object type) { return graph.vertexFor(block).getOutgoingDestinationsDataNotOfType(type); }
public BasicBlock getOutgoingDestination(BasicBlock block) { return graph.vertexFor(block).getOutgoingDestinationData(); }
public BasicBlock getOutgoingDestinationOfType(BasicBlock block, Object type) { return graph.vertexFor(block).getOutgoingDestinationDataOfType(type); }
public Edge<BasicBlock> getOutgoingEdgeOfType(BasicBlock block, Object type) { return graph.vertexFor(block).getOutgoingEdgeOfType(type); }
public BasicBlock getIncomingSourceOfType(BasicBlock block, Object type) { return graph.vertexFor(block).getIncomingSourceDataOfType(type); }
public BasicBlock getIncomingSource(BasicBlock block) { return graph.vertexFor(block).getIncomingSourceData(); }
public Iterable<Edge<BasicBlock>> getIncomingEdges(BasicBlock block) { return graph.vertexFor(block).getIncomingEdges(); }
public Iterable<BasicBlock> getIncomingSources(BasicBlock block) { return graph.vertexFor(block).getIncomingSourcesData(); }