use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method filterExecutableTypes.
private List<ExecutableTypeData> filterExecutableTypes(List<ExecutableTypeData> executableTypes, List<SpecializationData> specializations) {
Set<TypeMirror> specializedReturnTypes = new HashSet<>();
for (SpecializationData specialization : specializations) {
specializedReturnTypes.add(specialization.getReturnType().getType());
}
List<ExecutableTypeData> filteredTypes = new ArrayList<>();
outer: for (ExecutableTypeData executable : executableTypes) {
if (executable.getMethod() == null) {
continue;
}
if (executable.isAbstract()) {
filteredTypes.add(executable);
continue;
}
if (executable.isFinal()) {
// no way to implement that
continue;
}
if (!executable.hasUnexpectedValue(context)) {
filteredTypes.add(executable);
continue;
} else {
TypeMirror returnType = executable.getReturnType();
if (boxingEliminationEnabled && (isVoid(returnType) || ElementUtils.isPrimitive(returnType))) {
for (TypeMirror specializedReturnType : specializedReturnTypes) {
if (isSubtypeBoxed(context, specializedReturnType, returnType)) {
filteredTypes.add(executable);
continue outer;
}
}
}
}
}
Collections.sort(filteredTypes);
return filteredTypes;
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method createExecuteDelegation.
private ExecuteDelegationResult createExecuteDelegation(CodeTreeBuilder parent, FrameState frameState, ExecutableTypeData type, List<ExecutableTypeData> delegateableTypes, final List<SpecializationData> compatibleSpecializations, List<SpecializationData> implementedSpecializations) {
CodeTreeBuilder builder = parent.create();
List<SpecializationData> notImplemented = new ArrayList<>(compatibleSpecializations);
for (SpecializationData specialization : implementedSpecializations) {
notImplemented.remove(specialization);
}
if (notImplemented.isEmpty()) {
throw new AssertionError();
}
List<ExecutableTypeData> compatibleDelegateTypes = filterCompatibleExecutableTypes(type, delegateableTypes);
List<ExecutableTypeData> delegatedDelegateTypes = new ArrayList<>();
CodeTreeBuilder delegateBuilder = builder.create();
boolean elseIf = false;
boolean coversAllSpecializations = false;
if (boxingEliminationEnabled) {
Set<TypeMirror> optimizeTypes = new HashSet<>();
for (SpecializationData specialization : reachableSpecializations) {
TypeMirror returnType = specialization.getReturnType().getType();
if (ElementUtils.isPrimitive(returnType)) {
optimizeTypes.add(returnType);
}
}
for (TypeMirror optimizedType : ElementUtils.uniqueSortedTypes(optimizeTypes, true)) {
ExecutableTypeData delegateType = null;
for (ExecutableTypeData compatibleType : compatibleDelegateTypes) {
if (ElementUtils.typeEquals(compatibleType.getReturnType(), optimizedType)) {
delegateType = compatibleType;
break;
}
}
if (delegateType != null) {
List<SpecializationData> delegateSpecializations = filterImplementedSpecializations(delegateType, filterCompatibleSpecializations(delegateType, reachableSpecializations));
coversAllSpecializations = delegateSpecializations.size() == reachableSpecializations.size();
if (!coversAllSpecializations) {
builder.tree(state.createLoad(frameState));
elseIf = delegateBuilder.startIf(elseIf);
delegateBuilder.startGroup();
delegateBuilder.tree(state.createContainsOnly(frameState, 0, -1, delegateSpecializations.toArray(), reachableSpecializationsArray)).end();
delegateBuilder.string(" && ");
delegateBuilder.tree(state.createIsNotAny(frameState, reachableSpecializationsArray));
delegateBuilder.end();
delegateBuilder.end();
delegateBuilder.startBlock();
}
delegatedDelegateTypes.add(delegateType);
delegateBuilder.tree(createCallExecute(type, delegateType, frameState));
if (!coversAllSpecializations) {
delegateBuilder.end();
}
if (coversAllSpecializations) {
break;
}
}
}
}
if (!compatibleDelegateTypes.isEmpty() && !coversAllSpecializations) {
ExecutableTypeData delegateType = compatibleDelegateTypes.get(0);
coversAllSpecializations = notImplemented.size() == reachableSpecializations.size();
if (!coversAllSpecializations) {
builder.tree(state.createLoad(frameState));
elseIf = delegateBuilder.startIf(elseIf);
delegateBuilder.tree(state.createContains(frameState, notImplemented.toArray())).end();
delegateBuilder.startBlock();
}
delegatedDelegateTypes.add(delegateType);
delegateBuilder.tree(createCallExecute(type, delegateType, frameState));
if (!coversAllSpecializations) {
delegateBuilder.end();
}
}
boolean hasUnexpected = false;
for (ExecutableTypeData delegateType : delegatedDelegateTypes) {
if (needsUnexpectedResultException(delegateType)) {
hasUnexpected = true;
break;
}
}
if (hasUnexpected) {
builder.startTryBlock();
builder.tree(delegateBuilder.build());
builder.end().startCatchBlock(context.getType(UnexpectedResultException.class), "ex");
if (isVoid(type.getReturnType())) {
builder.returnStatement();
} else {
builder.startReturn();
builder.tree(expectOrCast(getType(Object.class), type, CodeTreeBuilder.singleString("ex")));
builder.end();
}
builder.end();
} else {
builder.tree(delegateBuilder.build());
}
return new ExecuteDelegationResult(builder.build(), !coversAllSpecializations);
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method resolveTargetExecutable.
private ExecutableTypeData resolveTargetExecutable(NodeExecutionData execution, TypeMirror target) {
NodeChildData child = execution.getChild();
if (child == null) {
return null;
}
ExecutableTypeData targetExecutable = child.findExecutableType(target);
if (targetExecutable == null) {
targetExecutable = child.findAnyGenericExecutableType(context);
}
return targetExecutable;
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method createExecuteAndSpecializeType.
private ExecutableTypeData createExecuteAndSpecializeType() {
SpecializationData polymorphicSpecialization = node.getPolymorphicSpecialization();
TypeMirror polymorphicType = polymorphicSpecialization.getReturnType().getType();
List<TypeMirror> parameters = new ArrayList<>();
for (Parameter param : polymorphicSpecialization.getSignatureParameters()) {
parameters.add(param.getType());
}
return new ExecutableTypeData(node, polymorphicType, "executeAndSpecialize", node.getFrameType(), parameters);
}
use of com.oracle.truffle.dsl.processor.model.ExecutableTypeData in project graal by oracle.
the class FlatNodeGenFactory method createFallbackGuard.
private Element createFallbackGuard() {
boolean frameUsed = false;
FrameState frameState = FrameState.load(this);
List<SpecializationData> specializations = new ArrayList<>(reachableSpecializations);
for (ListIterator<SpecializationData> iterator = specializations.listIterator(); iterator.hasNext(); ) {
SpecializationData specialization = iterator.next();
if (specialization.isFallback()) {
iterator.remove();
} else if (!specialization.isReachesFallback()) {
iterator.remove();
} else {
if (specialization.isFrameUsedByGuard()) {
frameUsed = true;
}
}
}
SpecializationGroup group = SpecializationGroup.create(specializations);
ExecutableTypeData executableType = node.findAnyGenericExecutableType(context, -1);
if (!frameUsed) {
frameState.removeValue(FRAME_VALUE);
}
fallbackNeedsState = false;
fallbackNeedsFrame = frameUsed;
state.createLoad(frameState);
CodeExecutableElement method = frameState.createMethod(modifiers(PRIVATE), getType(boolean.class), METHOD_FALLBACK_GUARD, FRAME_VALUE, STATE_VALUE);
CodeTree result = visitSpecializationGroup(CodeTreeBuilder.createBuilder(), group, executableType, frameState, null, NodeExecutionMode.FALLBACK_GUARD);
if (!fallbackNeedsState) {
VariableElement toRemove = null;
for (VariableElement v : method.getParameters()) {
if (v.getSimpleName().toString().equals(STATE_VALUE)) {
toRemove = v;
break;
}
}
if (toRemove != null) {
method.getParameters().remove(toRemove);
}
}
final CodeTreeBuilder builder = method.createBuilder();
for (SpecializationData implemented : specializations) {
if (implemented.getMaximumNumberOfInstances() > 1) {
method.getAnnotationMirrors().add(createExplodeLoop());
break;
}
}
builder.tree(result);
builder.returnTrue();
if (!accessesCachedState(specializations)) {
method.getModifiers().add(STATIC);
}
return method;
}
Aggregations