Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java @ 12729:64d960e854e6
Canonicalize comparison of type conversion with constants.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 08 Nov 2013 16:59:01 +0100 |
parents | 4aec62c32a82 |
children | bb992a44734e |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. |
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:
5502
diff
changeset
|
25 import com.oracle.graal.api.meta.*; |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
26 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
|
27 import com.oracle.graal.graph.spi.*; |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
28 import com.oracle.graal.nodes.*; |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
29 import com.oracle.graal.nodes.spi.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 |
5056
2f2c6347fce4
comments cleanup/retagging
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4550
diff
changeset
|
31 /* TODO (thomaswue/gdub) For high-level optimization purpose the compare node should be a boolean *value* (it is currently only a helper node) |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 * But in the back-end the comparison should not always be materialized (for example in x86 the comparison result will not be in a register but in a flag) |
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 * Compare should probably be made a value (so that it can be canonicalized for example) and in later stages some Compare usage should be transformed |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 * into variants that do not materialize the value (CompareIf, CompareGuard...) |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 */ |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
37 public abstract class CompareNode extends LogicNode implements Canonicalizable, LIRLowerable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 @Input private ValueNode x; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 @Input private ValueNode y; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 public ValueNode x() { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 return x; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 public ValueNode y() { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 return y; |
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 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 * Constructs a new Compare instruction. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7098
diff
changeset
|
52 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 * @param x the instruction producing the first input to the instruction |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 * @param y the instruction that produces the second input to this instruction |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 */ |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
56 public CompareNode(ValueNode x, ValueNode y) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 assert (x == null && y == null) || x.kind() == y.kind(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 this.x = x; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 this.y = y; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 * Gets the condition (comparison operation) for this instruction. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7098
diff
changeset
|
64 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 * @return the condition |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 */ |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
67 public abstract Condition condition(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 /** |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
70 * Checks whether unordered inputs mean true or false (only applies to float operations). |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7098
diff
changeset
|
71 * |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 * @return {@code true} if unordered inputs produce true |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 */ |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
74 public abstract boolean unorderedIsTrue(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 @Override |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 public void generate(LIRGeneratorTool gen) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 |
12052
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
80 private LogicNode optimizeConditional(Constant constant, ConditionalNode conditionalNode, ConstantReflectionProvider constantReflection, Condition cond) { |
5660
3570883de730
generalized canonicalization of a compare node for inputs of type ConditionalNode
Doug Simon <doug.simon@oracle.com>
parents:
5541
diff
changeset
|
81 Constant trueConstant = conditionalNode.trueValue().asConstant(); |
3570883de730
generalized canonicalization of a compare node for inputs of type ConditionalNode
Doug Simon <doug.simon@oracle.com>
parents:
5541
diff
changeset
|
82 Constant falseConstant = conditionalNode.falseValue().asConstant(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 |
12052
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
84 if (falseConstant != null && trueConstant != null && constantReflection != null) { |
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
85 boolean trueResult = cond.foldCondition(trueConstant, constant, constantReflection, unorderedIsTrue()); |
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
86 boolean falseResult = cond.foldCondition(falseConstant, constant, constantReflection, unorderedIsTrue()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 |
6571
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
88 if (trueResult == falseResult) { |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
89 return LogicConstantNode.forBoolean(trueResult, graph()); |
6571
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
90 } else { |
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
91 if (trueResult) { |
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
92 assert falseResult == false; |
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
93 return conditionalNode.condition(); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 } else { |
6571
f182f58459fa
removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents:
5758
diff
changeset
|
95 assert falseResult == true; |
11409
1f302b6e16b0
Introduce LogicNegationNode and remove Negatable interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
9448
diff
changeset
|
96 return graph().unique(new LogicNegationNode(conditionalNode.condition())); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
98 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
99 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
101 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
103 |
9448
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
104 protected void setX(ValueNode x) { |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
105 updateUsages(this.x, x); |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
106 this.x = x; |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
107 } |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
108 |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
109 protected void setY(ValueNode y) { |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
110 updateUsages(this.y, y); |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
111 this.y = y; |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
112 } |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
113 |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
114 protected LogicNode optimizeNormalizeCmp(Constant constant, NormalizeCompareNode normalizeNode, boolean mirrored) { |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
115 throw new GraalInternalError("NormalizeCompareNode connected to %s (%s %s %s)", this, constant, normalizeNode, mirrored); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
116 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
117 |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
118 @Override |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11409
diff
changeset
|
119 public Node canonical(CanonicalizerTool tool) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
120 if (x().isConstant() && y().isConstant() && tool.getMetaAccess() != null) { |
12052
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
121 return LogicConstantNode.forBoolean(condition().foldCondition(x().asConstant(), y().asConstant(), tool.getConstantReflection(), unorderedIsTrue()), graph()); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
122 } |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
123 if (x().isConstant()) { |
5660
3570883de730
generalized canonicalization of a compare node for inputs of type ConditionalNode
Doug Simon <doug.simon@oracle.com>
parents:
5541
diff
changeset
|
124 if (y() instanceof ConditionalNode) { |
12052
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
125 return optimizeConditional(x().asConstant(), (ConditionalNode) y(), tool.getConstantReflection(), condition().mirror()); |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
126 } else if (y() instanceof NormalizeCompareNode) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
127 return optimizeNormalizeCmp(x().asConstant(), (NormalizeCompareNode) y(), true); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
128 } |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
129 } else if (y().isConstant()) { |
5660
3570883de730
generalized canonicalization of a compare node for inputs of type ConditionalNode
Doug Simon <doug.simon@oracle.com>
parents:
5541
diff
changeset
|
130 if (x() instanceof ConditionalNode) { |
12052
0afe7370260c
refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
131 return optimizeConditional(y().asConstant(), (ConditionalNode) x(), tool.getConstantReflection(), condition()); |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
132 } else if (x() instanceof NormalizeCompareNode) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5402
diff
changeset
|
133 return optimizeNormalizeCmp(y().asConstant(), (NormalizeCompareNode) x(), false); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
134 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
135 } |
9448
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
136 if (x() instanceof ConvertNode && y() instanceof ConvertNode) { |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
137 ConvertNode convertX = (ConvertNode) x(); |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
138 ConvertNode convertY = (ConvertNode) y(); |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12655
diff
changeset
|
139 if (convertX.isLossless() && convertY.isLossless()) { |
9448
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
140 setX(convertX.value()); |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
141 setY(convertY.value()); |
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
142 } |
12729
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
143 } else if (x() instanceof ConvertNode && y().isConstant()) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
144 ConvertNode convertX = (ConvertNode) x(); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
145 ConstantNode newY = canonicalConvertConstant(convertX, y().asConstant()); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
146 if (newY != null) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
147 setX(convertX.value()); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
148 setY(newY); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
149 } |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
150 } else if (y() instanceof ConvertNode && x().isConstant()) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
151 ConvertNode convertY = (ConvertNode) y(); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
152 ConstantNode newX = canonicalConvertConstant(convertY, x().asConstant()); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
153 if (newX != null) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
154 setX(newX); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
155 setY(convertY.value()); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
156 } |
9448
7b88c5e5cbd4
Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7767
diff
changeset
|
157 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
158 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
159 } |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
160 |
12729
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
161 private static ConstantNode canonicalConvertConstant(ConvertNode convert, Constant constant) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
162 if (convert.isLossless()) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
163 assert constant.getKind() == convert.getToKind(); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
164 Constant reverseConverted = ConvertNode.convert(convert.getToKind(), convert.getFromKind(), constant); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
165 if (convert.evalConst(reverseConverted).equals(constant)) { |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
166 return ConstantNode.forPrimitive(reverseConverted, convert.graph()); |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
167 } |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
168 } |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
169 return null; |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
170 } |
64d960e854e6
Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
12695
diff
changeset
|
171 |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
172 public static CompareNode createCompareNode(StructuredGraph graph, Condition condition, ValueNode x, ValueNode y) { |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
173 assert x.kind() == y.kind(); |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
174 assert condition.isCanonical() : "condition is not canonical: " + condition; |
12695
4aec62c32a82
Helper functions for identifying numeric kinds.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
175 assert !x.kind().isNumericFloat(); |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
176 |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
177 CompareNode comparison; |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
178 if (condition == Condition.EQ) { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6950
diff
changeset
|
179 if (x.kind() == Kind.Object) { |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
180 comparison = new ObjectEqualsNode(x, y); |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
181 } else { |
12695
4aec62c32a82
Helper functions for identifying numeric kinds.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
182 assert x.kind().isNumericInteger(); |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
183 comparison = new IntegerEqualsNode(x, y); |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
184 } |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
185 } else if (condition == Condition.LT) { |
12695
4aec62c32a82
Helper functions for identifying numeric kinds.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
186 assert x.kind().isNumericInteger(); |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
187 comparison = new IntegerLessThanNode(x, y); |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
188 } else { |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
189 assert condition == Condition.BT; |
12695
4aec62c32a82
Helper functions for identifying numeric kinds.
Roland Schatz <roland.schatz@oracle.com>
parents:
12656
diff
changeset
|
190 assert x.kind().isNumericInteger(); |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
191 comparison = new IntegerBelowThanNode(x, y); |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
192 } |
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
193 |
12655
2c4aa758ee18
made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
194 return graph.unique(comparison); |
6950
41938af2b3d8
modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents:
6571
diff
changeset
|
195 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 } |