Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeData.java @ 20940:476374f3fe9a
Truffle-DSL: generate better polymorphic execute signatures
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | 18c0f02fa4d2 |
children | 1ed58a90b510 |
comparison
equal
deleted
inserted
replaced
20939:f83fd99b2962 | 20940:476374f3fe9a |
---|---|
46 private ParameterSpec instanceParameterSpec; | 46 private ParameterSpec instanceParameterSpec; |
47 | 47 |
48 private final List<SpecializationData> specializations = new ArrayList<>(); | 48 private final List<SpecializationData> specializations = new ArrayList<>(); |
49 private final List<ShortCircuitData> shortCircuits = new ArrayList<>(); | 49 private final List<ShortCircuitData> shortCircuits = new ArrayList<>(); |
50 private final List<CreateCastData> casts = new ArrayList<>(); | 50 private final List<CreateCastData> casts = new ArrayList<>(); |
51 private Map<Integer, List<ExecutableTypeData>> executableTypes; | 51 private final List<ExecutableTypeData> executableTypes = new ArrayList<>(); |
52 | 52 |
53 private final NodeExecutionData thisExecution; | 53 private final NodeExecutionData thisExecution; |
54 private final boolean generateFactory; | 54 private final boolean generateFactory; |
55 | 55 |
56 private TypeMirror frameType; | 56 private TypeMirror frameType; |
133 } | 133 } |
134 return types; | 134 return types; |
135 } | 135 } |
136 | 136 |
137 public int getSignatureSize() { | 137 public int getSignatureSize() { |
138 if (getSpecializations() != null && !getSpecializations().isEmpty()) { | 138 return getChildExecutions().size(); |
139 return getSpecializations().get(0).getSignatureSize(); | |
140 } | |
141 return 0; | |
142 } | 139 } |
143 | 140 |
144 public boolean isFrameUsedByAnyGuard() { | 141 public boolean isFrameUsedByAnyGuard() { |
145 for (SpecializationData specialization : specializations) { | 142 for (SpecializationData specialization : specializations) { |
146 if (!specialization.isReachable()) { | 143 if (!specialization.isReachable()) { |
290 for (SpecializationData specialization : getSpecializations()) { | 287 for (SpecializationData specialization : getSpecializations()) { |
291 methods.add(specialization.getMethod()); | 288 methods.add(specialization.getMethod()); |
292 } | 289 } |
293 | 290 |
294 for (ExecutableTypeData execType : getExecutableTypes()) { | 291 for (ExecutableTypeData execType : getExecutableTypes()) { |
295 methods.add(execType.getMethod()); | 292 if (execType.getMethod() != null) { |
296 } | 293 methods.add(execType.getMethod()); |
297 | 294 } |
295 } | |
298 for (ShortCircuitData shortcircuit : getShortCircuits()) { | 296 for (ShortCircuitData shortcircuit : getShortCircuits()) { |
299 methods.add(shortcircuit.getMethod()); | 297 methods.add(shortcircuit.getMethod()); |
300 } | 298 } |
301 | 299 |
302 if (getCasts() != null) { | 300 if (getCasts() != null) { |
327 } | 325 } |
328 return null; | 326 return null; |
329 } | 327 } |
330 | 328 |
331 public List<ExecutableTypeData> getExecutableTypes(int evaluatedCount) { | 329 public List<ExecutableTypeData> getExecutableTypes(int evaluatedCount) { |
332 if (executableTypes == null) { | |
333 return Collections.emptyList(); | |
334 } | |
335 if (evaluatedCount == -1) { | 330 if (evaluatedCount == -1) { |
336 List<ExecutableTypeData> typeData = new ArrayList<>(); | 331 return executableTypes; |
337 for (int currentEvaluationCount : executableTypes.keySet()) { | |
338 typeData.addAll(executableTypes.get(currentEvaluationCount)); | |
339 } | |
340 return typeData; | |
341 } else { | 332 } else { |
342 List<ExecutableTypeData> types = executableTypes.get(evaluatedCount); | 333 List<ExecutableTypeData> filteredTypes = new ArrayList<>(); |
343 if (types == null) { | 334 for (ExecutableTypeData type : executableTypes) { |
344 return Collections.emptyList(); | 335 if (type.getEvaluatedCount() == evaluatedCount) { |
345 } | 336 filteredTypes.add(type); |
346 return types; | 337 } |
338 } | |
339 return filteredTypes; | |
347 } | 340 } |
348 } | 341 } |
349 | 342 |
350 public List<ExecutableTypeData> findGenericExecutableTypes(ProcessorContext context, int evaluatedCount) { | 343 public List<ExecutableTypeData> findGenericExecutableTypes(ProcessorContext context, int evaluatedCount) { |
351 List<ExecutableTypeData> types = new ArrayList<>(); | 344 List<ExecutableTypeData> types = new ArrayList<>(); |
494 | 487 |
495 public List<SpecializationData> getSpecializations() { | 488 public List<SpecializationData> getSpecializations() { |
496 return specializations; | 489 return specializations; |
497 } | 490 } |
498 | 491 |
492 public ExecutableTypeData getGenericExecutableType(ExecutableTypeData typeHint) { | |
493 ExecutableTypeData polymorphicDelegate = null; | |
494 if (typeHint != null) { | |
495 polymorphicDelegate = typeHint; | |
496 while (polymorphicDelegate.getDelegatedTo() != null && polymorphicDelegate.getEvaluatedCount() != getSignatureSize()) { | |
497 polymorphicDelegate = polymorphicDelegate.getDelegatedTo(); | |
498 } | |
499 } | |
500 if (polymorphicDelegate == null) { | |
501 for (ExecutableTypeData type : getExecutableTypes()) { | |
502 if (type.getDelegatedTo() == null && type.getEvaluatedCount() == getSignatureSize()) { | |
503 polymorphicDelegate = type; | |
504 break; | |
505 } | |
506 } | |
507 } | |
508 return polymorphicDelegate; | |
509 } | |
510 | |
499 public List<ExecutableTypeData> getExecutableTypes() { | 511 public List<ExecutableTypeData> getExecutableTypes() { |
500 return getExecutableTypes(-1); | 512 return getExecutableTypes(-1); |
501 } | 513 } |
502 | 514 |
503 public List<ShortCircuitData> getShortCircuits() { | 515 public List<ShortCircuitData> getShortCircuits() { |
508 int minimalEvaluatedParameters = Integer.MAX_VALUE; | 520 int minimalEvaluatedParameters = Integer.MAX_VALUE; |
509 for (ExecutableTypeData type : getExecutableTypes()) { | 521 for (ExecutableTypeData type : getExecutableTypes()) { |
510 minimalEvaluatedParameters = Math.min(minimalEvaluatedParameters, type.getEvaluatedCount()); | 522 minimalEvaluatedParameters = Math.min(minimalEvaluatedParameters, type.getEvaluatedCount()); |
511 } | 523 } |
512 return minimalEvaluatedParameters; | 524 return minimalEvaluatedParameters; |
513 } | |
514 | |
515 public void setExecutableTypes(Map<Integer, List<ExecutableTypeData>> executableTypes) { | |
516 this.executableTypes = executableTypes; | |
517 } | 525 } |
518 | 526 |
519 @Override | 527 @Override |
520 public String toString() { | 528 public String toString() { |
521 return getClass().getSimpleName() + "[" + getNodeId() + "]"; | 529 return getClass().getSimpleName() + "[" + getNodeId() + "]"; |
534 | 542 |
535 public int compareTo(NodeData o) { | 543 public int compareTo(NodeData o) { |
536 return getNodeId().compareTo(o.getNodeId()); | 544 return getNodeId().compareTo(o.getNodeId()); |
537 } | 545 } |
538 | 546 |
539 public List<TypeMirror> getPossibleTypes(NodeExecutionData execution) { | 547 public List<TypeMirror> getGenericTypes(NodeExecutionData execution) { |
540 List<TypeMirror> types = new ArrayList<>(); | 548 List<TypeMirror> types = new ArrayList<>(); |
541 | 549 |
542 // add types possible through return types and evaluated parameters in execute methods | 550 // add types possible through return types and evaluated parameters in execute methods |
543 if (execution.getChild() != null) { | 551 if (execution.getChild() != null) { |
544 for (ExecutableTypeData executable : execution.getChild().getNodeData().getExecutableTypes()) { | 552 for (ExecutableTypeData executable : execution.getChild().getNodeData().getExecutableTypes()) { |