# HG changeset patch # User Doug Simon # Date 1373990213 -7200 # Node ID 388fbd0dd4a41649509448b1686d026f38e376ce # Parent 745322b363597d783fc9e68c3a01cfe95156f114 moved BranchNodeProbabilities to graal.nodes project diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -26,8 +26,8 @@ import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.nodes.GuardingPiNode.*; import static com.oracle.graal.nodes.calc.IsNullNode.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.phases.GraalOptions.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import java.lang.reflect.*; import java.util.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -26,10 +26,10 @@ import static com.oracle.graal.api.meta.DeoptimizationReason.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.TypeCheckSnippetUtils.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.nodes.extended.UnsafeCastNode.*; import static com.oracle.graal.phases.GraalOptions.*; import static com.oracle.graal.replacements.SnippetTemplate.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Tue Jul 16 17:56:53 2013 +0200 @@ -24,7 +24,7 @@ import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.meta.HotSpotRuntime.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import sun.misc.*; import com.oracle.graal.api.code.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -27,8 +27,8 @@ import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; import static com.oracle.graal.hotspot.replacements.TypeCheckSnippetUtils.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.phases.GraalOptions.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -27,8 +27,8 @@ import static com.oracle.graal.hotspot.nodes.EndLockScopeNode.*; import static com.oracle.graal.hotspot.nodes.VMErrorNode.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.replacements.SnippetTemplate.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import java.util.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -25,11 +25,11 @@ import static com.oracle.graal.api.code.UnsignedMath.*; import static com.oracle.graal.api.meta.LocationIdentity.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.nodes.extended.UnsafeArrayCastNode.*; import static com.oracle.graal.nodes.extended.UnsafeCastNode.*; import static com.oracle.graal.phases.GraalOptions.*; import static com.oracle.graal.replacements.SnippetTemplate.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import static com.oracle.graal.replacements.nodes.ExplodeLoopNode.*; import com.oracle.graal.api.code.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -24,8 +24,8 @@ import static com.oracle.graal.api.meta.LocationIdentity.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.phases.GraalOptions.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import java.lang.reflect.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java Tue Jul 16 17:56:53 2013 +0200 @@ -23,7 +23,7 @@ package com.oracle.graal.hotspot.replacements; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/TypeCheckSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/TypeCheckSnippetUtils.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/TypeCheckSnippetUtils.java Tue Jul 16 17:56:53 2013 +0200 @@ -23,8 +23,8 @@ package com.oracle.graal.hotspot.replacements; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.phases.GraalOptions.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import java.util.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeArrayCopySnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -24,8 +24,8 @@ import static com.oracle.graal.api.meta.LocationIdentity.*; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.replacements.SnippetTemplate.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.replacements; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.phases.GraalOptions.*; import static com.oracle.graal.replacements.SnippetTemplate.*; @@ -42,7 +43,6 @@ import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; import com.oracle.graal.replacements.nodes.*; import com.oracle.graal.word.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; public class WriteBarrierSnippets implements Snippets { diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BranchProbabilityNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BranchProbabilityNode.java Tue Jul 16 17:56:53 2013 +0200 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.nodes.extended; + +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; + +/** + * Instances of this node class will look for a preceding if node and put the given probability into + * the if node's taken probability. Then the branch probability node will be removed. This node is + * intended primarily for snippets, so that they can define their fast and slow paths. + */ +public class BranchProbabilityNode extends FloatingNode implements Canonicalizable, Lowerable { + + public static final double LIKELY_PROBABILITY = 0.6; + public static final double NOT_LIKELY_PROBABILITY = 1 - LIKELY_PROBABILITY; + + public static final double FREQUENT_PROBABILITY = 0.9; + public static final double NOT_FREQUENT_PROBABILITY = 1 - FREQUENT_PROBABILITY; + + public static final double FAST_PATH_PROBABILITY = 0.99; + public static final double SLOW_PATH_PROBABILITY = 1 - FAST_PATH_PROBABILITY; + + public static final double VERY_FAST_PATH_PROBABILITY = 0.999; + public static final double VERY_SLOW_PATH_PROBABILITY = 1 - VERY_FAST_PATH_PROBABILITY; + + @Input private ValueNode probability; + @Input private ValueNode condition; + + public BranchProbabilityNode(ValueNode probability, ValueNode condition) { + super(condition.stamp()); + this.probability = probability; + this.condition = condition; + } + + public ValueNode getProbability() { + return probability; + } + + public ValueNode getCondition() { + return condition; + } + + @Override + public ValueNode canonical(CanonicalizerTool tool) { + if (probability.isConstant()) { + double probabilityValue = probability.asConstant().asDouble(); + if (probabilityValue < 0.0) { + throw new GraalInternalError("A negative probability of " + probabilityValue + " is not allowed!"); + } else if (probabilityValue > 1.0) { + throw new GraalInternalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!"); + } + boolean couldSet = false; + for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) { + if (node.condition() == Condition.EQ) { + ValueNode other = node.x(); + if (node.x() == this) { + other = node.y(); + } + if (other.isConstant()) { + double probabilityToSet = probabilityValue; + if (other.asConstant().asInt() == 0) { + probabilityToSet = 1.0 - probabilityToSet; + } + for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) { + couldSet = true; + ifNodeUsages.setTrueSuccessorProbability(probabilityToSet); + } + } + } + } + if (!couldSet) { + if (isSubstitutionGraph()) { + return this; + } + throw new GraalInternalError("Wrong usage of branch probability injection!"); + } + return condition; + } + return this; + } + + private boolean isSubstitutionGraph() { + return usages().count() == 1 && usages().first() instanceof ReturnNode; + } + + /** + * This intrinsic should only be used for the condition of an if statement. The parameter + * condition should also only denote a simple condition and not a combined condition involving + * && or || operators. It injects the probability of the condition into the if statement. + * + * @param probability the probability that the given condition is true as a double value between + * 0.0 and 1.0. + * @param condition the simple condition without any && or || operators + * @return the condition + */ + @NodeIntrinsic + public static boolean probability(double probability, boolean condition) { + assert probability >= 0.0 && probability <= 1.0; + return condition; + } + + @Override + public void lower(LoweringTool tool, LoweringType loweringType) { + throw new GraalInternalError("Branch probability could not be injected, because the probability value did not reduce to a constant value."); + } +} diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64ConvertSnippets.java --- a/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64ConvertSnippets.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64ConvertSnippets.java Tue Jul 16 17:56:53 2013 +0200 @@ -22,8 +22,8 @@ */ package com.oracle.graal.replacements.amd64; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static com.oracle.graal.replacements.SnippetTemplate.*; -import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import java.util.*; diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BranchProbabilityNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BranchProbabilityNode.java Tue Jul 16 17:29:39 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.replacements.nodes; - -import com.oracle.graal.graph.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.spi.*; - -/** - * Instances of this node class will look for a preceding if node and put the given probability into - * the if node's taken probability. Then the branch probability node will be removed. This node is - * intended primarily for snippets, so that they can define their fast and slow paths. - */ -public class BranchProbabilityNode extends FloatingNode implements Canonicalizable, Lowerable { - - public static final double LIKELY_PROBABILITY = 0.6; - public static final double NOT_LIKELY_PROBABILITY = 1 - LIKELY_PROBABILITY; - - public static final double FREQUENT_PROBABILITY = 0.9; - public static final double NOT_FREQUENT_PROBABILITY = 1 - FREQUENT_PROBABILITY; - - public static final double FAST_PATH_PROBABILITY = 0.99; - public static final double SLOW_PATH_PROBABILITY = 1 - FAST_PATH_PROBABILITY; - - public static final double VERY_FAST_PATH_PROBABILITY = 0.999; - public static final double VERY_SLOW_PATH_PROBABILITY = 1 - VERY_FAST_PATH_PROBABILITY; - - @Input private ValueNode probability; - @Input private ValueNode condition; - - public BranchProbabilityNode(ValueNode probability, ValueNode condition) { - super(condition.stamp()); - this.probability = probability; - this.condition = condition; - } - - public ValueNode getProbability() { - return probability; - } - - public ValueNode getCondition() { - return condition; - } - - @Override - public ValueNode canonical(CanonicalizerTool tool) { - if (probability.isConstant()) { - double probabilityValue = probability.asConstant().asDouble(); - if (probabilityValue < 0.0) { - throw new GraalInternalError("A negative probability of " + probabilityValue + " is not allowed!"); - } else if (probabilityValue > 1.0) { - throw new GraalInternalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!"); - } - boolean couldSet = false; - for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) { - if (node.condition() == Condition.EQ) { - ValueNode other = node.x(); - if (node.x() == this) { - other = node.y(); - } - if (other.isConstant()) { - double probabilityToSet = probabilityValue; - if (other.asConstant().asInt() == 0) { - probabilityToSet = 1.0 - probabilityToSet; - } - for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) { - couldSet = true; - ifNodeUsages.setTrueSuccessorProbability(probabilityToSet); - } - } - } - } - if (!couldSet) { - if (isSubstitutionGraph()) { - return this; - } - throw new GraalInternalError("Wrong usage of branch probability injection!"); - } - return condition; - } - return this; - } - - private boolean isSubstitutionGraph() { - return usages().count() == 1 && usages().first() instanceof ReturnNode; - } - - /** - * This intrinsic should only be used for the condition of an if statement. The parameter - * condition should also only denote a simple condition and not a combined condition involving - * && or || operators. It injects the probability of the condition into the if statement. - * - * @param probability the probability that the given condition is true as a double value between - * 0.0 and 1.0. - * @param condition the simple condition without any && or || operators - * @return the condition - */ - @NodeIntrinsic - public static boolean probability(double probability, boolean condition) { - assert probability >= 0.0 && probability <= 1.0; - return condition; - } - - @Override - public void lower(LoweringTool tool, LoweringType loweringType) { - throw new GraalInternalError("Branch probability could not be injected, because the probability value did not reduce to a constant value."); - } -} diff -r 745322b36359 -r 388fbd0dd4a4 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Tue Jul 16 17:29:39 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Tue Jul 16 17:56:53 2013 +0200 @@ -28,8 +28,8 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.nodes.*; import com.oracle.graal.truffle.nodes.*; import com.oracle.truffle.api.*;