Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java @ 13851:e86d32f4803f
Truffle: Implement cache for truffle inlining heuristic.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 31 Jan 2014 16:09:50 +0100 |
parents | 641f22b1c6b8 |
children | f46cab39a9a2 |
comparison
equal
deleted
inserted
replaced
13846:1e72cd05b77e | 13851:e86d32f4803f |
---|---|
100 * @param target the {@link CallTarget} to call | 100 * @param target the {@link CallTarget} to call |
101 * @return a call node that calls the provided target | 101 * @return a call node that calls the provided target |
102 */ | 102 */ |
103 public static CallNode create(CallTarget target) { | 103 public static CallNode create(CallTarget target) { |
104 if (isInlinable(target)) { | 104 if (isInlinable(target)) { |
105 return new InlinableCallNode(target); | 105 return new InlinableCallNode((RootCallTarget) target); |
106 } else { | 106 } else { |
107 return new DefaultCallNode(target); | 107 return new DefaultCallNode(target); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 /** | 111 /** |
112 * Warning: this is internal API and may change without notice. | 112 * Warning: this is internal API and may change without notice. |
113 */ | 113 */ |
114 public static int internalGetCallCount(CallNode callNode) { | 114 public interface CompilerCallView { |
115 if (callNode.isInlinable() && !callNode.isInlined()) { | 115 |
116 return ((InlinableCallNode) callNode).getCallCount(); | 116 int getCallCount(); |
117 } | 117 |
118 throw new UnsupportedOperationException(); | 118 void resetCallCount(); |
119 | |
120 void store(Object value); | |
121 | |
122 Object load(); | |
119 } | 123 } |
120 | 124 |
121 /** | 125 /** |
122 * Warning: this is internal API and may change without notice. | 126 * Warning: this is internal API and may change without notice. |
123 */ | 127 */ |
124 public static void internalResetCallCount(CallNode callNode) { | 128 public CompilerCallView getCompilerCallView() { |
125 if (callNode.isInlinable() && !callNode.isInlined()) { | 129 return null; |
126 ((InlinableCallNode) callNode).resetCallCount(); | |
127 return; | |
128 } | |
129 } | 130 } |
130 | 131 |
131 private static boolean isInlinable(CallTarget callTarget) { | 132 private static boolean isInlinable(CallTarget callTarget) { |
132 if (callTarget instanceof DefaultCallTarget) { | 133 if (callTarget instanceof RootCallTarget) { |
133 return (((DefaultCallTarget) callTarget).getRootNode()).isInlinable(); | 134 return (((RootCallTarget) callTarget).getRootNode()).isInlinable(); |
134 } | 135 } |
135 return false; | 136 return false; |
136 } | 137 } |
137 | 138 |
138 @Override | 139 @Override |
166 return false; | 167 return false; |
167 } | 168 } |
168 | 169 |
169 } | 170 } |
170 | 171 |
171 static final class InlinableCallNode extends CallNode { | 172 static final class InlinableCallNode extends CallNode implements CompilerCallView { |
172 | 173 |
173 private int callCount; | 174 private int callCount; |
174 | 175 |
175 public InlinableCallNode(CallTarget target) { | 176 public InlinableCallNode(RootCallTarget target) { |
176 super(target); | 177 super(target); |
177 } | 178 } |
178 | 179 |
179 @Override | 180 @Override |
180 public Object call(PackedFrame parentFrame, Arguments arguments) { | 181 public Object call(PackedFrame parentFrame, Arguments arguments) { |
206 @Override | 207 @Override |
207 public boolean isInlinable() { | 208 public boolean isInlinable() { |
208 return true; | 209 return true; |
209 } | 210 } |
210 | 211 |
212 @Override | |
213 public CompilerCallView getCompilerCallView() { | |
214 return this; | |
215 } | |
216 | |
211 /* Truffle internal API. */ | 217 /* Truffle internal API. */ |
212 int getCallCount() { | 218 public int getCallCount() { |
213 return callCount; | 219 return callCount; |
214 } | 220 } |
215 | 221 |
216 /* Truffle internal API. */ | 222 /* Truffle internal API. */ |
217 void resetCallCount() { | 223 public void resetCallCount() { |
218 callCount = 0; | 224 callCount = 0; |
225 } | |
226 | |
227 private Object storedCompilerInfo; | |
228 | |
229 public void store(Object value) { | |
230 this.storedCompilerInfo = value; | |
231 } | |
232 | |
233 public Object load() { | |
234 return storedCompilerInfo; | |
219 } | 235 } |
220 | 236 |
221 } | 237 } |
222 | 238 |
223 static final class InlinedCallNode extends CallNode { | 239 static final class InlinedCallNode extends CallNode { |