comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java @ 14564:5d1308c78ddc

Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
author Christian Humer <christian.humer@gmail.com>
date Mon, 17 Mar 2014 14:29:45 +0100
parents 3ea5f337cc0d
children b1dded9c748a
comparison
equal deleted inserted replaced
14108:98d38009bb2b 14564:5d1308c78ddc
30 import javax.lang.model.element.*; 30 import javax.lang.model.element.*;
31 import javax.lang.model.type.*; 31 import javax.lang.model.type.*;
32 import javax.lang.model.util.*; 32 import javax.lang.model.util.*;
33 33
34 import com.oracle.truffle.api.dsl.*; 34 import com.oracle.truffle.api.dsl.*;
35 import com.oracle.truffle.api.nodes.NodeInfo.Kind;
36 import com.oracle.truffle.api.nodes.*; 35 import com.oracle.truffle.api.nodes.*;
37 import com.oracle.truffle.dsl.processor.*; 36 import com.oracle.truffle.dsl.processor.*;
38 import com.oracle.truffle.dsl.processor.ast.*; 37 import com.oracle.truffle.dsl.processor.ast.*;
39 import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality; 38 import com.oracle.truffle.dsl.processor.node.NodeChildData.Cardinality;
40 import com.oracle.truffle.dsl.processor.node.SpecializationGroup.TypeGuard; 39 import com.oracle.truffle.dsl.processor.node.SpecializationGroup.TypeGuard;
952 951
953 if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) { 952 if (node.getGenericSpecialization() != null && node.getGenericSpecialization().isReachable()) {
954 clazz.add(createGenericExecute(node, rootGroup)); 953 clazz.add(createGenericExecute(node, rootGroup));
955 } 954 }
956 955
957 clazz.add(createGetKind(node, null, Kind.SPECIALIZED)); 956 clazz.add(createGetCost(node, null, NodeCost.MONOMORPHIC));
958 } 957 }
959 958
960 protected boolean needsInvokeCopyConstructorMethod() { 959 protected boolean needsInvokeCopyConstructorMethod() {
961 return getModel().getNode().isPolymorphic(); 960 return getModel().getNode().isPolymorphic();
962 } 961 }
963 962
964 protected CodeExecutableElement createGetKind(NodeData node, SpecializationData specialization, Kind kind) { 963 protected CodeExecutableElement createGetCost(NodeData node, SpecializationData specialization, NodeCost cost) {
965 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeInfoKind(), "getKind"); 964 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getNodeCost(), "getCost");
966 965
967 TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeInfoKind(); 966 TypeMirror nodeInfoKind = context.getTruffleTypes().getNodeCost();
968 967
969 CodeTreeBuilder builder = method.createBuilder(); 968 CodeTreeBuilder builder = method.createBuilder();
970 if (node.isPolymorphic() && specialization == null) { 969 if (node.isPolymorphic() && specialization == null) {
971 // assume next0 exists 970 // assume next0 exists
972 builder.startIf().string("next0 != null && next0.getKind() == ").staticReference(nodeInfoKind, "SPECIALIZED").end(); 971 builder.startIf().string("next0 != null && next0.getCost() == ").staticReference(nodeInfoKind, "MONOMORPHIC").end();
973 builder.startBlock(); 972 builder.startBlock();
974 builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end(); 973 builder.startReturn().staticReference(nodeInfoKind, "POLYMORPHIC").end();
975 builder.end(); 974 builder.end();
976 } 975 }
977 976
978 builder.startReturn().staticReference(nodeInfoKind, kind.name()).end(); 977 builder.startReturn().staticReference(nodeInfoKind, cost.name()).end();
979 return method; 978 return method;
980 } 979 }
981 980
982 protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) { 981 protected CodeExecutableElement createInvokeCopyConstructor(TypeMirror baseType, SpecializationData specialization) {
983 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor"); 982 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), baseType, "invokeCopyConstructor");
2474 if (nodeGen != null) { 2473 if (nodeGen != null) {
2475 baseType = nodeGen.asType(); 2474 baseType = nodeGen.asType();
2476 } 2475 }
2477 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false); 2476 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false);
2478 2477
2479 clazz.getAnnotationMirrors().add(createNodeInfo(node, Kind.POLYMORPHIC)); 2478 clazz.getAnnotationMirrors().add(createNodeInfo(node, NodeCost.NONE));
2480 2479
2481 for (ActualParameter polymorphParameter : polymorph.getSignatureParameters()) { 2480 for (ActualParameter polymorphParameter : polymorph.getSignatureParameters()) {
2482 if (!polymorphParameter.getTypeSystemType().isGeneric()) { 2481 if (!polymorphParameter.getTypeSystemType().isGeneric()) {
2483 continue; 2482 continue;
2484 } 2483 }
2521 if (needsInvokeCopyConstructorMethod()) { 2520 if (needsInvokeCopyConstructorMethod()) {
2522 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization)); 2521 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
2523 } 2522 }
2524 2523
2525 createCachedExecuteMethods(specialization); 2524 createCachedExecuteMethods(specialization);
2526 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.SPECIALIZED)); 2525 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.NONE));
2527 } 2526 }
2528 2527
2529 private ExecutableElement createUpdateType(ActualParameter parameter) { 2528 private ExecutableElement createUpdateType(ActualParameter parameter) {
2530 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), createUpdateTypeName(parameter)); 2529 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), getContext().getType(void.class), createUpdateTypeName(parameter));
2531 method.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), "type")); 2530 method.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), "type"));
2561 if (nodeGen != null) { 2560 if (nodeGen != null) {
2562 baseType = nodeGen.asType(); 2561 baseType = nodeGen.asType();
2563 } 2562 }
2564 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false); 2563 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false);
2565 2564
2566 Kind kind; 2565 NodeCost cost;
2567 if (specialization.isGeneric()) { 2566 if (specialization.isGeneric()) {
2568 kind = Kind.GENERIC; 2567 cost = NodeCost.MEGAMORPHIC;
2569 } else if (specialization.isUninitialized()) { 2568 } else if (specialization.isUninitialized()) {
2570 kind = Kind.UNINITIALIZED; 2569 cost = NodeCost.UNINITIALIZED;
2571 } else if (specialization.isPolymorphic()) { 2570 } else if (specialization.isPolymorphic()) {
2572 kind = Kind.POLYMORPHIC; 2571 cost = NodeCost.NONE;
2573 } else if (specialization.isSpecialized()) { 2572 } else if (specialization.isSpecialized()) {
2574 kind = Kind.SPECIALIZED; 2573 cost = NodeCost.MONOMORPHIC;
2575 } else { 2574 } else {
2576 throw new AssertionError(); 2575 throw new AssertionError();
2577 } 2576 }
2578 clazz.getAnnotationMirrors().add(createNodeInfo(node, kind)); 2577 clazz.getAnnotationMirrors().add(createNodeInfo(node, cost));
2579 2578
2580 return clazz; 2579 return clazz;
2581 } 2580 }
2582 2581
2583 protected CodeAnnotationMirror createNodeInfo(NodeData node, Kind kind) { 2582 protected CodeAnnotationMirror createNodeInfo(NodeData node, NodeCost cost) {
2584 String shortName = node.getShortName(); 2583 String shortName = node.getShortName();
2585 CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation()); 2584 CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation());
2586 if (shortName != null) { 2585 if (shortName != null) {
2587 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName)); 2586 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName));
2588 } 2587 }
2589 2588
2590 DeclaredType nodeinfoKind = getContext().getTruffleTypes().getNodeInfoKind(); 2589 DeclaredType nodeinfoCost = getContext().getTruffleTypes().getNodeCost();
2591 VariableElement varKind = Utils.findVariableElement(nodeinfoKind, kind.name()); 2590 VariableElement varKind = Utils.findVariableElement(nodeinfoCost, cost.name());
2592 2591
2593 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("kind"), new CodeAnnotationValue(varKind)); 2592 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("cost"), new CodeAnnotationValue(varKind));
2594 return nodeInfoMirror; 2593 return nodeInfoMirror;
2595 } 2594 }
2596 2595
2597 @Override 2596 @Override
2598 protected void createChildren(SpecializationData specialization) { 2597 protected void createChildren(SpecializationData specialization) {
2607 if (needsInvokeCopyConstructorMethod()) { 2606 if (needsInvokeCopyConstructorMethod()) {
2608 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization)); 2607 clazz.add(createInvokeCopyConstructor(nodeGen.asType(), specialization));
2609 } 2608 }
2610 2609
2611 if (specialization.isGeneric()) { 2610 if (specialization.isGeneric()) {
2612 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.GENERIC)); 2611 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.MEGAMORPHIC));
2613 } else if (specialization.isUninitialized()) { 2612 } else if (specialization.isUninitialized()) {
2614 clazz.add(createGetKind(specialization.getNode(), specialization, Kind.UNINITIALIZED)); 2613 clazz.add(createGetCost(specialization.getNode(), specialization, NodeCost.UNINITIALIZED));
2615 } 2614 }
2616 } 2615 }
2617 2616
2618 protected void createConstructors(CodeTypeElement clazz) { 2617 protected void createConstructors(CodeTypeElement clazz) {
2619 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass()); 2618 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass());