use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method persistSpecializationClass.
private Collection<IfTriple> persistSpecializationClass(FrameState frameState, SpecializationData specialization) {
if (!useSpecializationClass(specialization)) {
return Collections.emptyList();
}
String localName = createSpecializationLocalName(specialization);
LocalVariable var = frameState.get(localName);
if (var == null) {
// no specialization class initialized
return Collections.emptyList();
}
String persistFrameState = createSpecializationClassPersisted(specialization);
if (frameState.getBoolean(persistFrameState, false)) {
// no specialization class initialized
return Collections.emptyList();
} else {
frameState.setBoolean(persistFrameState, true);
}
CodeTree ref = var.createReference();
CodeTreeBuilder builder = new CodeTreeBuilder(null);
builder.startStatement();
builder.string("this.", createSpecializationFieldName(specialization));
builder.string(" = ");
if (specializationClassIsNode(specialization)) {
builder.startCall("super", "insert").tree(ref).end();
} else {
builder.tree(ref);
}
builder.end();
return Arrays.asList(new IfTriple(builder.build(), null, null));
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createSpecialize.
private CodeTree createSpecialize(CodeTreeBuilder parent, FrameState frameState, SpecializationGroup group, SpecializationData specialization) {
CodeTreeBuilder builder = parent.create();
List<IfTriple> triples = new ArrayList<>();
triples.addAll(initializeSpecializationClass(frameState, specialization));
triples.addAll(initializeCaches(frameState, group, specialization.getCaches(), NodeExecutionMode.SLOW_PATH, false, true));
triples.addAll(persistAssumptions(frameState, specialization));
triples.addAll(persistSpecializationClass(frameState, specialization));
builder.end(IfTriple.materialize(builder, triples, true));
List<SpecializationData> excludesSpecializations = new ArrayList<>();
for (SpecializationData otherSpeciailzation : reachableSpecializations) {
if (otherSpeciailzation == specialization) {
continue;
}
if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
excludesSpecializations.add(otherSpeciailzation);
}
}
if (!excludesSpecializations.isEmpty()) {
SpecializationData[] excludesArray = excludesSpecializations.toArray(new SpecializationData[0]);
builder.tree(exclude.createSet(frameState, excludesArray, true, true));
for (SpecializationData excludes : excludesArray) {
if (useSpecializationClass(excludes)) {
builder.statement("this." + createSpecializationFieldName(excludes) + " = null");
}
}
builder.tree((state.createSet(frameState, excludesArray, false, false)));
}
CodeTree updateImplicitCast = createUpdateImplicitCastState(builder, frameState, specialization);
if (updateImplicitCast != null) {
builder.tree(createUpdateImplicitCastState(builder, frameState, specialization));
}
builder.tree(state.createSet(frameState, new SpecializationData[] { specialization }, true, true));
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method loadSpecializationClass.
private CodeTree loadSpecializationClass(FrameState frameState, SpecializationData specialization) {
if (!useSpecializationClass(specialization)) {
return null;
}
String localName = createSpecializationLocalName(specialization);
String typeName = createSpecializationTypeName(specialization);
LocalVariable var = frameState.get(localName);
CodeTreeBuilder builder = new CodeTreeBuilder(null);
builder.startStatement();
if (var == null) {
builder.string(typeName);
builder.string(" ");
}
builder.string(localName);
builder.string(" = ");
builder.tree(createSpecializationFieldReference(frameState, specialization, null));
builder.end();
if (var == null) {
frameState.set(localName, new LocalVariable(new GeneratedTypeMirror("", typeName), localName, null));
}
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createExecute.
private CodeExecutableElement createExecute(CodeTypeElement clazz, ExecutableTypeData type, List<ExecutableTypeData> delegateableTypes) {
final List<SpecializationData> allSpecializations = reachableSpecializations;
final List<SpecializationData> compatibleSpecializations = filterCompatibleSpecializations(type, allSpecializations);
List<SpecializationData> implementedSpecializations;
if (delegateableTypes.isEmpty()) {
implementedSpecializations = compatibleSpecializations;
} else {
implementedSpecializations = filterImplementedSpecializations(type, compatibleSpecializations);
}
FrameState frameState = FrameState.load(this, type, Integer.MAX_VALUE);
CodeExecutableElement method = createExecuteMethod(null, type, frameState, true);
clazz.add(method);
CodeTreeBuilder builder = method.createBuilder();
// do I miss specializations that are reachable from this executable?
if (compatibleSpecializations.size() != implementedSpecializations.size()) {
ExecuteDelegationResult delegation = createExecuteDelegation(builder, frameState, type, delegateableTypes, compatibleSpecializations, implementedSpecializations);
builder.tree(delegation.tree);
if (!delegation.hasFallthrough) {
return method;
}
}
if (implementedSpecializations.isEmpty()) {
implementedSpecializations = compatibleSpecializations;
}
if (implementedSpecializations.isEmpty()) {
builder.tree(createTransferToInterpreterAndInvalidate());
builder.startThrow().startNew(getType(AssertionError.class)).doubleQuote("Delegation failed.").end().end();
} else {
SpecializationGroup group = SpecializationGroup.create(implementedSpecializations);
builder.tree(createFastPath(builder, implementedSpecializations, group, type, frameState));
}
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createAssignExecuteChild.
private CodeTree createAssignExecuteChild(FrameState originalFrameState, FrameState frameState, CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData forType, LocalVariable targetValue) {
CodeTreeBuilder builder = parent.create();
ChildExecutionResult executeChild = createExecuteChild(builder, originalFrameState, frameState, execution, targetValue);
builder.tree(createTryExecuteChild(targetValue, executeChild.code, true, executeChild.throwsUnexpectedResult));
builder.end();
if (executeChild.throwsUnexpectedResult) {
builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
FrameState slowPathFrameState = originalFrameState.copy();
slowPathFrameState.setValue(execution, targetValue.makeGeneric(context).accessWith(CodeTreeBuilder.singleString("ex.getResult()")));
ExecutableTypeData delegateType = node.getGenericExecutableType(forType);
boolean found = false;
for (NodeExecutionData otherExecution : node.getChildExecutions()) {
if (found) {
LocalVariable childEvaluatedValue = slowPathFrameState.createValue(otherExecution, genericType);
builder.tree(createAssignExecuteChild(slowPathFrameState.copy(), slowPathFrameState, builder, otherExecution, delegateType, childEvaluatedValue));
slowPathFrameState.setValue(otherExecution, childEvaluatedValue);
} else {
// skip forward already evaluated
found = execution == otherExecution;
}
}
builder.tree(createCallExecuteAndSpecialize(forType, slowPathFrameState));
builder.end();
}
return builder.build();
}
Aggregations