Esempio n. 1
0
File: CFG.java Progetto: 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);
  }
Esempio n. 2
0
File: CFG.java Progetto: cwgem/jruby
  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;
  }
Esempio n. 3
0
File: CFG.java Progetto: 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);
    }
  }
Esempio n. 4
0
File: CFG.java Progetto: cwgem/jruby
 public void addEdge(BasicBlock source, BasicBlock destination, Object type) {
   graph.vertexFor(source).addEdgeTo(destination, type);
 }
Esempio n. 5
0
File: CFG.java Progetto: cwgem/jruby
 public Set<Edge<BasicBlock>> getOutgoingEdges(BasicBlock block) {
   return graph.vertexFor(block).getOutgoingEdges();
 }
Esempio n. 6
0
File: CFG.java Progetto: cwgem/jruby
 public Iterable<Edge<BasicBlock>> getOutgoingEdgesNotOfType(BasicBlock block, Object type) {
   return graph.vertexFor(block).getOutgoingEdgesNotOfType(type);
 }
Esempio n. 7
0
File: CFG.java Progetto: cwgem/jruby
 public Iterable<BasicBlock> getOutgoingDestinations(BasicBlock block) {
   return graph.vertexFor(block).getOutgoingDestinationsData();
 }
Esempio n. 8
0
File: CFG.java Progetto: cwgem/jruby
 public Iterable<BasicBlock> getOutgoingDestinationsNotOfType(BasicBlock block, Object type) {
   return graph.vertexFor(block).getOutgoingDestinationsDataNotOfType(type);
 }
Esempio n. 9
0
File: CFG.java Progetto: cwgem/jruby
 public BasicBlock getOutgoingDestination(BasicBlock block) {
   return graph.vertexFor(block).getOutgoingDestinationData();
 }
Esempio n. 10
0
File: CFG.java Progetto: cwgem/jruby
 public BasicBlock getOutgoingDestinationOfType(BasicBlock block, Object type) {
   return graph.vertexFor(block).getOutgoingDestinationDataOfType(type);
 }
Esempio n. 11
0
File: CFG.java Progetto: cwgem/jruby
 public Edge<BasicBlock> getOutgoingEdgeOfType(BasicBlock block, Object type) {
   return graph.vertexFor(block).getOutgoingEdgeOfType(type);
 }
Esempio n. 12
0
File: CFG.java Progetto: cwgem/jruby
 public BasicBlock getIncomingSourceOfType(BasicBlock block, Object type) {
   return graph.vertexFor(block).getIncomingSourceDataOfType(type);
 }
Esempio n. 13
0
File: CFG.java Progetto: cwgem/jruby
 public BasicBlock getIncomingSource(BasicBlock block) {
   return graph.vertexFor(block).getIncomingSourceData();
 }
Esempio n. 14
0
File: CFG.java Progetto: cwgem/jruby
 public Iterable<Edge<BasicBlock>> getIncomingEdges(BasicBlock block) {
   return graph.vertexFor(block).getIncomingEdges();
 }
Esempio n. 15
0
File: CFG.java Progetto: cwgem/jruby
 public Iterable<BasicBlock> getIncomingSources(BasicBlock block) {
   return graph.vertexFor(block).getIncomingSourcesData();
 }