43972
|
1 |
/*
|
46344
|
2 |
* Copyright (c) 2011, 2017, 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 |
*/
|
|
23 |
package org.graalvm.compiler.nodes.calc;
|
|
24 |
|
46344
|
25 |
import org.graalvm.compiler.core.common.NumUtil;
|
48861
|
26 |
import org.graalvm.compiler.core.common.calc.CanonicalCondition;
|
43972
|
27 |
import org.graalvm.compiler.core.common.type.IntegerStamp;
|
|
28 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
46393
|
29 |
import org.graalvm.compiler.graph.Node;
|
43972
|
30 |
import org.graalvm.compiler.graph.NodeClass;
|
46393
|
31 |
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
|
43972
|
32 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
33 |
import org.graalvm.compiler.nodes.LogicNode;
|
48190
|
34 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
35 |
import org.graalvm.compiler.nodes.ValueNode;
|
48861
|
36 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
37 |
|
|
38 |
import jdk.vm.ci.code.CodeUtil;
|
48861
|
39 |
import jdk.vm.ci.meta.ConstantReflectionProvider;
|
|
40 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
43972
|
41 |
|
|
42 |
@NodeInfo(shortName = "|<|")
|
46344
|
43 |
public final class IntegerBelowNode extends IntegerLowerThanNode {
|
43972
|
44 |
public static final NodeClass<IntegerBelowNode> TYPE = NodeClass.create(IntegerBelowNode.class);
|
46344
|
45 |
private static final BelowOp OP = new BelowOp();
|
43972
|
46 |
|
|
47 |
public IntegerBelowNode(ValueNode x, ValueNode y) {
|
46344
|
48 |
super(TYPE, x, y, OP);
|
48190
|
49 |
assert x.stamp(NodeView.DEFAULT) instanceof IntegerStamp;
|
|
50 |
assert y.stamp(NodeView.DEFAULT) instanceof IntegerStamp;
|
43972
|
51 |
}
|
|
52 |
|
48190
|
53 |
public static LogicNode create(ValueNode x, ValueNode y, NodeView view) {
|
|
54 |
return OP.create(x, y, view);
|
43972
|
55 |
}
|
|
56 |
|
48190
|
57 |
public static LogicNode create(ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess, OptionValues options, Integer smallestCompareWidth, ValueNode x, ValueNode y,
|
|
58 |
NodeView view) {
|
|
59 |
LogicNode value = OP.canonical(constantReflection, metaAccess, options, smallestCompareWidth, OP.getCondition(), false, x, y, view);
|
46393
|
60 |
if (value != null) {
|
|
61 |
return value;
|
|
62 |
}
|
48190
|
63 |
return create(x, y, view);
|
46393
|
64 |
}
|
|
65 |
|
43972
|
66 |
@Override
|
46393
|
67 |
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
|
48190
|
68 |
NodeView view = NodeView.from(tool);
|
|
69 |
ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), OP.getCondition(), false, forX, forY, view);
|
46393
|
70 |
if (value != null) {
|
|
71 |
return value;
|
|
72 |
}
|
|
73 |
return this;
|
43972
|
74 |
}
|
|
75 |
|
46344
|
76 |
public static class BelowOp extends LowerOp {
|
46393
|
77 |
@Override
|
48190
|
78 |
protected CompareNode duplicateModified(ValueNode newX, ValueNode newY, boolean unorderedIsTrue, NodeView view) {
|
|
79 |
assert newX.stamp(NodeView.DEFAULT) instanceof IntegerStamp && newY.stamp(NodeView.DEFAULT) instanceof IntegerStamp;
|
46393
|
80 |
return new IntegerBelowNode(newX, newY);
|
|
81 |
}
|
46344
|
82 |
|
|
83 |
@Override
|
|
84 |
protected long upperBound(IntegerStamp stamp) {
|
|
85 |
return stamp.unsignedUpperBound();
|
|
86 |
}
|
|
87 |
|
|
88 |
@Override
|
|
89 |
protected long lowerBound(IntegerStamp stamp) {
|
|
90 |
return stamp.unsignedLowerBound();
|
43972
|
91 |
}
|
46344
|
92 |
|
|
93 |
@Override
|
|
94 |
protected int compare(long a, long b) {
|
|
95 |
return Long.compareUnsigned(a, b);
|
|
96 |
}
|
|
97 |
|
|
98 |
@Override
|
|
99 |
protected long min(long a, long b) {
|
|
100 |
return NumUtil.minUnsigned(a, b);
|
|
101 |
}
|
|
102 |
|
|
103 |
@Override
|
|
104 |
protected long max(long a, long b) {
|
|
105 |
return NumUtil.maxUnsigned(a, b);
|
|
106 |
}
|
43972
|
107 |
|
46344
|
108 |
@Override
|
|
109 |
protected long cast(long a, int bits) {
|
|
110 |
return CodeUtil.zeroExtend(a, bits);
|
|
111 |
}
|
|
112 |
|
|
113 |
@Override
|
|
114 |
protected long minValue(int bits) {
|
|
115 |
return 0;
|
|
116 |
}
|
|
117 |
|
|
118 |
@Override
|
|
119 |
protected long maxValue(int bits) {
|
|
120 |
return NumUtil.maxValueUnsigned(bits);
|
43972
|
121 |
}
|
46344
|
122 |
|
|
123 |
@Override
|
|
124 |
protected IntegerStamp forInteger(int bits, long min, long max) {
|
|
125 |
return StampFactory.forUnsignedInteger(bits, min, max);
|
|
126 |
}
|
43972
|
127 |
|
46344
|
128 |
@Override
|
48861
|
129 |
protected CanonicalCondition getCondition() {
|
|
130 |
return CanonicalCondition.BT;
|
43972
|
131 |
}
|
46344
|
132 |
|
|
133 |
@Override
|
46371
|
134 |
protected IntegerLowerThanNode createNode(ValueNode x, ValueNode y) {
|
46344
|
135 |
return new IntegerBelowNode(x, y);
|
|
136 |
}
|
43972
|
137 |
}
|
|
138 |
}
|