use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method initializeUninitialized.
private static void initializeUninitialized(final NodeData node) {
SpecializationData generic = node.getGenericSpecialization();
if (generic == null) {
return;
}
TemplateMethod uninializedMethod = new TemplateMethod("Uninitialized", -1, node, generic.getSpecification(), null, null, generic.getReturnType(), generic.getParameters());
// should not use messages from generic specialization
uninializedMethod.getMessages().clear();
node.getSpecializations().add(new SpecializationData(node, uninializedMethod, SpecializationKind.UNINITIALIZED));
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData 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.SpecializationData 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.SpecializationData in project graal by oracle.
the class FlatNodeGenFactory method parameterBoxingElimination.
/*
* It duplicates a group into small subgroups of specializations that don't need boxing when
* executing the children.
*/
private List<BoxingSplit> parameterBoxingElimination(SpecializationGroup group, int evaluatedcount) {
if (!boxingEliminationEnabled) {
return Collections.emptyList();
}
List<SpecializationData> allSpecializations = group.collectSpecializations();
List<Set<TypeGuard>> signatures = new ArrayList<>();
List<List<SpecializationData>> signatureSpecializations = new ArrayList<>();
for (SpecializationData specialization : allSpecializations) {
int index = -1;
List<TypeGuard> guards = new ArrayList<>();
for (Parameter p : specialization.getSignatureParameters()) {
index++;
if (!ElementUtils.isPrimitive(p.getType())) {
continue;
} else if (index < evaluatedcount) {
continue;
} else {
NodeChildData child = p.getSpecification().getExecution().getChild();
if (child != null && child.findExecutableType(p.getType()) == null) {
// type cannot be executed so it cannot be eliminated
continue;
}
}
guards.add(new TypeGuard(p.getType(), index));
}
if (!guards.isEmpty()) {
boolean directFound = false;
for (int i = 0; i < signatures.size(); i++) {
if (guards.containsAll(signatures.get(i))) {
if (signatures.get(i).containsAll(guards)) {
directFound = true;
}
signatureSpecializations.get(i).add(specialization);
}
}
if (!directFound) {
signatures.add(new LinkedHashSet<>(guards));
List<SpecializationData> specializations = new ArrayList<>();
specializations.add(specialization);
signatureSpecializations.add(specializations);
}
}
}
List<BoxingSplit> groups = new ArrayList<>();
for (int i = 0; i < signatureSpecializations.size(); i++) {
List<SpecializationData> groupedSpecialization = signatureSpecializations.get(i);
if (allSpecializations.size() == groupedSpecialization.size()) {
// contains all specializations does not make sense to group
continue;
}
Set<TypeGuard> signature = signatures.get(i);
TypeMirror[] signatureMirrors = new TypeMirror[signature.size()];
int index = 0;
for (TypeGuard typeGuard : signature) {
signatureMirrors[index] = typeGuard.getType();
index++;
}
groups.add(new BoxingSplit(SpecializationGroup.create(groupedSpecialization), signatureMirrors));
}
Collections.sort(groups, new Comparator<BoxingSplit>() {
public int compare(BoxingSplit o1, BoxingSplit o2) {
return Integer.compare(o2.primitiveSignature.length, o1.primitiveSignature.length);
}
});
return groups;
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData 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);
}
Aggregations