use of com.oracle.truffle.dsl.processor.model.NodeExecutionData in project graal by oracle.
the class FlatNodeGenFactory method createThrowUnsupported.
private CodeTree createThrowUnsupported(final CodeTreeBuilder parent, final FrameState frameState) {
CodeTreeBuilder builder = parent.create();
builder.startThrow().startNew(context.getType(UnsupportedSpecializationException.class));
builder.string("this");
builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Node.class)), null);
List<CodeTree> values = new ArrayList<>();
for (NodeExecutionData execution : node.getChildExecutions()) {
NodeChildData child = execution.getChild();
LocalVariable var = frameState.getValue(execution);
if (child != null) {
builder.string(accessNodeField(execution));
} else {
builder.string("null");
}
if (var != null) {
values.add(var.createReference());
}
}
builder.end();
builder.trees(values.toArray(new CodeTree[0]));
builder.end().end();
return builder.build();
}
use of com.oracle.truffle.dsl.processor.model.NodeExecutionData 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.model.NodeExecutionData 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();
}
use of com.oracle.truffle.dsl.processor.model.NodeExecutionData in project graal by oracle.
the class FlatNodeGenFactory method bindExpressionValues.
private Map<Variable, LocalVariable> bindExpressionValues(FrameState frameState, DSLExpression expression, SpecializationData specialization) throws AssertionError {
Map<Variable, LocalVariable> bindings = new HashMap<>();
Set<Variable> boundVariables = expression.findBoundVariables();
if (specialization == null && !boundVariables.isEmpty()) {
throw new AssertionError("Cannot bind guard variable in non-specialization group. yet.");
}
// resolve bindings for local context
for (Variable variable : boundVariables) {
Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable());
if (resolvedParameter != null) {
LocalVariable localVariable;
if (resolvedParameter.getSpecification().isCached()) {
// bind cached variable
String cachedMemberName = createFieldName(specialization, resolvedParameter);
localVariable = frameState.get(cachedMemberName);
CodeTree ref;
if (localVariable == null) {
ref = createCacheReference(frameState, specialization, resolvedParameter);
} else {
ref = localVariable.createReference();
}
bindings.put(variable, new LocalVariable(resolvedParameter.getType(), cachedMemberName, ref));
} else {
// bind local variable
if (resolvedParameter.getSpecification().isSignature()) {
NodeExecutionData execution = resolvedParameter.getSpecification().getExecution();
localVariable = frameState.getValue(execution);
} else {
localVariable = frameState.get(resolvedParameter.getLocalName());
}
if (localVariable != null) {
bindings.put(variable, localVariable);
}
}
}
}
return bindings;
}
use of com.oracle.truffle.dsl.processor.model.NodeExecutionData in project graal by oracle.
the class FlatNodeGenFactory method createFastPath.
private CodeTree createFastPath(CodeTreeBuilder parent, List<SpecializationData> allSpecializations, SpecializationGroup originalGroup, final ExecutableTypeData currentType, FrameState frameState) {
final CodeTreeBuilder builder = parent.create();
builder.tree(state.createLoad(frameState));
int sharedExecutes = 0;
for (NodeExecutionData execution : node.getChildExecutions()) {
boolean canExecuteChild = execution.getIndex() < currentType.getEvaluatedCount();
for (TypeGuard checkedGuard : originalGroup.getTypeGuards()) {
if (checkedGuard.getSignatureIndex() == execution.getIndex()) {
canExecuteChild = true;
break;
}
}
if (!canExecuteChild) {
break;
}
for (TypeGuard checkedGuard : originalGroup.getTypeGuards()) {
// we cannot pull out guards that use optimized implicit source types
if (resolveOptimizedImplicitSourceTypes(execution, checkedGuard.getType()).size() > 1) {
canExecuteChild = false;
break;
}
}
if (!canExecuteChild) {
break;
}
builder.tree(createFastPathExecuteChild(builder, frameState.copy(), frameState, currentType, originalGroup, execution));
sharedExecutes++;
}
List<BoxingSplit> boxingSplits = parameterBoxingElimination(originalGroup, sharedExecutes);
if (boxingSplits.isEmpty()) {
builder.tree(executeFastPathGroup(builder, frameState, currentType, originalGroup, sharedExecutes, null));
addExplodeLoop(builder, originalGroup);
} else {
FrameState originalFrameState = frameState.copy();
boolean elseIf = false;
for (BoxingSplit split : boxingSplits) {
elseIf = builder.startIf(elseIf);
List<SpecializationData> specializations = split.group.collectSpecializations();
builder.startGroup();
builder.tree(state.createContainsOnly(frameState, 0, -1, specializations.toArray(), allSpecializations.toArray())).end();
builder.string(" && ");
builder.tree(state.createIsNotAny(frameState, allSpecializations.toArray()));
builder.end();
builder.end().startBlock();
builder.tree(wrapInAMethod(builder, split.group, originalFrameState, split.getName(), executeFastPathGroup(builder, frameState.copy(), currentType, split.group, sharedExecutes, specializations)));
builder.end();
}
builder.startElseBlock();
builder.tree(wrapInAMethod(builder, originalGroup, originalFrameState, "generic", executeFastPathGroup(builder, frameState, currentType, originalGroup, sharedExecutes, null)));
builder.end();
}
return builder.build();
}
Aggregations