annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FloatEqualsNode.java @ 16212:51c7c676d41a

implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
author Lukas Stadler <lukas.stadler@oracle.com>
date Wed, 25 Jun 2014 11:21:44 +0200
parents 66a9286203a2
children 5d468add216f
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 /*
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
2 * Copyright (c) 2011, 2014, 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
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
25 import com.oracle.graal.compiler.common.*;
15200
97eed257999b Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 14024
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.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28 import com.oracle.graal.graph.*;
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
29 import com.oracle.graal.graph.spi.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 import com.oracle.graal.nodes.*;
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
31 import com.oracle.graal.nodes.util.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 @NodeInfo(shortName = "==")
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 public final class FloatEqualsNode extends CompareNode {
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 /**
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37 * Constructs a new floating point equality comparison node.
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
38 *
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39 * @param x the instruction producing the first input to the instruction
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 * @param y the instruction that produces the second input to this instruction
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 */
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42 public FloatEqualsNode(ValueNode x, ValueNode y) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43 super(x, y);
16006
66a9286203a2 decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents: 15975
diff changeset
44 assert x.stamp() instanceof FloatStamp && y.stamp() instanceof FloatStamp : x.stamp() + " " + y.stamp();
14024
34c07ef28bc9 Support integer arithmetic for arbitrary types.
Roland Schatz <roland.schatz@oracle.com>
parents: 7530
diff changeset
45 assert x.stamp().isCompatible(y.stamp());
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 @Override
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 public Condition condition() {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 return Condition.EQ;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53 @Override
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 public boolean unorderedIsTrue() {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55 return false;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 }
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
57
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
58 @Override
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
59 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
60 ValueNode result = super.canonical(tool, forX, forY);
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
61 if (result != this) {
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
62 return result;
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
63 }
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
64 if (forX.stamp() instanceof FloatStamp && forY.stamp() instanceof FloatStamp) {
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
65 FloatStamp xStamp = (FloatStamp) forX.stamp();
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
66 FloatStamp yStamp = (FloatStamp) forY.stamp();
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
67 if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY) && xStamp.isNonNaN() && yStamp.isNonNaN()) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
68 return LogicConstantNode.tautology();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
69 } else if (xStamp.alwaysDistinct(yStamp)) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
70 return LogicConstantNode.contradiction();
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
71 }
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
72 }
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16006
diff changeset
73 return this;
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
74 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
75
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
76 @Override
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
77 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
78 if (newX.stamp() instanceof FloatStamp && newY.stamp() instanceof FloatStamp) {
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
79 return new FloatEqualsNode(newX, newY);
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
80 } else if (newX.stamp() instanceof IntegerStamp && newY.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
81 return new IntegerEqualsNode(newX, newY);
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
82 }
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
83 throw GraalInternalError.shouldNotReachHere();
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15349
diff changeset
84 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
85 }