annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java @ 19403:61d3cb8e1280

Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 17:47:43 +0100
parents 7e2c87dae93e
children 8fc336a04d77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.nodes.calc;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
19170
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
25 import com.oracle.graal.api.meta.*;
15200
97eed257999b Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 14633
diff changeset
26 import com.oracle.graal.compiler.common.calc.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15200
diff changeset
27 import com.oracle.graal.compiler.common.type.*;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
28 import com.oracle.graal.graph.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
29 import com.oracle.graal.graph.spi.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16822
diff changeset
30 import com.oracle.graal.nodeinfo.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
32 import com.oracle.graal.nodes.util.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 @NodeInfo(shortName = "|<|")
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
35 public final class IntegerBelowNode extends CompareNode {
19403
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19396
diff changeset
36 public static final NodeClass<IntegerBelowNode> TYPE = NodeClass.get(IntegerBelowNode.class);
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
38 public IntegerBelowNode(ValueNode x, ValueNode y) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
39 super(TYPE, Condition.BT, false, x, y);
15975
0ad889977080 CompareNode.canonicalizeSymmetricConstant can lead to float<->int changes so the right type of node needs to be created depending on the inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15961
diff changeset
40 assert x.stamp() instanceof IntegerStamp;
0ad889977080 CompareNode.canonicalizeSymmetricConstant can lead to float<->int changes so the right type of node needs to be created depending on the inputs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15961
diff changeset
41 assert y.stamp() instanceof IntegerStamp;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
19170
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
44 public static LogicNode create(ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) {
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
45 LogicNode result = CompareNode.tryConstantFold(Condition.BT, x, y, constantReflection, false);
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
46 if (result != null) {
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
47 return result;
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
48 } else {
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
49 result = findSynonym(x, y);
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
50 if (result != null) {
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
51 return result;
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
52 }
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
53 return new IntegerBelowNode(x, y);
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
54 }
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
55 }
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
56
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 @Override
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
58 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
59 ValueNode result = super.canonical(tool, forX, forY);
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
60 if (result != this) {
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
61 return result;
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
62 }
19170
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
63 LogicNode synonym = findSynonym(forX, forY);
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
64 if (synonym != null) {
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
65 return synonym;
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
66 }
19174
c154b12465d2 Fix method IntegerBelowNode#findSynonym.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19170
diff changeset
67 if (forX.isConstant() && forX.asJavaConstant().asLong() == 0) {
c154b12465d2 Fix method IntegerBelowNode#findSynonym.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19170
diff changeset
68 // 0 |<| y is the same as 0 != y
19373
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
69 return LogicNegationNode.create(CompareNode.createCompareNode(Condition.EQ, forX, forY, tool.getConstantReflection()));
19174
c154b12465d2 Fix method IntegerBelowNode#findSynonym.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19170
diff changeset
70 }
19170
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
71 return this;
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
72 }
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
73
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
74 private static LogicNode findSynonym(ValueNode forX, ValueNode forY) {
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
75 if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
76 return LogicConstantNode.contradiction();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
77 } else if (forX.stamp() instanceof IntegerStamp && forY.stamp() instanceof IntegerStamp) {
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
78 IntegerStamp xStamp = (IntegerStamp) forX.stamp();
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
79 IntegerStamp yStamp = (IntegerStamp) forY.stamp();
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
80 if (yStamp.isPositive()) {
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
81 if (xStamp.isPositive() && xStamp.upperBound() < yStamp.lowerBound()) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
82 return LogicConstantNode.tautology();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
83 } else if (xStamp.isStrictlyNegative() || xStamp.lowerBound() >= yStamp.upperBound()) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
84 return LogicConstantNode.contradiction();
5443
141817e206d4 changes to the dependencies and stamp system:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5425
diff changeset
85 }
141817e206d4 changes to the dependencies and stamp system:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5425
diff changeset
86 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 }
19170
3b2e98f9e47c Initial prototype for loop explosion during graph building.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
88 return null;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
89 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
90
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
91 @Override
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
92 protected CompareNode duplicateModified(ValueNode newX, ValueNode newY) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
93 return new IntegerBelowNode(newX, newY);
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
94 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
95 }