Mercurial > hg > truffle
comparison graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ProfileCompiledMethodsPhase.java @ 15470:c55f44b3c5e5
remove NodesToDoubles, refactoring of node probability and inlining relevance computation
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Fri, 02 May 2014 12:02:27 +0200 |
parents | 24d4b669756e |
children | 4bd6ad45ee0a |
comparison
equal
deleted
inserted
replaced
15469:5c05f3666abf | 15470:c55f44b3c5e5 |
---|---|
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.graal.phases.common; | 23 package com.oracle.graal.phases.common; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 import java.util.function.*; | |
26 | 27 |
27 import com.oracle.graal.compiler.common.cfg.*; | 28 import com.oracle.graal.compiler.common.cfg.*; |
28 import com.oracle.graal.graph.*; | 29 import com.oracle.graal.graph.*; |
29 import com.oracle.graal.nodes.*; | 30 import com.oracle.graal.nodes.*; |
30 import com.oracle.graal.nodes.calc.*; | 31 import com.oracle.graal.nodes.calc.*; |
31 import com.oracle.graal.nodes.cfg.*; | 32 import com.oracle.graal.nodes.cfg.*; |
32 import com.oracle.graal.nodes.debug.*; | 33 import com.oracle.graal.nodes.debug.*; |
33 import com.oracle.graal.nodes.extended.*; | 34 import com.oracle.graal.nodes.extended.*; |
34 import com.oracle.graal.nodes.java.*; | 35 import com.oracle.graal.nodes.java.*; |
35 import com.oracle.graal.nodes.spi.*; | 36 import com.oracle.graal.nodes.spi.*; |
36 import com.oracle.graal.nodes.util.*; | |
37 import com.oracle.graal.nodes.virtual.*; | 37 import com.oracle.graal.nodes.virtual.*; |
38 import com.oracle.graal.phases.*; | 38 import com.oracle.graal.phases.*; |
39 import com.oracle.graal.phases.graph.*; | 39 import com.oracle.graal.phases.graph.*; |
40 import com.oracle.graal.phases.schedule.*; | 40 import com.oracle.graal.phases.schedule.*; |
41 | 41 |
61 private static boolean WITH_INVOKE_FREE_SECTIONS = false; | 61 private static boolean WITH_INVOKE_FREE_SECTIONS = false; |
62 private static boolean WITH_INVOKES = true; | 62 private static boolean WITH_INVOKES = true; |
63 | 63 |
64 @Override | 64 @Override |
65 protected void run(StructuredGraph graph) { | 65 protected void run(StructuredGraph graph) { |
66 ComputeProbabilityClosure closure = new ComputeProbabilityClosure(graph); | 66 ToDoubleFunction<FixedNode> probabilities = new FixedNodeProbabilityCache(); |
67 NodesToDoubles probabilities = closure.apply(); | |
68 SchedulePhase schedule = new SchedulePhase(); | 67 SchedulePhase schedule = new SchedulePhase(); |
69 schedule.apply(graph, false); | 68 schedule.apply(graph, false); |
70 | 69 |
71 ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true); | 70 ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true); |
72 for (Loop<Block> loop : cfg.getLoops()) { | 71 for (Loop<Block> loop : cfg.getLoops()) { |
73 double loopProbability = probabilities.get(loop.header.getBeginNode()); | 72 double loopProbability = probabilities.applyAsDouble(loop.header.getBeginNode()); |
74 if (loopProbability > (1D / Integer.MAX_VALUE)) { | 73 if (loopProbability > (1D / Integer.MAX_VALUE)) { |
75 addSectionCounters(loop.header.getBeginNode(), loop.blocks, loop.children, schedule, probabilities); | 74 addSectionCounters(loop.header.getBeginNode(), loop.blocks, loop.children, schedule, probabilities); |
76 } | 75 } |
77 } | 76 } |
78 // don't put the counter increase directly after the start (problems with OSR) | 77 // don't put the counter increase directly after the start (problems with OSR) |
91 } | 90 } |
92 } | 91 } |
93 } | 92 } |
94 } | 93 } |
95 | 94 |
96 private static void addSectionCounters(FixedWithNextNode start, Collection<Block> sectionBlocks, Collection<Loop<Block>> childLoops, SchedulePhase schedule, NodesToDoubles probabilities) { | 95 private static void addSectionCounters(FixedWithNextNode start, Collection<Block> sectionBlocks, Collection<Loop<Block>> childLoops, SchedulePhase schedule, |
96 ToDoubleFunction<FixedNode> probabilities) { | |
97 HashSet<Block> blocks = new HashSet<>(sectionBlocks); | 97 HashSet<Block> blocks = new HashSet<>(sectionBlocks); |
98 for (Loop<?> loop : childLoops) { | 98 for (Loop<?> loop : childLoops) { |
99 blocks.removeAll(loop.blocks); | 99 blocks.removeAll(loop.blocks); |
100 } | 100 } |
101 double weight = getSectionWeight(schedule, probabilities, blocks) / probabilities.get(start); | 101 double weight = getSectionWeight(schedule, probabilities, blocks) / probabilities.applyAsDouble(start); |
102 DynamicCounterNode.addCounterBefore(GROUP_NAME, sectionHead(start), (long) weight, true, start.next()); | 102 DynamicCounterNode.addCounterBefore(GROUP_NAME, sectionHead(start), (long) weight, true, start.next()); |
103 if (WITH_INVOKE_FREE_SECTIONS && !hasInvoke(blocks)) { | 103 if (WITH_INVOKE_FREE_SECTIONS && !hasInvoke(blocks)) { |
104 DynamicCounterNode.addCounterBefore(GROUP_NAME_WITHOUT, sectionHead(start), (long) weight, true, start.next()); | 104 DynamicCounterNode.addCounterBefore(GROUP_NAME_WITHOUT, sectionHead(start), (long) weight, true, start.next()); |
105 } | 105 } |
106 } | 106 } |
111 } else { | 111 } else { |
112 return ""; | 112 return ""; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 private static double getSectionWeight(SchedulePhase schedule, NodesToDoubles probabilities, Collection<Block> blocks) { | 116 private static double getSectionWeight(SchedulePhase schedule, ToDoubleFunction<FixedNode> probabilities, Collection<Block> blocks) { |
117 double count = 0; | 117 double count = 0; |
118 for (Block block : blocks) { | 118 for (Block block : blocks) { |
119 double blockProbability = probabilities.get(block.getBeginNode()); | 119 double blockProbability = probabilities.applyAsDouble(block.getBeginNode()); |
120 for (ScheduledNode node : schedule.getBlockToNodesMap().get(block)) { | 120 for (ScheduledNode node : schedule.getBlockToNodesMap().get(block)) { |
121 count += blockProbability * getNodeWeight(node); | 121 count += blockProbability * getNodeWeight(node); |
122 } | 122 } |
123 } | 123 } |
124 return count; | 124 return count; |