Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java @ 11265:ef6915cf1e59
Add illegal stamp
Remove ValueNode.(object|integer)Stamp: use explicit tests/casts
Fix ObjectStamp.join
Introduce ObjectStamp.castTo
Add some tests for ObjectStamp.join
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 08 Aug 2013 18:17:47 +0200 |
parents | 19c5a07c7843 |
children | 6d28ce8cdeb7 |
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) 2009, 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 |
7724
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
25 import static com.oracle.graal.nodes.calc.CompareNode.*; |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
26 |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
28 import com.oracle.graal.nodes.*; |
7724
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
29 import com.oracle.graal.nodes.java.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
30 import com.oracle.graal.nodes.spi.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
5657
diff
changeset
|
33 * The {@code ConditionalNode} class represents a comparison that yields one of two values. Note |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
5657
diff
changeset
|
34 * that these nodes are not built directly from the bytecode but are introduced by canonicalization. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 */ |
7724
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
36 public final class ConditionalNode extends BinaryNode implements Canonicalizable, LIRLowerable, Negatable { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 |
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
|
38 @Input private LogicNode condition; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 |
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
|
40 public LogicNode condition() { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 return condition; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
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
|
44 public ConditionalNode(LogicNode condition, ValueNode trueValue, ValueNode falseValue) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 super(trueValue.kind(), trueValue, falseValue); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 assert trueValue.kind() == falseValue.kind(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 this.condition = condition; |
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 |
7724
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
50 @Override |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
51 public boolean inferStamp() { |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
52 return updateStamp(x().stamp().meet(y().stamp())); |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
53 } |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
54 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 public ValueNode trueValue() { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 return x(); |
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 public ValueNode falseValue() { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 return y(); |
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 @Override |
4309
4a609a685fa4
changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents:
4199
diff
changeset
|
64 public ValueNode canonical(CanonicalizerTool tool) { |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
65 // this optimizes the case where a value that can only be 0 or 1 is materialized to 0 or 1 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
66 if (x().isConstant() && y().isConstant() && condition instanceof IntegerEqualsNode) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
67 IntegerEqualsNode equals = (IntegerEqualsNode) condition; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
68 if (equals.y().isConstant() && equals.y().asConstant().equals(Constant.INT_0)) { |
11265 | 69 if (x().asConstant().equals(Constant.INT_0) && y().asConstant().equals(Constant.INT_1)) { |
70 return equals.x(); | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
71 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
72 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5563
diff
changeset
|
73 } |
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
|
74 if (condition instanceof LogicConstantNode) { |
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7724
diff
changeset
|
75 LogicConstantNode c = (LogicConstantNode) condition; |
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7724
diff
changeset
|
76 if (c.getValue()) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 return trueValue(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 } else { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 return falseValue(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 if (trueValue() == falseValue()) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 return trueValue(); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 return this; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 @Override |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 public void generate(LIRGeneratorTool generator) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 generator.emitConditional(this); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 } |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5061
diff
changeset
|
93 |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5061
diff
changeset
|
94 @Override |
9440
e35cf6b23b34
Add the condition that was negated in Negatable.negate
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8480
diff
changeset
|
95 public Negatable negate(LogicNode cond) { |
e35cf6b23b34
Add the condition that was negated in Negatable.negate
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
8480
diff
changeset
|
96 assert condition() == cond; |
5563
6a2671066204
added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
97 ConditionalNode replacement = graph().unique(new ConditionalNode(condition, falseValue(), trueValue())); |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9440
diff
changeset
|
98 graph().replaceFloating(this, replacement); |
5563
6a2671066204
added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
99 return replacement; |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5061
diff
changeset
|
100 } |
7724
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
101 |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
102 private ConditionalNode(Condition condition, ValueNode x, ValueNode y) { |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
103 this(createCompareNode(condition, x, y), ConstantNode.forInt(1, x.graph()), ConstantNode.forInt(0, x.graph())); |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
104 } |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
105 |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
106 private ConditionalNode(ValueNode type, ValueNode object) { |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
107 this(type.graph().add(new InstanceOfDynamicNode(type, object)), ConstantNode.forInt(1, type.graph()), ConstantNode.forInt(0, type.graph())); |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
108 } |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
109 |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
110 @NodeIntrinsic |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
111 public static native boolean materializeCondition(@ConstantNodeParameter Condition condition, int x, int y); |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
112 |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
113 @NodeIntrinsic |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
114 public static native boolean materializeCondition(@ConstantNodeParameter Condition condition, long x, long y); |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
115 |
ac3579b4adc9
remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
116 @NodeIntrinsic |
8480
7abc6865bdc6
made method substitutions for Class be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
117 public static boolean materializeIsInstance(Class mirror, Object object) { |
7abc6865bdc6
made method substitutions for Class be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
118 return mirror.isInstance(object); |
7abc6865bdc6
made method substitutions for Class be interpretable
Doug Simon <doug.simon@oracle.com>
parents:
8451
diff
changeset
|
119 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
120 } |