< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/contract/NodeCostUtil.java

Print this page
rev 52509 : [mq]: graal


  66             schedule.apply(graph);
  67             cfg = graph.getLastSchedule().getCFG();
  68             blockToNodes = b -> graph.getLastSchedule().getBlockToNodesMap().get(b);
  69         } else {
  70             cfg = ControlFlowGraph.compute(graph, true, true, false, false);
  71             BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
  72             for (Block b : cfg.getBlocks()) {
  73                 ArrayList<FixedNode> curNodes = new ArrayList<>();
  74                 for (FixedNode node : b.getNodes()) {
  75                     curNodes.add(node);
  76                 }
  77                 nodes.put(b, curNodes);
  78             }
  79             blockToNodes = b -> nodes.get(b);
  80         }
  81         double weightedCycles = 0D;
  82         DebugContext debug = graph.getDebug();
  83         try (DebugContext.Scope s = debug.scope("NodeCostSummary")) {
  84             for (Block block : cfg.getBlocks()) {
  85                 for (Node n : blockToNodes.apply(block)) {
  86                     double probWeighted = n.estimatedNodeCycles().value * block.probability();
  87                     assert Double.isFinite(probWeighted);
  88                     weightedCycles += probWeighted;
  89                     if (debug.isLogEnabled()) {
  90                         debug.log("Node %s contributes cycles:%f size:%d to graph %s [block prob:%f]", n, n.estimatedNodeCycles().value * block.probability(),
  91                                         n.estimatedNodeSize().value, graph, block.probability());
  92                     }
  93                 }
  94             }
  95         }
  96         assert weightedCycles >= 0D;
  97         assert Double.isFinite(weightedCycles);
  98         return weightedCycles;
  99     }
 100 
 101     private static int deltaCompare(double a, double b, double delta) {
 102         if (Math.abs(a - b) <= delta) {
 103             return 0;
 104         }
 105         return Double.compare(a, b);
 106     }
 107 
 108     /**
 109      * Factor to control the "imprecision" of the before - after relation when verifying phase
 110      * effects. If the cost model is perfect the best theoretical value is 0.0D (Ignoring the fact
 111      * that profiling information is not reliable and thus the, probability based, profiling view on


  66             schedule.apply(graph);
  67             cfg = graph.getLastSchedule().getCFG();
  68             blockToNodes = b -> graph.getLastSchedule().getBlockToNodesMap().get(b);
  69         } else {
  70             cfg = ControlFlowGraph.compute(graph, true, true, false, false);
  71             BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
  72             for (Block b : cfg.getBlocks()) {
  73                 ArrayList<FixedNode> curNodes = new ArrayList<>();
  74                 for (FixedNode node : b.getNodes()) {
  75                     curNodes.add(node);
  76                 }
  77                 nodes.put(b, curNodes);
  78             }
  79             blockToNodes = b -> nodes.get(b);
  80         }
  81         double weightedCycles = 0D;
  82         DebugContext debug = graph.getDebug();
  83         try (DebugContext.Scope s = debug.scope("NodeCostSummary")) {
  84             for (Block block : cfg.getBlocks()) {
  85                 for (Node n : blockToNodes.apply(block)) {
  86                     double probWeighted = n.estimatedNodeCycles().value * block.getRelativeFrequency();
  87                     assert Double.isFinite(probWeighted);
  88                     weightedCycles += probWeighted;
  89                     if (debug.isLogEnabled()) {
  90                         debug.log("Node %s contributes cycles:%f size:%d to graph %s [block freq:%f]", n, n.estimatedNodeCycles().value * block.getRelativeFrequency(),
  91                                         n.estimatedNodeSize().value, graph, block.getRelativeFrequency());
  92                     }
  93                 }
  94             }
  95         }
  96         assert weightedCycles >= 0D;
  97         assert Double.isFinite(weightedCycles);
  98         return weightedCycles;
  99     }
 100 
 101     private static int deltaCompare(double a, double b, double delta) {
 102         if (Math.abs(a - b) <= delta) {
 103             return 0;
 104         }
 105         return Double.compare(a, b);
 106     }
 107 
 108     /**
 109      * Factor to control the "imprecision" of the before - after relation when verifying phase
 110      * effects. If the cost model is perfect the best theoretical value is 0.0D (Ignoring the fact
 111      * that profiling information is not reliable and thus the, probability based, profiling view on
< prev index next >