annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java @ 11881:da9db8331658

moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
author Doug Simon <doug.simon@oracle.com>
date Tue, 01 Oct 2013 20:38:25 +0200
parents 9a747d8e0d0f
children e8a70ba77439
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
10526
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
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;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
9647
2adfe940fd55 Make PiNode a guarding node so that it can be used for guarded to guarding edges
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9646
diff changeset
25 import com.oracle.graal.api.meta.*;
8651
3d03bc1de46c PiNode: add markerinterface IterableNodeType for fast iteration
Bernhard Urban <bernhard.urban@jku.at>
parents: 8649
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.*;
9647
2adfe940fd55 Make PiNode a guarding node so that it can be used for guarded to guarding edges
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9646
diff changeset
28 import com.oracle.graal.nodes.extended.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.spi.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.nodes.type.*;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31
6467
5d398a326315 documented PiNode
Doug Simon <doug.simon@oracle.com>
parents: 6290
diff changeset
32 /**
10526
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
33 * A node that changes the type of its input, usually narrowing it. For example, a PiNode refines
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7394
diff changeset
34 * the type of a receiver during type-guarded inlining to be the type tested by the guard.
10526
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
35 *
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
36 * In contrast to a {@link GuardedValueNode}, a PiNode is useless as soon as the type of its input
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
37 * is as narrow or narrower than the PiNode's type. The PiNode, and therefore also the scheduling
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
38 * restriction enforced by the anchor, will go away.
6467
5d398a326315 documented PiNode
Doug Simon <doug.simon@oracle.com>
parents: 6290
diff changeset
39 */
11631
1aed684853f6 refactored IterableNodeType into a top level type to avoid problems it was causing for javac and JDT (CR-1408)
Doug Simon <doug.simon@oracle.com>
parents: 10762
diff changeset
40 public class PiNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, IterableNodeType, GuardingNode, Canonicalizable, ValueProxy {
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41
5073
2db1ad9dd385 rename PiNode.value to PiNode.object and UnsafeCastNode.x to UnsafeCastNode.object
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
42 @Input private ValueNode object;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
5073
2db1ad9dd385 rename PiNode.value to PiNode.object and UnsafeCastNode.x to UnsafeCastNode.object
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
44 public ValueNode object() {
2db1ad9dd385 rename PiNode.value to PiNode.object and UnsafeCastNode.x to UnsafeCastNode.object
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
45 return object;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 }
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47
8649
39fc99302250 PiNode: use existing dependencies array for anchor
Bernhard Urban <bernhard.urban@jku.at>
parents: 7530
diff changeset
48 public PiNode(ValueNode object, Stamp stamp) {
39fc99302250 PiNode: use existing dependencies array for anchor
Bernhard Urban <bernhard.urban@jku.at>
parents: 7530
diff changeset
49 super(stamp);
39fc99302250 PiNode: use existing dependencies array for anchor
Bernhard Urban <bernhard.urban@jku.at>
parents: 7530
diff changeset
50 this.object = object;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 }
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
53 public PiNode(ValueNode object, Stamp stamp, ValueNode anchor) {
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
54 super(stamp, (GuardingNode) anchor);
5073
2db1ad9dd385 rename PiNode.value to PiNode.object and UnsafeCastNode.x to UnsafeCastNode.object
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
55 this.object = object;
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 }
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
58 public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
59 this(object, StampFactory.object(toType, exactType, nonNull || ObjectStamp.isObjectNonNull(object.stamp())));
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
60 }
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
61
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
62 @Override
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 public void generate(LIRGeneratorTool generator) {
9647
2adfe940fd55 Make PiNode a guarding node so that it can be used for guarded to guarding edges
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9646
diff changeset
64 if (object.kind() != Kind.Void && object.kind() != Kind.Illegal) {
2adfe940fd55 Make PiNode a guarding node so that it can be used for guarded to guarding edges
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9646
diff changeset
65 generator.setResult(this, generator.operand(object));
2adfe940fd55 Make PiNode a guarding node so that it can be used for guarded to guarding edges
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9646
diff changeset
66 }
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
67 }
5831
ed08c40d67de Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5337
diff changeset
68
ed08c40d67de Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5337
diff changeset
69 @Override
ed08c40d67de Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5337
diff changeset
70 public boolean inferStamp() {
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
71 if (stamp() == StampFactory.forNodeIntrinsic()) {
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
72 return false;
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
73 }
5890
c241963cda6d added Stamp.join, used by PiNodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5889
diff changeset
74 return updateStamp(stamp().join(object().stamp()));
5831
ed08c40d67de Add a alwaysNull property to ObjectStamp (Phi(null, a! A) get a "a A" stamp and not just "a -")
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5337
diff changeset
75 }
6710
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6467
diff changeset
76
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6467
diff changeset
77 @Override
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6467
diff changeset
78 public void virtualize(VirtualizerTool tool) {
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7335
diff changeset
79 State state = tool.getObjectState(object);
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7335
diff changeset
80 if (state != null && state.getState() == EscapeState.Virtual) {
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
81 assert ObjectStamp.typeOrNull(this).isAssignableFrom(state.getVirtualObject().type());
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7335
diff changeset
82 tool.replaceWithVirtual(state.getVirtualObject());
6710
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6467
diff changeset
83 }
6db6881c1270 add Virtualizable and VirtualizerTool, refactor PEA to use it
Lukas Stadler <lukas.stadler@jku.at>
parents: 6467
diff changeset
84 }
10054
10fbede11db0 Canonicalize useless PiNodes away
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10040
diff changeset
85
10fbede11db0 Canonicalize useless PiNodes away
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10040
diff changeset
86 @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: 11800
diff changeset
87 public Node canonical(CanonicalizerTool tool) {
10526
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
88 inferStamp();
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
89 if (stamp().equals(object().stamp())) {
815c675b07b0 split PiNode into PiNode and GuardedValueNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 10054
diff changeset
90 return object();
10054
10fbede11db0 Canonicalize useless PiNodes away
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10040
diff changeset
91 }
10fbede11db0 Canonicalize useless PiNodes away
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10040
diff changeset
92 return this;
10fbede11db0 Canonicalize useless PiNodes away
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10040
diff changeset
93 }
10762
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10526
diff changeset
94
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10526
diff changeset
95 @Override
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10526
diff changeset
96 public ValueNode getOriginalValue() {
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10526
diff changeset
97 return object;
c483912aaf70 add ValueProxy interface and infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 10526
diff changeset
98 }
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
99
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
100 @NodeIntrinsic
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
101 public static native <T> T piCast(Object object, @ConstantNodeParameter Stamp stamp);
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
102
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
103 @NodeIntrinsic
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
104 public static native <T> T piCast(Object object, @ConstantNodeParameter Stamp stamp, GuardingNode anchor);
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
105
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
106 @SuppressWarnings("unused")
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
107 @NodeIntrinsic
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
108 public static <T> T piCast(Object object, @ConstantNodeParameter Class<T> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull) {
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
109 return toType.cast(object);
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11713
diff changeset
110 }
4648
83b4cc4df77a experimental: added PiNode and PropagateTypesPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
111 }