43972
|
1 |
/*
|
52910
|
2 |
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.nodes.calc;
|
|
26 |
|
46393
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
|
|
28 |
|
48861
|
29 |
import org.graalvm.compiler.core.common.calc.CanonicalCondition;
|
43972
|
30 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
31 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
46459
|
32 |
import org.graalvm.compiler.graph.IterableNodeType;
|
43972
|
33 |
import org.graalvm.compiler.graph.NodeClass;
|
|
34 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
|
35 |
import org.graalvm.compiler.nodeinfo.NodeCycles;
|
|
36 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
37 |
import org.graalvm.compiler.nodes.ConstantNode;
|
|
38 |
import org.graalvm.compiler.nodes.LogicConstantNode;
|
|
39 |
import org.graalvm.compiler.nodes.LogicNode;
|
48190
|
40 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
41 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
42 |
|
|
43 |
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
|
44 |
import jdk.vm.ci.meta.JavaKind;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Returns -1, 0, or 1 if either x < y, x == y, or x > y. If the comparison is undecided (one
|
|
48 |
* of the inputs is NaN), the result is 1 if isUnorderedLess is false and -1 if isUnorderedLess is
|
|
49 |
* true.
|
|
50 |
*/
|
46393
|
51 |
@NodeInfo(cycles = NodeCycles.CYCLES_2, size = SIZE_2)
|
46459
|
52 |
public final class NormalizeCompareNode extends BinaryNode implements IterableNodeType {
|
43972
|
53 |
|
|
54 |
public static final NodeClass<NormalizeCompareNode> TYPE = NodeClass.create(NormalizeCompareNode.class);
|
|
55 |
protected final boolean isUnorderedLess;
|
|
56 |
|
46459
|
57 |
public NormalizeCompareNode(ValueNode x, ValueNode y, JavaKind kind, boolean isUnorderedLess) {
|
|
58 |
super(TYPE, StampFactory.forInteger(kind, -1, 1), x, y);
|
43972
|
59 |
this.isUnorderedLess = isUnorderedLess;
|
|
60 |
}
|
|
61 |
|
46459
|
62 |
public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
|
|
63 |
ValueNode result = tryConstantFold(x, y, isUnorderedLess, kind, constantReflection);
|
|
64 |
if (result != null) {
|
|
65 |
return result;
|
|
66 |
}
|
|
67 |
|
|
68 |
return new NormalizeCompareNode(x, y, kind, isUnorderedLess);
|
|
69 |
}
|
|
70 |
|
|
71 |
protected static ValueNode tryConstantFold(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
|
48861
|
72 |
LogicNode result = CompareNode.tryConstantFold(CanonicalCondition.EQ, x, y, null, false);
|
43972
|
73 |
if (result instanceof LogicConstantNode) {
|
|
74 |
LogicConstantNode logicConstantNode = (LogicConstantNode) result;
|
48861
|
75 |
LogicNode resultLT = CompareNode.tryConstantFold(CanonicalCondition.LT, x, y, constantReflection, isUnorderedLess);
|
43972
|
76 |
if (resultLT instanceof LogicConstantNode) {
|
|
77 |
LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
|
|
78 |
if (logicConstantNodeLT.getValue()) {
|
46459
|
79 |
return ConstantNode.forIntegerKind(kind, -1);
|
43972
|
80 |
} else if (logicConstantNode.getValue()) {
|
46459
|
81 |
return ConstantNode.forIntegerKind(kind, 0);
|
43972
|
82 |
} else {
|
46459
|
83 |
return ConstantNode.forIntegerKind(kind, 1);
|
43972
|
84 |
}
|
|
85 |
}
|
|
86 |
}
|
46459
|
87 |
return null;
|
43972
|
88 |
}
|
|
89 |
|
|
90 |
@Override
|
|
91 |
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
|
48190
|
92 |
NodeView view = NodeView.from(tool);
|
|
93 |
ValueNode result = tryConstantFold(x, y, isUnorderedLess, stamp(view).getStackKind(), tool.getConstantReflection());
|
46459
|
94 |
if (result != null) {
|
|
95 |
return result;
|
|
96 |
}
|
43972
|
97 |
return this;
|
|
98 |
}
|
|
99 |
|
|
100 |
@Override
|
|
101 |
public boolean inferStamp() {
|
|
102 |
return false;
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
public Stamp foldStamp(Stamp stampX, Stamp stampY) {
|
48190
|
107 |
return stamp(NodeView.DEFAULT);
|
43972
|
108 |
}
|
46459
|
109 |
|
|
110 |
public boolean isUnorderedLess() {
|
|
111 |
return isUnorderedLess;
|
|
112 |
}
|
43972
|
113 |
}
|