Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BranchProbabilityNode.java @ 19526:8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 20 Feb 2015 22:22:55 +0100 |
parents | 61d3cb8e1280 |
children | c66037cb9cd1 |
rev | line source |
---|---|
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
10787
388fbd0dd4a4
moved BranchNodeProbabilities to graal.nodes project
Doug Simon <doug.simon@oracle.com>
parents:
9840
diff
changeset
|
23 package com.oracle.graal.nodes.extended; |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
14906
diff
changeset
|
25 import com.oracle.graal.compiler.common.*; |
15200
97eed257999b
Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15193
diff
changeset
|
26 import com.oracle.graal.compiler.common.calc.*; |
19396
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
27 import com.oracle.graal.graph.*; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11880
diff
changeset
|
28 import com.oracle.graal.graph.spi.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16822
diff
changeset
|
29 import com.oracle.graal.nodeinfo.*; |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.nodes.*; |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
31 import com.oracle.graal.nodes.calc.*; |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.spi.*; |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7368
diff
changeset
|
35 * Instances of this node class will look for a preceding if node and put the given probability into |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7368
diff
changeset
|
36 * the if node's taken probability. Then the branch probability node will be removed. This node is |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7368
diff
changeset
|
37 * intended primarily for snippets, so that they can define their fast and slow paths. |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 */ |
16822
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16221
diff
changeset
|
39 @NodeInfo |
18998
ec0733b5a90a
Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18969
diff
changeset
|
40 public final class BranchProbabilityNode extends FloatingNode implements Simplifiable, Lowerable { |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
41 |
19526
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19403
diff
changeset
|
42 public static final NodeClass<BranchProbabilityNode> TYPE = NodeClass.create(BranchProbabilityNode.class); |
7554
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
43 public static final double LIKELY_PROBABILITY = 0.6; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
44 public static final double NOT_LIKELY_PROBABILITY = 1 - LIKELY_PROBABILITY; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
45 |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
46 public static final double FREQUENT_PROBABILITY = 0.9; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
47 public static final double NOT_FREQUENT_PROBABILITY = 1 - FREQUENT_PROBABILITY; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
48 |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
49 public static final double FAST_PATH_PROBABILITY = 0.99; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
50 public static final double SLOW_PATH_PROBABILITY = 1 - FAST_PATH_PROBABILITY; |
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
51 |
9514
56dc7fe83f8a
rename: VERY_FAST_DEOPT_PATH_PROBABILITY -> VERY_FAST_PATH_PROBABILITY
Doug Simon <doug.simon@oracle.com>
parents:
9320
diff
changeset
|
52 public static final double VERY_FAST_PATH_PROBABILITY = 0.999; |
56dc7fe83f8a
rename: VERY_FAST_DEOPT_PATH_PROBABILITY -> VERY_FAST_PATH_PROBABILITY
Doug Simon <doug.simon@oracle.com>
parents:
9320
diff
changeset
|
53 public static final double VERY_SLOW_PATH_PROBABILITY = 1 - VERY_FAST_PATH_PROBABILITY; |
7554
9472211c812b
named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
54 |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
55 @Input ValueNode probability; |
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16895
diff
changeset
|
56 @Input ValueNode condition; |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
57 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18187
diff
changeset
|
58 public BranchProbabilityNode(ValueNode probability, ValueNode condition) { |
19396
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
59 super(TYPE, condition.stamp()); |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 this.probability = probability; |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
61 this.condition = condition; |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
62 } |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
63 |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
64 public ValueNode getProbability() { |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
65 return probability; |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
66 } |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
67 |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
68 public ValueNode getCondition() { |
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
69 return condition; |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
70 } |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
71 |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
72 @Override |
16221
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
73 public void simplify(SimplifierTool tool) { |
9308
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
74 if (probability.isConstant()) { |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
75 double probabilityValue = probability.asJavaConstant().asDouble(); |
9308
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
76 if (probabilityValue < 0.0) { |
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
77 throw new GraalInternalError("A negative probability of " + probabilityValue + " is not allowed!"); |
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
78 } else if (probabilityValue > 1.0) { |
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
79 throw new GraalInternalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!"); |
18871
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
80 } else if (Double.isNaN(probabilityValue)) { |
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
81 /* |
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
82 * We allow NaN if the node is in unreachable code that will eventually fall away, |
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
83 * or else an error will be thrown during lowering since we keep the node around. |
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
84 */ |
d493f179ef76
BranchProbabilityNode: branch probability value may evaluate to NaN in unreached code
Andreas Woess <andreas.woess@jku.at>
parents:
18845
diff
changeset
|
85 return; |
9308
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
86 } |
9317
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
87 boolean couldSet = false; |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
88 for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) { |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
89 if (node.condition() == Condition.EQ) { |
16207
df6f2365b153
rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15200
diff
changeset
|
90 ValueNode other = node.getX(); |
df6f2365b153
rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15200
diff
changeset
|
91 if (node.getX() == this) { |
df6f2365b153
rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15200
diff
changeset
|
92 other = node.getY(); |
9317
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
93 } |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
94 if (other.isConstant()) { |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
95 double probabilityToSet = probabilityValue; |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
17450
diff
changeset
|
96 if (other.asJavaConstant().asInt() == 0) { |
9317
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
97 probabilityToSet = 1.0 - probabilityToSet; |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
98 } |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
99 for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) { |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
100 couldSet = true; |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
101 ifNodeUsages.setTrueSuccessorProbability(probabilityToSet); |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
102 } |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
103 } |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
104 } |
18d28d9bb13a
Fix branch probability injection.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9316
diff
changeset
|
105 } |
16221
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
106 if (couldSet) { |
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
107 replaceAndDelete(condition); |
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
108 tool.addToWorkList(condition.usages()); |
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
109 } else { |
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
110 if (!isSubstitutionGraph()) { |
8e82823712ba
let BranchProbabilityNode implement Simplifiable instead of Canonicalizable
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16207
diff
changeset
|
111 throw new GraalInternalError("Wrong usage of branch probability injection!"); |
9839
b360b05aa996
Quick fix for BranchProbabilityNode.
Andreas Woess <andreas.woess@jku.at>
parents:
9514
diff
changeset
|
112 } |
9308
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
113 } |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
114 } |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
115 } |
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
116 |
9839
b360b05aa996
Quick fix for BranchProbabilityNode.
Andreas Woess <andreas.woess@jku.at>
parents:
9514
diff
changeset
|
117 private boolean isSubstitutionGraph() { |
18969
14496953435e
Use Node#getUsageCount wherever possible.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18871
diff
changeset
|
118 return getUsageCount() == 1 && usages().first() instanceof ReturnNode; |
9839
b360b05aa996
Quick fix for BranchProbabilityNode.
Andreas Woess <andreas.woess@jku.at>
parents:
9514
diff
changeset
|
119 } |
b360b05aa996
Quick fix for BranchProbabilityNode.
Andreas Woess <andreas.woess@jku.at>
parents:
9514
diff
changeset
|
120 |
9318
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
121 /** |
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
122 * This intrinsic should only be used for the condition of an if statement. The parameter |
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
123 * condition should also only denote a simple condition and not a combined condition involving |
14906 | 124 * && or || operators. It injects the probability of the condition into the if |
125 * statement. | |
126 * | |
9318
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
127 * @param probability the probability that the given condition is true as a double value between |
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
128 * 0.0 and 1.0. |
14906 | 129 * @param condition the simple condition without any && or || operators |
9318
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
130 * @return the condition |
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
131 */ |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
132 @NodeIntrinsic |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
133 public static boolean probability(double probability, boolean condition) { |
9318
dc04c7e8f714
Add javadoc to BranchProbabilityNode.probability node intrinsic. Avoid combined conditions in connection with the probability.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9317
diff
changeset
|
134 assert probability >= 0.0 && probability <= 1.0; |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
135 return condition; |
9308
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
136 } |
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
137 |
2b62ddcf8fd8
Allow lazy resolving of the constant input value of the node injecting probabilities into if nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8478
diff
changeset
|
138 @Override |
11579
ae619d70bf4b
Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
10787
diff
changeset
|
139 public void lower(LoweringTool tool) { |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9309
diff
changeset
|
140 throw new GraalInternalError("Branch probability could not be injected, because the probability value did not reduce to a constant value."); |
8478
e9dad49ce336
made method substitutions for System be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
141 } |
7368
f04a5e46cdd2
new facility to add branch probabilities for snippets, probabilities for frequently-used snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
142 } |