58299
|
1 |
/*
|
|
2 |
* Copyright (c) 2009, 2018, 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 |
|
|
24 |
|
|
25 |
package org.graalvm.compiler.nodes.calc;
|
|
26 |
|
|
27 |
import org.graalvm.compiler.graph.NodeClass;
|
|
28 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
|
29 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
30 |
import org.graalvm.compiler.nodes.LogicNode;
|
|
31 |
import org.graalvm.compiler.nodes.NodeView;
|
|
32 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
33 |
import org.graalvm.compiler.options.OptionValues;
|
|
34 |
|
|
35 |
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
|
36 |
import jdk.vm.ci.meta.JavaKind;
|
|
37 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* If the comparison is undecided (one of the inputs is NaN), the result is 1 if isUnorderedLess is
|
|
41 |
* false and -1 if isUnorderedLess is true.
|
|
42 |
*/
|
|
43 |
@NodeInfo
|
|
44 |
public final class FloatNormalizeCompareNode extends AbstractNormalizeCompareNode {
|
|
45 |
public static final NodeClass<FloatNormalizeCompareNode> TYPE = NodeClass.create(FloatNormalizeCompareNode.class);
|
|
46 |
protected final boolean isUnorderedLess;
|
|
47 |
|
|
48 |
public FloatNormalizeCompareNode(ValueNode x, ValueNode y, JavaKind kind, boolean isUnorderedLess) {
|
|
49 |
super(TYPE, kind, x, y);
|
|
50 |
this.isUnorderedLess = isUnorderedLess;
|
|
51 |
}
|
|
52 |
|
|
53 |
public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
|
|
54 |
ValueNode result = tryConstantFold(x, y, isUnorderedLess, false, kind, constantReflection);
|
|
55 |
if (result != null) {
|
|
56 |
return result;
|
|
57 |
}
|
|
58 |
|
|
59 |
return new FloatNormalizeCompareNode(x, y, kind, isUnorderedLess);
|
|
60 |
}
|
|
61 |
|
|
62 |
@Override
|
|
63 |
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
|
|
64 |
NodeView view = NodeView.from(tool);
|
|
65 |
ValueNode result = tryConstantFold(x, y, isUnorderedLess, false, stamp(view).getStackKind(), tool.getConstantReflection());
|
|
66 |
if (result != null) {
|
|
67 |
return result;
|
|
68 |
}
|
|
69 |
return this;
|
|
70 |
}
|
|
71 |
|
|
72 |
public boolean isUnorderedLess() {
|
|
73 |
return isUnorderedLess;
|
|
74 |
}
|
|
75 |
|
|
76 |
@Override
|
|
77 |
public LogicNode createEqualComparison() {
|
|
78 |
return FloatEqualsNode.create(x, y, NodeView.DEFAULT);
|
|
79 |
}
|
|
80 |
|
|
81 |
@Override
|
|
82 |
public LogicNode createEqualComparison(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth, NodeView view) {
|
|
83 |
return FloatEqualsNode.create(constantReflection, metaAccess, options, smallestCompareWidth, x, y, NodeView.DEFAULT);
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
public LogicNode createLowerComparison(boolean swapInputs) {
|
|
88 |
ValueNode a = swapInputs ? y : x;
|
|
89 |
ValueNode b = swapInputs ? x : y;
|
|
90 |
return FloatLessThanNode.create(a, b, isUnorderedLess() ^ swapInputs, NodeView.DEFAULT);
|
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
public LogicNode createLowerComparison(boolean swapInputs, ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth,
|
|
95 |
NodeView view) {
|
|
96 |
ValueNode a = swapInputs ? y : x;
|
|
97 |
ValueNode b = swapInputs ? x : y;
|
|
98 |
return FloatLessThanNode.create(constantReflection, metaAccess, options, smallestCompareWidth, a, b, isUnorderedLess() ^ swapInputs, NodeView.DEFAULT);
|
|
99 |
}
|
|
100 |
}
|