19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common.inlining.walker;
26
27 import java.util.BitSet;
28 import java.util.LinkedList;
29 import java.util.function.ToDoubleFunction;
30
31 import jdk.internal.vm.compiler.collections.EconomicSet;
32 import jdk.internal.vm.compiler.collections.Equivalence;
33 import org.graalvm.compiler.nodes.FixedNode;
34 import org.graalvm.compiler.nodes.Invoke;
35 import org.graalvm.compiler.nodes.ParameterNode;
36 import org.graalvm.compiler.nodes.StructuredGraph;
37 import org.graalvm.compiler.nodes.ValueNode;
38 import org.graalvm.compiler.phases.common.inlining.policy.AbstractInliningPolicy;
39 import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache;
40
41 import jdk.vm.ci.meta.ResolvedJavaMethod;
42
43 /**
44 * <p>
45 * A {@link CallsiteHolder} whose graph has been copied already and thus can be modified without
46 * affecting the original (usually cached) version.
47 * </p>
48 *
49 * <p>
50 * An instance of this class is derived from an
51 * {@link org.graalvm.compiler.phases.common.inlining.info.elem.InlineableGraph InlineableGraph} and
52 * contains a subset of the information there: just the {@link Invoke} nodes from it. Such nodes are
53 * candidates for depth-first search of further inlining opportunities (thus the adjective
54 * "explorable" given to this class)
55 * </p>
56 *
57 * @see InliningData#moveForward()
58 */
59 public final class CallsiteHolderExplorable extends CallsiteHolder {
70
71 /**
72 * @see #getFixedParams()
73 */
74 private final EconomicSet<ParameterNode> fixedParams;
75
76 private final ToDoubleFunction<FixedNode> probabilities;
77 private final ComputeInliningRelevance computeInliningRelevance;
78
79 public CallsiteHolderExplorable(StructuredGraph graph, double probability, double relevance, BitSet freshlyInstantiatedArguments, LinkedList<Invoke> invokes) {
80 assert graph != null;
81 this.graph = graph;
82 this.probability = probability;
83 this.relevance = relevance;
84 this.fixedParams = fixedParamsAt(freshlyInstantiatedArguments);
85 remainingInvokes = invokes == null ? new InliningIterator(graph).apply() : invokes;
86 if (remainingInvokes.isEmpty()) {
87 probabilities = null;
88 computeInliningRelevance = null;
89 } else {
90 probabilities = new FixedNodeProbabilityCache();
91 computeInliningRelevance = new ComputeInliningRelevance(graph, probabilities);
92 computeProbabilities();
93 }
94 assert repOK();
95 }
96
97 /**
98 * @see #getFixedParams()
99 */
100 private EconomicSet<ParameterNode> fixedParamsAt(BitSet freshlyInstantiatedArguments) {
101 if (freshlyInstantiatedArguments == null || freshlyInstantiatedArguments.isEmpty()) {
102 return EconomicSet.create(Equivalence.IDENTITY);
103 }
104 EconomicSet<ParameterNode> result = EconomicSet.create(Equivalence.IDENTITY);
105 for (ParameterNode p : graph.getNodes(ParameterNode.TYPE)) {
106 if (freshlyInstantiatedArguments.get(p.index())) {
107 result.add(p);
108 }
109 }
110 return result;
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.phases.common.inlining.walker;
26
27 import java.util.BitSet;
28 import java.util.LinkedList;
29 import java.util.function.ToDoubleFunction;
30
31 import jdk.internal.vm.compiler.collections.EconomicSet;
32 import jdk.internal.vm.compiler.collections.Equivalence;
33 import org.graalvm.compiler.nodes.FixedNode;
34 import org.graalvm.compiler.nodes.Invoke;
35 import org.graalvm.compiler.nodes.ParameterNode;
36 import org.graalvm.compiler.nodes.StructuredGraph;
37 import org.graalvm.compiler.nodes.ValueNode;
38 import org.graalvm.compiler.phases.common.inlining.policy.AbstractInliningPolicy;
39 import org.graalvm.compiler.phases.graph.FixedNodeRelativeFrequencyCache;
40
41 import jdk.vm.ci.meta.ResolvedJavaMethod;
42
43 /**
44 * <p>
45 * A {@link CallsiteHolder} whose graph has been copied already and thus can be modified without
46 * affecting the original (usually cached) version.
47 * </p>
48 *
49 * <p>
50 * An instance of this class is derived from an
51 * {@link org.graalvm.compiler.phases.common.inlining.info.elem.InlineableGraph InlineableGraph} and
52 * contains a subset of the information there: just the {@link Invoke} nodes from it. Such nodes are
53 * candidates for depth-first search of further inlining opportunities (thus the adjective
54 * "explorable" given to this class)
55 * </p>
56 *
57 * @see InliningData#moveForward()
58 */
59 public final class CallsiteHolderExplorable extends CallsiteHolder {
70
71 /**
72 * @see #getFixedParams()
73 */
74 private final EconomicSet<ParameterNode> fixedParams;
75
76 private final ToDoubleFunction<FixedNode> probabilities;
77 private final ComputeInliningRelevance computeInliningRelevance;
78
79 public CallsiteHolderExplorable(StructuredGraph graph, double probability, double relevance, BitSet freshlyInstantiatedArguments, LinkedList<Invoke> invokes) {
80 assert graph != null;
81 this.graph = graph;
82 this.probability = probability;
83 this.relevance = relevance;
84 this.fixedParams = fixedParamsAt(freshlyInstantiatedArguments);
85 remainingInvokes = invokes == null ? new InliningIterator(graph).apply() : invokes;
86 if (remainingInvokes.isEmpty()) {
87 probabilities = null;
88 computeInliningRelevance = null;
89 } else {
90 probabilities = new FixedNodeRelativeFrequencyCache();
91 computeInliningRelevance = new ComputeInliningRelevance(graph, probabilities);
92 computeProbabilities();
93 }
94 assert repOK();
95 }
96
97 /**
98 * @see #getFixedParams()
99 */
100 private EconomicSet<ParameterNode> fixedParamsAt(BitSet freshlyInstantiatedArguments) {
101 if (freshlyInstantiatedArguments == null || freshlyInstantiatedArguments.isEmpty()) {
102 return EconomicSet.create(Equivalence.IDENTITY);
103 }
104 EconomicSet<ParameterNode> result = EconomicSet.create(Equivalence.IDENTITY);
105 for (ParameterNode p : graph.getNodes(ParameterNode.TYPE)) {
106 if (freshlyInstantiatedArguments.get(p.index())) {
107 result.add(p);
108 }
109 }
110 return result;
|