Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java @ 14073:c5411233cdf8
Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 05 Mar 2014 23:33:25 +0100 |
parents | f46cab39a9a2 |
children | f157fabf6b38 |
comparison
equal
deleted
inserted
replaced
14072:036e61d4cebd | 14073:c5411233cdf8 |
---|---|
29 | 29 |
30 /** | 30 /** |
31 * This node represents a call to a static {@link CallTarget}. This node should be used whenever a | 31 * This node represents a call to a static {@link CallTarget}. This node should be used whenever a |
32 * {@link CallTarget} is considered constant at a certain location in the tree. This enables the | 32 * {@link CallTarget} is considered constant at a certain location in the tree. This enables the |
33 * Truffle runtime to perform inlining or other optimizations for this call-site. This class is | 33 * Truffle runtime to perform inlining or other optimizations for this call-site. This class is |
34 * intended to be implemented by truffle runtime implementors and not by guest languague | 34 * intended to be implemented by truffle runtime implementors and not by guest language |
35 * implementors. | 35 * implementors. |
36 * | 36 * |
37 * @see #create(CallTarget) to create a CallNode instance. | 37 * @see #create(CallTarget) to create a CallNode instance. |
38 */ | 38 */ |
39 public abstract class CallNode extends Node { | 39 public abstract class CallNode extends Node { |
43 protected CallNode(CallTarget callTarget) { | 43 protected CallNode(CallTarget callTarget) { |
44 this.callTarget = callTarget; | 44 this.callTarget = callTarget; |
45 } | 45 } |
46 | 46 |
47 /** | 47 /** |
48 * @return the constant {@link CallTarget} that is associated with this {@link CallNode}. | |
49 */ | |
50 public CallTarget getCallTarget() { | |
51 return callTarget; | |
52 } | |
53 | |
54 /** | |
55 * Calls this constant target passing a caller frame and arguments. | 48 * Calls this constant target passing a caller frame and arguments. |
56 * | 49 * |
57 * @param caller the caller frame | 50 * @param caller the caller frame |
58 * @param arguments the arguments that should be passed to the callee | 51 * @param arguments the arguments that should be passed to the callee |
59 * @return the return result of the call | 52 * @return the return result of the call |
60 */ | 53 */ |
61 public abstract Object call(PackedFrame caller, Arguments arguments); | 54 public abstract Object call(PackedFrame caller, Arguments arguments); |
55 | |
56 /** | |
57 * Returns the originally supplied {@link CallTarget} when this call node was created. Please | |
58 * note that the returned {@link CallTarget} is not necessarily the {@link CallTarget} that is | |
59 * called. For that use {@link #getCurrentCallTarget()} instead. | |
60 * | |
61 * @return the {@link CallTarget} provided. | |
62 */ | |
63 public CallTarget getCallTarget() { | |
64 return callTarget; | |
65 } | |
62 | 66 |
63 public abstract boolean isInlinable(); | 67 public abstract boolean isInlinable(); |
64 | 68 |
65 /** | 69 /** |
66 * @return true if this {@link CallNode} was already inlined. | 70 * @return true if this {@link CallNode} was already inlined. |
71 | 75 |
72 public abstract boolean isSplittable(); | 76 public abstract boolean isSplittable(); |
73 | 77 |
74 public abstract boolean split(); | 78 public abstract boolean split(); |
75 | 79 |
80 public final boolean isSplit() { | |
81 return getSplitCallTarget() != null; | |
82 } | |
83 | |
76 public abstract CallTarget getSplitCallTarget(); | 84 public abstract CallTarget getSplitCallTarget(); |
77 | 85 |
78 public abstract RootNode getInlinedRoot(); | 86 /** |
87 * Returns the used call target when {@link #call(PackedFrame, Arguments)} is invoked. If the | |
88 * {@link CallNode} was split this method returns the {@link CallTarget} returned by | |
89 * {@link #getSplitCallTarget()}. If not split this method returns the original supplied | |
90 * {@link CallTarget}. | |
91 * | |
92 * @return the used {@link CallTarget} when node is called | |
93 */ | |
94 public CallTarget getCurrentCallTarget() { | |
95 CallTarget split = getSplitCallTarget(); | |
96 if (split != null) { | |
97 return split; | |
98 } else { | |
99 return getCallTarget(); | |
100 } | |
101 } | |
102 | |
103 @Override | |
104 protected void onReplace(Node newNode, String reason) { | |
105 super.onReplace(newNode, reason); | |
106 | |
107 /* | |
108 * Old call nodes are removed in the old target root node. | |
109 */ | |
110 CallNode oldCall = this; | |
111 RootNode oldRoot = getCurrentRootNode(); | |
112 if (oldRoot != null) { | |
113 oldRoot.removeCachedCallNode(oldCall); | |
114 } | |
115 | |
116 /* | |
117 * New call nodes are registered in the new target root node. | |
118 */ | |
119 CallNode newCall = (CallNode) newNode; | |
120 RootNode newRoot = newCall.getCurrentRootNode(); | |
121 if (newRoot != null) { | |
122 newRoot.addCachedCallNode(newCall); | |
123 } | |
124 } | |
125 | |
126 /** | |
127 * Returns the {@link RootNode} associated with {@link CallTarget} returned by | |
128 * {@link #getCurrentCallTarget()}. | |
129 * | |
130 * @see #getCurrentCallTarget() | |
131 * @return the root node of the used call target | |
132 */ | |
133 public final RootNode getCurrentRootNode() { | |
134 CallTarget target = getCurrentCallTarget(); | |
135 if (target instanceof RootCallTarget) { | |
136 return ((RootCallTarget) target).getRootNode(); | |
137 } | |
138 return null; | |
139 } | |
140 | |
141 /** | |
142 * @deprecated instead use {@link #getCurrentRootNode()} and check for {@link #isInlined()} for | |
143 * true. | |
144 */ | |
145 @Deprecated | |
146 public RootNode getInlinedRoot() { | |
147 if (!isInlined()) { | |
148 return null; | |
149 } | |
150 return getCurrentRootNode(); | |
151 } | |
79 | 152 |
80 /** | 153 /** |
81 * Creates a new {@link CallNode} using a {@link CallTarget}. | 154 * Creates a new {@link CallNode} using a {@link CallTarget}. |
82 * | 155 * |
83 * @param target the {@link CallTarget} to call | 156 * @param target the {@link CallTarget} to call |
87 @Deprecated | 160 @Deprecated |
88 public static CallNode create(CallTarget target) { | 161 public static CallNode create(CallTarget target) { |
89 return Truffle.getRuntime().createCallNode(target); | 162 return Truffle.getRuntime().createCallNode(target); |
90 } | 163 } |
91 | 164 |
92 protected final void installParentInlinedCall() { | |
93 getInlinedRoot().addParentInlinedCall(this); | |
94 } | |
95 | |
96 } | 165 } |