annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java @ 21543:93c50cefb9e8

moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Mon, 25 May 2015 23:30:34 +0200
parents d5042bcd422f
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 /*
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
2 * Copyright (c) 2011, 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: 5502
diff changeset
25 import com.oracle.graal.api.meta.*;
15200
97eed257999b Move Condition to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15193
diff changeset
26 import com.oracle.graal.compiler.common.calc.*;
18360
6a5dc0bbebe7 Introduce PointerEqualsNode for metaspace pointer comparison.
Roland Schatz <roland.schatz@oracle.com>
parents: 18188
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: 19376
diff changeset
28 import com.oracle.graal.graph.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11880
diff changeset
29 import com.oracle.graal.graph.spi.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16822
diff changeset
30 import com.oracle.graal.nodeinfo.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5402
diff changeset
31 import com.oracle.graal.nodes.*;
21543
93c50cefb9e8 moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 19602
diff changeset
32 import com.oracle.jvmci.common.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
5056
2f2c6347fce4 comments cleanup/retagging
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4550
diff changeset
34 /* 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
35 * 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
36 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 * 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
38 * 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
39 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16601
diff changeset
40 @NodeInfo
19602
d5042bcd422f Remove isCommutative method from BinaryCommutative interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 19600
diff changeset
41 public abstract class CompareNode extends BinaryOpLogicNode implements Canonicalizable.Binary<ValueNode> {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
19526
8fc336a04d77 Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19471
diff changeset
43 public static final NodeClass<CompareNode> TYPE = NodeClass.create(CompareNode.class);
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
44 protected final Condition condition;
19115
1d33f713897d More restructuring of CompareNode. Move unorderedIsTrue flag to a field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19114
diff changeset
45 protected final boolean unorderedIsTrue;
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
46
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 * Constructs a new Compare instruction.
15184
94874b2fc509 common superclass for binary logic nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14950
diff changeset
49 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 * @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
51 * @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
52 */
19471
880717e44675 Use typed NodeClass in node constructors.
Roland Schatz <roland.schatz@oracle.com>
parents: 19403
diff changeset
53 protected CompareNode(NodeClass<? extends CompareNode> c, Condition condition, boolean unorderedIsTrue, ValueNode x, ValueNode y) {
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19376
diff changeset
54 super(c, x, y);
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
55 this.condition = condition;
19115
1d33f713897d More restructuring of CompareNode. Move unorderedIsTrue flag to a field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19114
diff changeset
56 this.unorderedIsTrue = unorderedIsTrue;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 * Gets the condition (comparison operation) for this instruction.
15184
94874b2fc509 common superclass for binary logic nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14950
diff changeset
61 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 * @return the condition
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 */
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
64 public final Condition condition() {
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
65 return condition;
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
66 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 /**
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5402
diff changeset
69 * Checks whether unordered inputs mean true or false (only applies to float operations).
15184
94874b2fc509 common superclass for binary logic nodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14950
diff changeset
70 *
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 * @return {@code true} if unordered inputs produce true
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 */
19115
1d33f713897d More restructuring of CompareNode. Move unorderedIsTrue flag to a field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19114
diff changeset
73 public final boolean unorderedIsTrue() {
1d33f713897d More restructuring of CompareNode. Move unorderedIsTrue flag to a field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19114
diff changeset
74 return this.unorderedIsTrue;
1d33f713897d More restructuring of CompareNode. Move unorderedIsTrue flag to a field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19114
diff changeset
75 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
77 private ValueNode optimizeConditional(Constant constant, ConditionalNode conditionalNode, ConstantReflectionProvider constantReflection, Condition cond) {
18487
0f4813e0b4a9 Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 18360
diff changeset
78 Constant trueConstant = conditionalNode.trueValue().asConstant();
0f4813e0b4a9 Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 18360
diff changeset
79 Constant falseConstant = conditionalNode.falseValue().asConstant();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80
12052
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
81 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
82 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
83 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
84
6571
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
85 if (trueResult == falseResult) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
86 return LogicConstantNode.forBoolean(trueResult);
6571
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
87 } else {
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
88 if (trueResult) {
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
89 assert falseResult == false;
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
90 return conditionalNode.condition();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 } else {
6571
f182f58459fa removed unnecessary boxing
Doug Simon <doug.simon@oracle.com>
parents: 5758
diff changeset
92 assert falseResult == true;
19373
03adf6499fee Better graph building time canonicalizations for logical negation and conditional node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19241
diff changeset
93 return LogicNegationNode.create(conditionalNode.condition());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 }
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 return this;
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
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
101 protected ValueNode optimizeNormalizeCmp(Constant constant, NormalizeCompareNode normalizeNode, boolean mirrored) {
21543
93c50cefb9e8 moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 19602
diff changeset
102 throw new JVMCIError("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
103 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104
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
105 @Override
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
106 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
107 ConstantReflectionProvider constantReflection = tool.getConstantReflection();
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
108 LogicNode constantCondition = tryConstantFold(condition(), forX, forY, constantReflection, unorderedIsTrue());
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
109 if (constantCondition != null) {
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
110 return constantCondition;
15349
7766f486f5d6 evaluate for BinaryOpLogicNodes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15348
diff changeset
111 }
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
112 ValueNode result;
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
113 if (forX.isConstant()) {
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
114 if ((result = canonicalizeSymmetricConstant(tool, forX.asConstant(), forY, true)) != this) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
115 return result;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116 }
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
117 } else if (forY.isConstant()) {
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
118 if ((result = canonicalizeSymmetricConstant(tool, forY.asConstant(), forX, false)) != this) {
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
119 return result;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 }
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
121 } else if (forX instanceof ConvertNode && forY instanceof ConvertNode) {
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
122 ConvertNode convertX = (ConvertNode) forX;
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
123 ConvertNode convertY = (ConvertNode) forY;
16156
0993768dfc8e new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15979
diff changeset
124 if (convertX.preservesOrder(condition()) && convertY.preservesOrder(condition()) && convertX.getValue().stamp().isCompatible(convertY.getValue().stamp())) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
125 return duplicateModified(convertX.getValue(), convertY.getValue());
9448
7b88c5e5cbd4 Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7767
diff changeset
126 }
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
127 }
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
128 return this;
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
129 }
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
130
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
131 public static LogicNode tryConstantFold(Condition condition, ValueNode forX, ValueNode forY, ConstantReflectionProvider constantReflection, boolean unorderedIsTrue) {
19116
7227f5671c87 Prototype for folding object equality at parse time.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
132 if (forX.isConstant() && forY.isConstant() && constantReflection != null) {
19114
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
133 return LogicConstantNode.forBoolean(condition.foldCondition(forX.asConstant(), forY.asConstant(), constantReflection, unorderedIsTrue));
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
134 }
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
135 return null;
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
136 }
b1dbba1f3f03 Restructure CompareNode. Create constant fold utility, store condition as data field.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
137
19116
7227f5671c87 Prototype for folding object equality at parse time.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19115
diff changeset
138 protected abstract LogicNode duplicateModified(ValueNode newX, ValueNode newY);
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
139
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
140 protected ValueNode canonicalizeSymmetricConstant(CanonicalizerTool tool, Constant constant, ValueNode nonConstant, boolean mirrored) {
16162
b3945bb0016f ConditionalNode is not a BinaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
141 if (nonConstant instanceof ConditionalNode) {
b3945bb0016f ConditionalNode is not a BinaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
142 return optimizeConditional(constant, (ConditionalNode) nonConstant, tool.getConstantReflection(), mirrored ? condition().mirror() : condition());
b3945bb0016f ConditionalNode is not a BinaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
143 } else if (nonConstant instanceof NormalizeCompareNode) {
b3945bb0016f ConditionalNode is not a BinaryNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16156
diff changeset
144 return optimizeNormalizeCmp(constant, (NormalizeCompareNode) nonConstant, mirrored);
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
145 } else if (nonConstant instanceof ConvertNode) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
146 ConvertNode convert = (ConvertNode) nonConstant;
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
147 ConstantNode newConstant = canonicalConvertConstant(tool, convert, constant);
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
148 if (newConstant != null) {
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
149 if (mirrored) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
150 return duplicateModified(newConstant, convert.getValue());
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
151 } else {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
152 return duplicateModified(convert.getValue(), newConstant);
15961
d5b824a41530 CompareNode refactorings
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15912
diff changeset
153 }
12729
64d960e854e6 Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 12695
diff changeset
154 }
9448
7b88c5e5cbd4 Add more canonicalizations for Compare and Negate nodes
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7767
diff changeset
155 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 return this;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 }
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
158
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
159 private ConstantNode canonicalConvertConstant(CanonicalizerTool tool, ConvertNode convert, Constant constant) {
18720
ab9d3ff6829b Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18713
diff changeset
160 ConstantReflectionProvider constantReflection = tool.getConstantReflection();
ab9d3ff6829b Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18713
diff changeset
161 if (convert.preservesOrder(condition(), constant, constantReflection)) {
ab9d3ff6829b Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18713
diff changeset
162 Constant reverseConverted = convert.reverse(constant, constantReflection);
ab9d3ff6829b Pass constant reflection into ConvertNode.convert
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18713
diff changeset
163 if (convert.convert(reverseConverted, constantReflection).equals(constant)) {
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
164 return ConstantNode.forConstant(convert.getValue().stamp(), reverseConverted, tool.getMetaAccess());
12729
64d960e854e6 Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 12695
diff changeset
165 }
64d960e854e6 Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 12695
diff changeset
166 }
64d960e854e6 Canonicalize comparison of type conversion with constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 12695
diff changeset
167 return null;
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
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
170 public static LogicNode createCompareNode(StructuredGraph graph, Condition condition, ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) {
19376
525d1e6067b7 Small fix for compare node. Returned node could already be in the graph.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
171 LogicNode result = createCompareNode(condition, x, y, constantReflection);
525d1e6067b7 Small fix for compare node. Returned node could already be in the graph.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19373
diff changeset
172 return (result.graph() == null ? graph.unique(result) : result);
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
173 }
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
174
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
175 public static LogicNode createCompareNode(Condition condition, ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14157
diff changeset
176 assert x.getKind() == y.getKind();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
177 assert condition.isCanonical() : "condition is not canonical: " + condition;
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14157
diff changeset
178 assert !x.getKind().isNumericFloat();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
179
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
180 LogicNode comparison;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
181 if (condition == Condition.EQ) {
18360
6a5dc0bbebe7 Introduce PointerEqualsNode for metaspace pointer comparison.
Roland Schatz <roland.schatz@oracle.com>
parents: 18188
diff changeset
182 if (x.stamp() instanceof AbstractObjectStamp) {
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
183 comparison = ObjectEqualsNode.create(x, y, constantReflection);
18360
6a5dc0bbebe7 Introduce PointerEqualsNode for metaspace pointer comparison.
Roland Schatz <roland.schatz@oracle.com>
parents: 18188
diff changeset
184 } else if (x.stamp() instanceof AbstractPointerStamp) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18720
diff changeset
185 comparison = new PointerEqualsNode(x, y);
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
186 } else {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14157
diff changeset
187 assert x.getKind().isNumericInteger();
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
188 comparison = IntegerEqualsNode.create(x, y, constantReflection);
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
189 }
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
190 } else if (condition == Condition.LT) {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14157
diff changeset
191 assert x.getKind().isNumericInteger();
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
192 comparison = IntegerLessThanNode.create(x, y, constantReflection);
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
193 } else {
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
194 assert condition == Condition.BT;
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 14157
diff changeset
195 assert x.getKind().isNumericInteger();
19241
30c8d110b281 More Truffle graph builder plugins and parse time canonicalizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19116
diff changeset
196 comparison = IntegerBelowNode.create(x, y, constantReflection);
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
197 }
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
198
16212
51c7c676d41a implement Canonicalizable.Binary in the BinaryOpLogicNode hierarchy
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16207
diff changeset
199 return comparison;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6571
diff changeset
200 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 }