Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 21879:90fd69243227
Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 09 Jun 2015 12:50:43 +0200 |
parents | 23f0f181bc05 |
children |
comparison
equal
deleted
inserted
replaced
21878:79fb8b5ef185 | 21879:90fd69243227 |
---|---|
30 | 30 |
31 import javax.lang.model.element.*; | 31 import javax.lang.model.element.*; |
32 import javax.lang.model.type.*; | 32 import javax.lang.model.type.*; |
33 import javax.lang.model.util.*; | 33 import javax.lang.model.util.*; |
34 | 34 |
35 import com.oracle.truffle.api.*; | |
35 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; | 36 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
36 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | 37 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
37 import com.oracle.truffle.api.dsl.*; | 38 import com.oracle.truffle.api.dsl.*; |
38 import com.oracle.truffle.api.dsl.internal.*; | 39 import com.oracle.truffle.api.dsl.internal.*; |
39 import com.oracle.truffle.api.dsl.internal.DSLOptions.ImplicitCastOptimization; | 40 import com.oracle.truffle.api.dsl.internal.DSLOptions.ImplicitCastOptimization; |
239 | 240 |
240 clazz.add(createExecutableTypeOverride(usedTypes, execType)); | 241 clazz.add(createExecutableTypeOverride(usedTypes, execType)); |
241 } | 242 } |
242 | 243 |
243 if (singleSpecializableUnsupportedUsed) { | 244 if (singleSpecializableUnsupportedUsed) { |
244 clazz.add(createUnsupportedMethod()); | 245 addUnsupportedMethod(clazz); |
245 } | 246 } |
246 } else { | 247 } else { |
247 | 248 |
248 for (ExecutableTypeData execType : usedTypes) { | 249 for (ExecutableTypeData execType : usedTypes) { |
249 if (execType.getMethod() == null) { | 250 if (execType.getMethod() == null) { |
296 annotation.setElementValue(annotation.findExecutableElement("value"), new CodeAnnotationValue("SA_LOCAL_SELF_COMPARISON")); | 297 annotation.setElementValue(annotation.findExecutableElement("value"), new CodeAnnotationValue("SA_LOCAL_SELF_COMPARISON")); |
297 clazz.addAnnotationMirror(annotation); | 298 clazz.addAnnotationMirror(annotation); |
298 } | 299 } |
299 } | 300 } |
300 | 301 |
301 private Element createUnsupportedMethod() { | 302 private void addUnsupportedMethod(CodeTypeElement clazz) { |
303 CodeVariableElement seenUnsupportedField = new CodeVariableElement(modifiers(PRIVATE), getType(boolean.class), "seenUnsupported0"); | |
304 seenUnsupportedField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class))); | |
305 clazz.add(seenUnsupportedField); | |
302 LocalContext locals = LocalContext.load(this); | 306 LocalContext locals = LocalContext.load(this); |
303 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED), getType(UnsupportedSpecializationException.class), "unsupported", varArgsThreshold); | 307 CodeExecutableElement method = locals.createMethod(modifiers(PRIVATE), getType(UnsupportedSpecializationException.class), "unsupported", varArgsThreshold); |
304 CodeTreeBuilder builder = method.createBuilder(); | 308 CodeTreeBuilder builder = method.createBuilder(); |
309 builder.startIf().string("!").string(seenUnsupportedField.getName()).end().startBlock(); | |
310 builder.startStatement().startStaticCall(getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); | |
311 builder.startStatement().string(seenUnsupportedField.getName()).string(" = true").end(); | |
312 builder.end(); | |
313 | |
305 builder.startReturn(); | 314 builder.startReturn(); |
306 builder.startNew(getType(UnsupportedSpecializationException.class)); | 315 builder.startNew(getType(UnsupportedSpecializationException.class)); |
307 builder.string("this"); | 316 builder.string("this"); |
308 builder.tree(createGetSuppliedChildren()); | 317 builder.tree(createGetSuppliedChildren()); |
309 locals.addReferencesTo(builder); | 318 locals.addReferencesTo(builder); |
310 builder.end(); | 319 builder.end(); |
311 builder.end(); | 320 builder.end(); |
312 return method; | 321 clazz.add(method); |
313 } | 322 } |
314 | 323 |
315 private CodeExecutableElement createNodeConstructor(CodeTypeElement clazz, ExecutableElement superConstructor) { | 324 private CodeExecutableElement createNodeConstructor(CodeTypeElement clazz, ExecutableElement superConstructor) { |
316 CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(), clazz, superConstructor); | 325 CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(), clazz, superConstructor); |
317 ElementUtils.setVisibility(constructor.getModifiers(), ElementUtils.getVisibility(superConstructor.getModifiers())); | 326 ElementUtils.setVisibility(constructor.getModifiers(), ElementUtils.getVisibility(superConstructor.getModifiers())); |