< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/BranchProbabilityNode.java

Print this page




  65 
  66     @Input ValueNode probability;
  67     @Input ValueNode condition;
  68 
  69     public BranchProbabilityNode(ValueNode probability, ValueNode condition) {
  70         super(TYPE, condition.stamp());
  71         this.probability = probability;
  72         this.condition = condition;
  73     }
  74 
  75     public ValueNode getProbability() {
  76         return probability;
  77     }
  78 
  79     public ValueNode getCondition() {
  80         return condition;
  81     }
  82 
  83     @Override
  84     public void simplify(SimplifierTool tool) {



  85         if (probability.isConstant()) {
  86             double probabilityValue = probability.asJavaConstant().asDouble();
  87             if (probabilityValue < 0.0) {
  88                 throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
  89             } else if (probabilityValue > 1.0) {
  90                 throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
  91             } else if (Double.isNaN(probabilityValue)) {
  92                 /*
  93                  * We allow NaN if the node is in unreachable code that will eventually fall away,
  94                  * or else an error will be thrown during lowering since we keep the node around.
  95                  */
  96                 return;
  97             }
  98             boolean usageFound = false;
  99             for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
 100                 assert node.condition() == Condition.EQ;
 101                 ValueNode other = node.getX();
 102                 if (node.getX() == this) {
 103                     other = node.getY();
 104                 }




  65 
  66     @Input ValueNode probability;
  67     @Input ValueNode condition;
  68 
  69     public BranchProbabilityNode(ValueNode probability, ValueNode condition) {
  70         super(TYPE, condition.stamp());
  71         this.probability = probability;
  72         this.condition = condition;
  73     }
  74 
  75     public ValueNode getProbability() {
  76         return probability;
  77     }
  78 
  79     public ValueNode getCondition() {
  80         return condition;
  81     }
  82 
  83     @Override
  84     public void simplify(SimplifierTool tool) {
  85         if (!hasUsages()) {
  86             return;
  87         }
  88         if (probability.isConstant()) {
  89             double probabilityValue = probability.asJavaConstant().asDouble();
  90             if (probabilityValue < 0.0) {
  91                 throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
  92             } else if (probabilityValue > 1.0) {
  93                 throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
  94             } else if (Double.isNaN(probabilityValue)) {
  95                 /*
  96                  * We allow NaN if the node is in unreachable code that will eventually fall away,
  97                  * or else an error will be thrown during lowering since we keep the node around.
  98                  */
  99                 return;
 100             }
 101             boolean usageFound = false;
 102             for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
 103                 assert node.condition() == Condition.EQ;
 104                 ValueNode other = node.getX();
 105                 if (node.getX() == this) {
 106                     other = node.getY();
 107                 }


< prev index next >