1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 package org.graalvm.compiler.nodes.calc;
  24 
  25 import org.graalvm.compiler.core.common.calc.Condition;
  26 import org.graalvm.compiler.core.common.type.FloatStamp;
  27 import org.graalvm.compiler.core.common.type.IntegerStamp;
  28 import org.graalvm.compiler.core.common.type.Stamp;
  29 import org.graalvm.compiler.debug.GraalError;
  30 import org.graalvm.compiler.graph.NodeClass;
  31 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  32 import org.graalvm.compiler.nodeinfo.NodeCycles;
  33 import org.graalvm.compiler.nodeinfo.NodeInfo;
  34 import org.graalvm.compiler.nodes.LogicConstantNode;
  35 import org.graalvm.compiler.nodes.LogicNode;
  36 import org.graalvm.compiler.nodes.ValueNode;
  37 import org.graalvm.compiler.nodes.util.GraphUtil;
  38 
  39 import jdk.vm.ci.meta.ConstantReflectionProvider;
  40 import jdk.vm.ci.meta.TriState;
  41 
  42 @NodeInfo(shortName = "<", cycles = NodeCycles.CYCLES_3)
  43 public final class FloatLessThanNode extends CompareNode {
  44     public static final NodeClass<FloatLessThanNode> TYPE = NodeClass.create(FloatLessThanNode.class);
  45 
  46     public FloatLessThanNode(ValueNode x, ValueNode y, boolean unorderedIsTrue) {
  47         super(TYPE, Condition.LT, unorderedIsTrue, x, y);
  48         assert x.stamp() instanceof FloatStamp && y.stamp() instanceof FloatStamp;
  49         assert x.stamp().isCompatible(y.stamp());
  50     }
  51 
  52     public static LogicNode create(ValueNode x, ValueNode y, boolean unorderedIsTrue, ConstantReflectionProvider constantReflection) {
  53         LogicNode result = CompareNode.tryConstantFold(Condition.LT, x, y, constantReflection, unorderedIsTrue);
  54         if (result != null) {
  55             return result;
  56         } else {
  57             return new FloatLessThanNode(x, y, unorderedIsTrue);
  58         }
  59     }
  60 
  61     @Override
  62     public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
  63         ValueNode result = super.canonical(tool, forX, forY);
  64         if (result != this) {
  65             return result;
  66         }
  67         if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY) && !unorderedIsTrue()) {
  68             return LogicConstantNode.contradiction();
  69         }
  70         return this;
  71     }
  72 
  73     @Override
  74     protected CompareNode duplicateModified(ValueNode newX, ValueNode newY) {
  75         if (newX.stamp() instanceof FloatStamp && newY.stamp() instanceof FloatStamp) {
  76             return new FloatLessThanNode(newX, newY, unorderedIsTrue);
  77         } else if (newX.stamp() instanceof IntegerStamp && newY.stamp() instanceof IntegerStamp) {
  78             return new IntegerLessThanNode(newX, newY);
  79         }
  80         throw GraalError.shouldNotReachHere();
  81     }
  82 
  83     @Override
  84     public Stamp getSucceedingStampForX(boolean negated) {
  85         return null;
  86     }
  87 
  88     @Override
  89     public Stamp getSucceedingStampForY(boolean negated) {
  90         return null;
  91     }
  92 
  93     @Override
  94     public TriState tryFold(Stamp xStampGeneric, Stamp yStampGeneric) {
  95         return TriState.UNKNOWN;
  96     }
  97 }