Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java @ 12395:8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 11 Oct 2013 20:05:55 +0200 |
parents | 29de278b7c1b |
children | d7f8dd4fe876 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java Wed Oct 09 15:33:36 2013 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeParser.java Fri Oct 11 20:05:55 2013 +0200 @@ -223,62 +223,44 @@ return; } - Signature genericSignature = node.getGenericSpecialization().getSignature(); - Set<Signature> signatures = new TreeSet<>(); + SpecializationData generic = node.getGenericSpecialization(); - for (SpecializationData specialization1 : node.getSpecializations()) { - Signature signature = specialization1.getSignature(); + List<TypeData> polymorphicSignature = new ArrayList<>(); + // TODO we should support more optimized for boxing +// List<ActualParameter> updatePolymorphic = generic.getReturnTypeAndParameters(); + List<ActualParameter> updatePolymorphic = Arrays.asList(); + for (ActualParameter genericParameter : updatePolymorphic) { + if (!genericParameter.getSpecification().isSignature()) { + continue; + } - for (SpecializationData specialization2 : node.getSpecializations()) { - if (specialization1 == specialization2) { + Set<TypeData> usedTypes = new HashSet<>(); + for (SpecializationData specialization : node.getSpecializations()) { + if (!specialization.isSpecialized()) { continue; } - signatures.add(signature.combine(genericSignature, specialization2.getSignature())); + ActualParameter parameter = specialization.findParameter(genericParameter.getLocalName()); + if (parameter == null) { + throw new AssertionError("Parameter existed in generic specialization but not in specialized. param = " + genericParameter.getLocalName()); + } + usedTypes.add(parameter.getTypeSystemType()); } + + TypeData polymorphicType; + if (usedTypes.size() == 1) { + polymorphicType = usedTypes.iterator().next(); + } else { + polymorphicType = node.getTypeSystem().getGenericTypeData(); + } + polymorphicSignature.add(polymorphicType); } - while (true) { - List<Signature> newSignatures = new ArrayList<>(); - for (Signature signature1 : signatures) { - for (Signature signature2 : signatures) { - if (signature1 == signature2) { - continue; - } - newSignatures.add(signature1.combine(genericSignature, signature2)); - } - } - if (!signatures.addAll(newSignatures)) { - break; - } - } - - List<Signature> sortedSignatures = new ArrayList<>(signatures); - - SpecializationData polymorphicGeneric = null; - List<SpecializationData> specializations = new ArrayList<>(); - SpecializationData generic = node.getGenericSpecialization(); - for (Signature signature : sortedSignatures) { - SpecializationData specialization = new SpecializationData(generic, false, false, true); - - for (Iterator<ActualParameter> iterator = specialization.getParameters().iterator(); iterator.hasNext();) { - ActualParameter param = iterator.next(); - if (param.getSpecification().isLocal()) { - iterator.remove(); - } - } - - specialization.forceFrame(context.getTruffleTypes().getFrame()); - specialization.setNode(node); - specialization.updateSignature(signature); - specializations.add(specialization); - - if (genericSignature.equals(signature)) { - polymorphicGeneric = specialization; - } - } - - node.setGenericPolymorphicSpecialization(polymorphicGeneric); - node.setPolymorphicSpecializations(specializations); + SpecializationData specialization = new SpecializationData(generic, false, false, true); + specialization.updateSignature(new Signature(polymorphicSignature)); + specialization.setNode(node); + node.setGenericPolymorphicSpecialization(specialization); + // TODO remove polymoprhic specializations + node.setPolymorphicSpecializations(Collections.<SpecializationData> emptyList()); } private NodeData parseNodeData(TypeElement templateType, TypeMirror nodeType, List<? extends Element> elements, List<TypeElement> typeHierarchy) {