use of com.oracle.truffle.dsl.processor.java.model.CodeTree 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.CodeTree 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.CodeTree in project graal by oracle.
the class FlatNodeGenFactory method bindExecuteMethodParameters.
private CodeTree[] bindExecuteMethodParameters(NodeExecutionData execution, ExecutableTypeData method, FrameState frameState) {
List<NodeExecutionData> executeWith = execution != null ? execution.getChild().getExecuteWith() : null;
List<CodeTree> values = new ArrayList<>();
if (method.getFrameParameter() != null) {
LocalVariable frameLocal = frameState.get(FRAME_VALUE);
if (frameLocal == null) {
values.add(CodeTreeBuilder.singleString("null"));
} else {
values.add(createParameterReference(frameLocal, method.getMethod(), 0));
}
}
int evaluatedIndex = 0;
for (int executionIndex = 0; executionIndex < node.getExecutionCount(); executionIndex++) {
NodeExecutionData parameterExecution;
if (executeWith != null && executionIndex < executeWith.size()) {
parameterExecution = executeWith.get(executionIndex);
} else {
parameterExecution = node.getChildExecutions().get(executionIndex);
}
if (evaluatedIndex < method.getEvaluatedCount()) {
TypeMirror targetType = method.getEvaluatedParameters().get(evaluatedIndex);
LocalVariable value = frameState.getValue(parameterExecution);
if (value != null) {
int parameterIndex = method.getParameterIndex(evaluatedIndex);
values.add(createParameterReference(value, method.getMethod(), parameterIndex));
} else {
values.add(CodeTreeBuilder.createBuilder().defaultValue(targetType).build());
}
evaluatedIndex++;
}
}
return values.toArray(new CodeTree[values.size()]);
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class FlatNodeGenFactory method callTemplateMethod.
private CodeTree callTemplateMethod(CodeTree receiver, TemplateMethod method, FrameState frameState) {
CodeTree[] bindings = new CodeTree[method.getParameters().size()];
int signatureIndex = 0;
for (int i = 0; i < bindings.length; i++) {
Parameter parameter = method.getParameters().get(i);
if (parameter.getSpecification().isCached() && method instanceof SpecializationData) {
bindings[i] = createCacheReference(frameState, (SpecializationData) method, parameter);
} else {
LocalVariable var = frameState.get(parameter, signatureIndex);
if (var == null) {
var = frameState.get(parameter.getLocalName());
}
if (var != null) {
bindings[i] = createParameterReference(var, method.getMethod(), i);
}
}
if (parameter.getSpecification().isSignature()) {
signatureIndex++;
}
}
return callMethod(receiver, method.getMethod(), bindings);
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTree in project graal by oracle.
the class FlatNodeGenFactory method combineTrees.
private static CodeTree combineTrees(String sep, CodeTree... trees) {
CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
String s = "";
for (CodeTree tree : trees) {
if (tree != null && !tree.isEmpty()) {
if (sep != null) {
builder.string(s);
}
builder.tree(tree);
s = sep;
}
}
return builder.build();
}
Aggregations