Mercurial > hg > graal-compiler
comparison 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 |
comparison
equal
deleted
inserted
replaced
12394:df3af5e007ad | 12395:8e8347ecabbc |
---|---|
221 if (!node.needsRewrites(context) || !node.isPolymorphic()) { | 221 if (!node.needsRewrites(context) || !node.isPolymorphic()) { |
222 node.setPolymorphicSpecializations(Collections.<SpecializationData> emptyList()); | 222 node.setPolymorphicSpecializations(Collections.<SpecializationData> emptyList()); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 Signature genericSignature = node.getGenericSpecialization().getSignature(); | 226 SpecializationData generic = node.getGenericSpecialization(); |
227 Set<Signature> signatures = new TreeSet<>(); | 227 |
228 | 228 List<TypeData> polymorphicSignature = new ArrayList<>(); |
229 for (SpecializationData specialization1 : node.getSpecializations()) { | 229 // TODO we should support more optimized for boxing |
230 Signature signature = specialization1.getSignature(); | 230 // List<ActualParameter> updatePolymorphic = generic.getReturnTypeAndParameters(); |
231 | 231 List<ActualParameter> updatePolymorphic = Arrays.asList(); |
232 for (SpecializationData specialization2 : node.getSpecializations()) { | 232 for (ActualParameter genericParameter : updatePolymorphic) { |
233 if (specialization1 == specialization2) { | 233 if (!genericParameter.getSpecification().isSignature()) { |
234 continue; | |
235 } | |
236 | |
237 Set<TypeData> usedTypes = new HashSet<>(); | |
238 for (SpecializationData specialization : node.getSpecializations()) { | |
239 if (!specialization.isSpecialized()) { | |
234 continue; | 240 continue; |
235 } | 241 } |
236 signatures.add(signature.combine(genericSignature, specialization2.getSignature())); | 242 ActualParameter parameter = specialization.findParameter(genericParameter.getLocalName()); |
237 } | 243 if (parameter == null) { |
238 } | 244 throw new AssertionError("Parameter existed in generic specialization but not in specialized. param = " + genericParameter.getLocalName()); |
239 | 245 } |
240 while (true) { | 246 usedTypes.add(parameter.getTypeSystemType()); |
241 List<Signature> newSignatures = new ArrayList<>(); | 247 } |
242 for (Signature signature1 : signatures) { | 248 |
243 for (Signature signature2 : signatures) { | 249 TypeData polymorphicType; |
244 if (signature1 == signature2) { | 250 if (usedTypes.size() == 1) { |
245 continue; | 251 polymorphicType = usedTypes.iterator().next(); |
246 } | 252 } else { |
247 newSignatures.add(signature1.combine(genericSignature, signature2)); | 253 polymorphicType = node.getTypeSystem().getGenericTypeData(); |
248 } | 254 } |
249 } | 255 polymorphicSignature.add(polymorphicType); |
250 if (!signatures.addAll(newSignatures)) { | 256 } |
251 break; | 257 |
252 } | 258 SpecializationData specialization = new SpecializationData(generic, false, false, true); |
253 } | 259 specialization.updateSignature(new Signature(polymorphicSignature)); |
254 | 260 specialization.setNode(node); |
255 List<Signature> sortedSignatures = new ArrayList<>(signatures); | 261 node.setGenericPolymorphicSpecialization(specialization); |
256 | 262 // TODO remove polymoprhic specializations |
257 SpecializationData polymorphicGeneric = null; | 263 node.setPolymorphicSpecializations(Collections.<SpecializationData> emptyList()); |
258 List<SpecializationData> specializations = new ArrayList<>(); | |
259 SpecializationData generic = node.getGenericSpecialization(); | |
260 for (Signature signature : sortedSignatures) { | |
261 SpecializationData specialization = new SpecializationData(generic, false, false, true); | |
262 | |
263 for (Iterator<ActualParameter> iterator = specialization.getParameters().iterator(); iterator.hasNext();) { | |
264 ActualParameter param = iterator.next(); | |
265 if (param.getSpecification().isLocal()) { | |
266 iterator.remove(); | |
267 } | |
268 } | |
269 | |
270 specialization.forceFrame(context.getTruffleTypes().getFrame()); | |
271 specialization.setNode(node); | |
272 specialization.updateSignature(signature); | |
273 specializations.add(specialization); | |
274 | |
275 if (genericSignature.equals(signature)) { | |
276 polymorphicGeneric = specialization; | |
277 } | |
278 } | |
279 | |
280 node.setGenericPolymorphicSpecialization(polymorphicGeneric); | |
281 node.setPolymorphicSpecializations(specializations); | |
282 } | 264 } |
283 | 265 |
284 private NodeData parseNodeData(TypeElement templateType, TypeMirror nodeType, List<? extends Element> elements, List<TypeElement> typeHierarchy) { | 266 private NodeData parseNodeData(TypeElement templateType, TypeMirror nodeType, List<? extends Element> elements, List<TypeElement> typeHierarchy) { |
285 NodeData nodeData = new NodeData(templateType, templateType.getSimpleName().toString()); | 267 NodeData nodeData = new NodeData(templateType, templateType.getSimpleName().toString()); |
286 | 268 |