示例#1
0
文件: CFG.java 项目: cwgem/jruby
  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);
  }
示例#2
0
文件: CFG.java 项目: cwgem/jruby
  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);
    }
  }
示例#3
0
文件: CFG.java 项目: cwgem/jruby
 public Collection<BasicBlock> getBasicBlocks() {
   return graph.allData();
 }