annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java @ 21455:ddc5350fe1ab

Handle AbstractPointerStamp in duplicateModified
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Mon, 18 May 2015 14:30:03 -0700
parents d30a0545ddc2
children 93c50cefb9e8
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 /*
18839
1b7dbb81df4f Use ArithmeticOpTable for shift operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 18188
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
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5504
diff changeset
25 import com.oracle.graal.api.meta.*;
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
26 import com.oracle.graal.compiler.common.*;
15200
97eed257999b Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 14711
diff changeset
27 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
28 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
29 import com.oracle.graal.graph.*;
19602
d5042bcd422f Remove isCommutative method from BinaryCommutative interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 19577
diff changeset
30 import com.oracle.graal.graph.spi.Canonicalizable.BinaryCommutative;
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
31 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
32 import com.oracle.graal.nodeinfo.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 import com.oracle.graal.nodes.*;
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
34 import com.oracle.graal.nodes.util.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 @NodeInfo(shortName = "==")
19602
d5042bcd422f Remove isCommutative method from BinaryCommutative interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 19577
diff changeset
37 public final class IntegerEqualsNode extends CompareNode implements BinaryCommutative<ValueNode> {
19526
8fc336a04d77 Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19403
diff changeset
38 public static final NodeClass<IntegerEqualsNode> TYPE = NodeClass.create(IntegerEqualsNode.class);
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
40 public IntegerEqualsNode(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
41 super(TYPE, Condition.EQ, false, x, y);
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 12695
diff changeset
42 assert !x.getKind().isNumericFloat() && x.getKind() != Kind.Object;
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 12695
diff changeset
43 assert !y.getKind().isNumericFloat() && y.getKind() != Kind.Object;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45
19147
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
46 public static LogicNode create(ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) {
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
47 LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, constantReflection, false);
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
48 if (result != null) {
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
49 return result;
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
50 } else {
19373
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
51 if (x instanceof ConditionalNode) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
52 ConditionalNode conditionalNode = (ConditionalNode) x;
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
53 if (conditionalNode.trueValue() == y) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
54 return conditionalNode.condition();
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
55 }
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
56 if (conditionalNode.falseValue() == y) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
57 return LogicNegationNode.create(conditionalNode.condition());
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
58 }
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
59 } else if (y instanceof ConditionalNode) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
60 ConditionalNode conditionalNode = (ConditionalNode) y;
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
61 if (conditionalNode.trueValue() == x) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
62 return conditionalNode.condition();
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
63 }
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
64 if (conditionalNode.falseValue() == x) {
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
65 return LogicNegationNode.create(conditionalNode.condition());
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
66 }
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
67 }
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19147
diff changeset
68
19575
b017118b412b Ensure a canonical ordering of inputs for commutative binary operations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19403
diff changeset
69 return new IntegerEqualsNode(x, y).maybeCommuteInputs();
19147
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
70 }
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
71 }
609480dfa0d8 Create ExplodeLoop plugin prototype. Special sort for blocks from bci block map builder for explode loop methods. Graph builder plugin for customizing static field accesses. New Truffle option TruffleExcludeAssertions default true that excludes assertion code from being partial evaluated in the new partial evaluator.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
72
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
73 @Override
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
74 protected ValueNode optimizeNormalizeCmp(Constant constant, NormalizeCompareNode normalizeNode, boolean mirrored) {
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
75 PrimitiveConstant primitive = (PrimitiveConstant) constant;
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
76 if (primitive.getKind() == Kind.Int && primitive.asInt() == 0) {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
77 ValueNode a = mirrored ? normalizeNode.getY() : normalizeNode.getX();
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
78 ValueNode b = mirrored ? normalizeNode.getX() : normalizeNode.getY();
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
79
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
80 if (normalizeNode.getX().getKind() == Kind.Double || normalizeNode.getX().getKind() == Kind.Float) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
81 return new FloatEqualsNode(a, b);
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
82 } else {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
83 return new IntegerEqualsNode(a, b);
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
84 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
85 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
86 return this;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
88
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
89 @Override
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
90 protected CompareNode duplicateModified(ValueNode newX, ValueNode newY) {
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
91 if (newX.stamp() instanceof FloatStamp && newY.stamp() instanceof FloatStamp) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
92 return new FloatEqualsNode(newX, newY);
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
93 } else if (newX.stamp() instanceof IntegerStamp && newY.stamp() instanceof IntegerStamp) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
94 return new IntegerEqualsNode(newX, newY);
21455
ddc5350fe1ab Handle AbstractPointerStamp in duplicateModified
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19718
diff changeset
95 } else if (newX.stamp() instanceof AbstractPointerStamp && newY.stamp() instanceof AbstractPointerStamp) {
ddc5350fe1ab Handle AbstractPointerStamp in duplicateModified
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 19718
diff changeset
96 return new IntegerEqualsNode(newX, newY);
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
97 }
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
98 throw GraalInternalError.shouldNotReachHere();
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
99 }
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
100
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
101 @Override
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
102 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
103 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
104 return LogicConstantNode.tautology();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
105 } else if (forX.stamp().alwaysDistinct(forY.stamp())) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
106 return LogicConstantNode.contradiction();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
107 }
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
108 return super.canonical(tool, forX, forY);
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
109 }
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
110
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
111 @Override
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
112 protected ValueNode canonicalizeSymmetricConstant(CanonicalizerTool tool, Constant constant, ValueNode nonConstant, boolean mirrored) {
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
113 if (constant instanceof PrimitiveConstant && ((PrimitiveConstant) constant).asLong() == 0) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
114 if (nonConstant instanceof AndNode) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
115 AndNode andNode = (AndNode) nonConstant;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
116 return new IntegerTestNode(andNode.getX(), andNode.getY());
18839
1b7dbb81df4f Use ArithmeticOpTable for shift operations.
Roland Schatz <roland.schatz@oracle.com>
parents: 18188
diff changeset
117 } else if (nonConstant instanceof ShiftNode && nonConstant.stamp() instanceof IntegerStamp) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
118 if (nonConstant instanceof LeftShiftNode) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
119 LeftShiftNode shift = (LeftShiftNode) nonConstant;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
120 if (shift.getY().isConstant()) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
121 int mask = shift.getShiftAmountMask();
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 17450
diff changeset
122 int amount = shift.getY().asJavaConstant().asInt() & mask;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
123 if (shift.getX().getKind() == Kind.Int) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
124 return new IntegerTestNode(shift.getX(), ConstantNode.forInt(-1 >>> amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
125 } else {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
126 assert shift.getX().getKind() == Kind.Long;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
127 return new IntegerTestNode(shift.getX(), ConstantNode.forLong(-1L >>> amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
128 }
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
129 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
130 } else if (nonConstant instanceof RightShiftNode) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
131 RightShiftNode shift = (RightShiftNode) nonConstant;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
132 if (shift.getY().isConstant() && ((IntegerStamp) shift.getX().stamp()).isPositive()) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
133 int mask = shift.getShiftAmountMask();
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 17450
diff changeset
134 int amount = shift.getY().asJavaConstant().asInt() & mask;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
135 if (shift.getX().getKind() == Kind.Int) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
136 return new IntegerTestNode(shift.getX(), ConstantNode.forInt(-1 << amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
137 } else {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
138 assert shift.getX().getKind() == Kind.Long;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
139 return new IntegerTestNode(shift.getX(), ConstantNode.forLong(-1L << amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
140 }
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
141 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
142 } else if (nonConstant instanceof UnsignedRightShiftNode) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
143 UnsignedRightShiftNode shift = (UnsignedRightShiftNode) nonConstant;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
144 if (shift.getY().isConstant()) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
145 int mask = shift.getShiftAmountMask();
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 17450
diff changeset
146 int amount = shift.getY().asJavaConstant().asInt() & mask;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
147 if (shift.getX().getKind() == Kind.Int) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
148 return new IntegerTestNode(shift.getX(), ConstantNode.forInt(-1 << amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
149 } else {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15975
diff changeset
150 assert shift.getX().getKind() == Kind.Long;
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18839
diff changeset
151 return new IntegerTestNode(shift.getX(), ConstantNode.forLong(-1L << amount));
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
152 }
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
153 }
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
154 }
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
155 }
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
156 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
157 return super.canonicalizeSymmetricConstant(tool, constant, nonConstant, mirrored);
14711
ba4b79da6351 canonicalize certain shift-compare expressions
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14633
diff changeset
158 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
159
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
160 @Override
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
161 public Stamp getSucceedingStampForX(boolean negated) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
162 if (!negated) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
163 return getX().stamp().join(getY().stamp());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
164 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
165 return null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
166 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
167
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
168 @Override
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
169 public Stamp getSucceedingStampForY(boolean negated) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
170 if (!negated) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
171 return getX().stamp().join(getY().stamp());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
172 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
173 return null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
174 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
175
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
176 @Override
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
177 public TriState tryFold(Stamp xStampGeneric, Stamp yStampGeneric) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
178 if (xStampGeneric instanceof IntegerStamp && yStampGeneric instanceof IntegerStamp) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
179 IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
180 IntegerStamp yStamp = (IntegerStamp) yStampGeneric;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
181 if (xStamp.alwaysDistinct(yStamp)) {
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
182 return TriState.FALSE;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
183 } else if (xStamp.neverDistinct(yStamp)) {
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
184 return TriState.TRUE;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
185 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
186 }
19718
d30a0545ddc2 Fixes after tryFold signature change.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19717
diff changeset
187 return TriState.UNKNOWN;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19602
diff changeset
188 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
189 }