annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/NormalizeCompareNode.java @ 19526:8fc336a04d77

Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 20 Feb 2015 22:22:55 +0100
parents 61d3cb8e1280
children 48c1ebd24120
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes.calc;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
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.*;
19379
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
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: 14906
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: 19379
diff changeset
28 import com.oracle.graal.graph.*;
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
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.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.nodes.spi.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 /**
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14024
diff changeset
35 * Returns -1, 0, or 1 if either x &lt; y, x == y, or x &gt; y. If the comparison is undecided (one
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14024
diff changeset
36 * of the inputs is NaN), the result is 1 if isUnorderedLess is false and -1 if isUnorderedLess is
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14024
diff changeset
37 * true.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16217
diff changeset
39 @NodeInfo
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19379
diff changeset
40 public final class NormalizeCompareNode extends BinaryNode implements Lowerable {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7098
diff changeset
41
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
42 public static final NodeClass<NormalizeCompareNode> TYPE = NodeClass.create(NormalizeCompareNode.class);
17328
c9bb0da795d4 Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents: 17327
diff changeset
43 protected final boolean isUnorderedLess;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
45 public NormalizeCompareNode(ValueNode x, ValueNode y, boolean isUnorderedLess) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19379
diff changeset
46 super(TYPE, StampFactory.forKind(Kind.Int), x, y);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 this.isUnorderedLess = isUnorderedLess;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
19379
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
50 public static ValueNode create(ValueNode x, ValueNode y, boolean isUnorderedLess, ConstantReflectionProvider constantReflection) {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
51 LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, constantReflection, false);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
52 if (result instanceof LogicConstantNode) {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
53 LogicConstantNode logicConstantNode = (LogicConstantNode) result;
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
54 LogicNode resultLT = CompareNode.tryConstantFold(Condition.LT, x, y, constantReflection, isUnorderedLess);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
55 if (resultLT instanceof LogicConstantNode) {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
56 LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
57 if (logicConstantNodeLT.getValue()) {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
58 return ConstantNode.forInt(-1);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
59 } else if (logicConstantNode.getValue()) {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
60 return ConstantNode.forInt(0);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
61 } else {
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
62 return ConstantNode.forInt(1);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
63 }
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
64 }
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
65 }
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
66
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
67 return new NormalizeCompareNode(x, y, isUnorderedLess);
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
68 }
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
69
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 @Override
16217
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
71 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
72 // nothing to do
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
73 return this;
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
74 }
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
75
561070049e73 implement Canonicalizable.Binary in the BinaryNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
76 @Override
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
77 public void lower(LoweringTool tool) {
7767
4a6646d8eb87 separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7724
diff changeset
78 LogicNode equalComp;
4a6646d8eb87 separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7724
diff changeset
79 LogicNode lessComp;
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
80 if (getX().stamp() instanceof FloatStamp) {
19116
7227f5671c87 Prototype for folding object equality at parse time.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
81 equalComp = graph().unique(FloatEqualsNode.create(getX(), getY(), tool.getConstantReflection()));
19379
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
82 lessComp = graph().unique(FloatLessThanNode.create(getX(), getY(), isUnorderedLess, tool.getConstantReflection()));
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5299
diff changeset
83 } else {
19379
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
84 equalComp = graph().unique(IntegerEqualsNode.create(getX(), getY(), tool.getConstantReflection()));
b720a1e02fa0 Add graph building time canonicalization for NormalizeCompareNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
85 lessComp = graph().unique(IntegerLessThanNode.create(getX(), getY(), tool.getConstantReflection()));
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5299
diff changeset
86 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5299
diff changeset
87
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
88 ConditionalNode equalValue = graph().unique(new ConditionalNode(equalComp, ConstantNode.forInt(0, graph()), ConstantNode.forInt(1, graph())));
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
89 ConditionalNode value = graph().unique(new ConditionalNode(lessComp, ConstantNode.forInt(-1, graph()), equalValue));
4550
e065aa86d077 Lower NormalizeCompareNode in the front end to avoid LIR operation.
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4199
diff changeset
90
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9251
diff changeset
91 graph().replaceFloating(this, value);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }