use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method resolveOptimizedImplicitSourceTypes.
private List<TypeMirror> resolveOptimizedImplicitSourceTypes(NodeExecutionData execution, TypeMirror targetType) {
List<TypeMirror> allSourceTypes = typeSystem.lookupSourceTypes(targetType);
List<TypeMirror> filteredSourceTypes = new ArrayList<>();
for (TypeMirror sourceType : allSourceTypes) {
ExecutableTypeData executableType = resolveTargetExecutable(execution, sourceType);
if (executableType == null) {
continue;
}
if (!ElementUtils.isPrimitive(sourceType) || !boxingEliminationEnabled) {
// don't optimize non primitives
continue;
}
if (!ElementUtils.typeEquals(executableType.getReturnType(), sourceType)) {
// no boxing optimization possible
continue;
}
filteredSourceTypes.add(sourceType);
}
return filteredSourceTypes;
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method createExecuteChild.
private ChildExecutionResult createExecuteChild(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
ChildExecutionResult result;
if (!typeSystem.hasImplicitSourceTypes(target.getTypeMirror())) {
ExecutableTypeData targetExecutable = resolveTargetExecutable(execution, target.typeMirror);
final CodeTreeBuilder builder = parent.create();
result = createCallSingleChildExecute(execution, target, frameState, targetExecutable);
builder.string(target.getName()).string(" = ");
builder.tree(result.code);
result.code = builder.build();
} else {
result = createExecuteChildImplicitCast(parent.create(), originalFrameState, frameState, execution, target);
}
return result;
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData 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.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method createExecuteChildImplicitCast.
private ChildExecutionResult createExecuteChildImplicitCast(CodeTreeBuilder parent, FrameState originalFrameState, FrameState frameState, NodeExecutionData execution, LocalVariable target) {
CodeTreeBuilder builder = parent.create();
List<TypeMirror> originalSourceTypes = typeSystem.lookupSourceTypes(target.getTypeMirror());
List<TypeMirror> sourceTypes = resolveOptimizedImplicitSourceTypes(execution, target.getTypeMirror());
TypeGuard typeGuard = new TypeGuard(target.getTypeMirror(), execution.getIndex());
boolean throwsUnexpected = false;
boolean elseIf = false;
for (TypeMirror sourceType : sourceTypes) {
ExecutableTypeData executableType = resolveTargetExecutable(execution, sourceType);
elseIf = builder.startIf(elseIf);
throwsUnexpected |= executableType.hasUnexpectedValue(context);
builder.startGroup();
builder.tree(state.createContainsOnly(frameState, originalSourceTypes.indexOf(sourceType), 1, new Object[] { typeGuard }, new Object[] { typeGuard }));
builder.string(" && ");
builder.tree(state.createIsNotAny(frameState, reachableSpecializationsArray));
builder.end();
builder.end();
builder.startBlock();
CodeTree value = callChildExecuteMethod(execution, executableType, frameState);
value = expect(executableType.getReturnType(), sourceType, value);
throwsUnexpected |= needsCastTo(executableType.getReturnType(), sourceType);
ImplicitCastData cast = typeSystem.lookupCast(sourceType, target.getTypeMirror());
if (cast != null) {
// we need to store the original value to restore it in
// case of a deopt
String localName = createSourceTypeLocalName(target, sourceType);
builder.startStatement().string(localName).string(" = ").tree(value).end();
value = callMethod(null, cast.getMethod(), CodeTreeBuilder.singleString(localName));
}
builder.startStatement().string(target.getName()).string(" = ").tree(value).end();
builder.end();
}
if (elseIf) {
builder.startElseBlock();
}
LocalVariable genericValue = target.makeGeneric(context).nextName();
builder.tree(createAssignExecuteChild(originalFrameState, frameState, builder, execution, node.getGenericExecutableType(null), genericValue));
builder.startStatement().string(target.getName()).string(" = ");
CodeTree implicitState = state.createExtractInteger(frameState, typeGuard);
builder.tree(TypeSystemCodeGenerator.implicitExpectFlat(typeSystem, target.getTypeMirror(), genericValue.createReference(), implicitState));
builder.end();
if (!sourceTypes.isEmpty()) {
builder.end();
}
return new ChildExecutionResult(builder.build(), throwsUnexpected);
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class NodeParser method initializeExecutableTypeHierarchy.
private static void initializeExecutableTypeHierarchy(NodeData node) {
SpecializationData polymorphic = node.getPolymorphicSpecialization();
if (polymorphic != null) {
boolean polymorphicSignatureFound = false;
List<TypeMirror> dynamicTypes = polymorphic.getDynamicTypes();
TypeMirror frame = null;
if (polymorphic.getFrame() != null) {
frame = dynamicTypes.remove(0);
}
ExecutableTypeData polymorphicType = new ExecutableTypeData(node, polymorphic.getReturnType().getType(), "execute", frame, dynamicTypes);
String genericName = ExecutableTypeData.createName(polymorphicType) + "_";
polymorphicType.setUniqueName(genericName);
for (ExecutableTypeData type : node.getExecutableTypes()) {
if (polymorphicType.sameSignature(type)) {
polymorphicSignatureFound = true;
break;
}
}
if (!polymorphicSignatureFound) {
node.getExecutableTypes().add(polymorphicType);
}
}
List<ExecutableTypeData> rootTypes = buildExecutableHierarchy(node);
List<ExecutableTypeData> additionalAbstractRootTypes = new ArrayList<>();
for (int i = 1; i < rootTypes.size(); i++) {
ExecutableTypeData rootType = rootTypes.get(i);
if (rootType.isAbstract()) {
// cannot implemement root
additionalAbstractRootTypes.add(rootType);
} else {
node.getExecutableTypes().remove(rootType);
}
}
if (!additionalAbstractRootTypes.isEmpty()) {
node.addError("Incompatible abstract execute methods found %s.", additionalAbstractRootTypes);
}
namesUnique(node.getExecutableTypes());
}
Aggregations