annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 18780:f4d78e4a878d

Truffle-DSL: fixed create method should have the same visibility as its originating constructor. (GRAAL-365 #resolve)
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 20:23:22 +0100
parents 76cbf5f33f82
children 93016f2f3f16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.dsl.processor.generator;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static com.oracle.truffle.dsl.processor.generator.GeneratorUtils.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import static com.oracle.truffle.dsl.processor.java.ElementUtils.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import static javax.lang.model.element.Modifier.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import java.util.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import javax.lang.model.element.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import javax.lang.model.type.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import javax.lang.model.util.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 import com.oracle.truffle.api.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 import com.oracle.truffle.api.dsl.internal.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 import com.oracle.truffle.api.dsl.internal.DSLOptions.ImplicitCastOptimization;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 import com.oracle.truffle.api.dsl.internal.DSLOptions.TypeBoxingOptimization;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 import com.oracle.truffle.api.frame.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 import com.oracle.truffle.api.nodes.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 import com.oracle.truffle.api.nodes.Node.Child;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 import com.oracle.truffle.dsl.processor.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 import com.oracle.truffle.dsl.processor.java.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 import com.oracle.truffle.dsl.processor.java.model.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 import com.oracle.truffle.dsl.processor.model.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 import com.oracle.truffle.dsl.processor.parser.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 import com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 public class NodeGenFactory {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 private static final String FRAME_VALUE = "frameValue";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
55 private static final String NAME_SUFFIX = "_";
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
56
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 private final ProcessorContext context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 private final NodeData node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 private final TypeSystemData typeSystem;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 private final TypeData genericType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 private final DSLOptions options;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 public NodeGenFactory(ProcessorContext context, NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 this.context = context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 this.node = node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 this.typeSystem = node.getTypeSystem();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 this.genericType = typeSystem.getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 this.options = typeSystem.getOptions();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 public static String nodeTypeName(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 return resolveNodeId(node) + "NodeGen";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 private static String resolveNodeId(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 String nodeid = node.getNodeId();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 nodeid = nodeid.substring(0, nodeid.length() - 4);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 return nodeid;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 public static TypeMirror nodeType(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 return new GeneratedTypeMirror(ElementUtils.getPackageName(node.getTemplateType()), nodeTypeName(node));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 private static String specializationTypeName(SpecializationData specialization) {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
88 return specialization.getId() + "Node_";
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 private static TypeMirror specializationType(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 return new GeneratedTypeMirror(ElementUtils.getPackageName(specialization.getNode().getTemplateType()) + "." + nodeTypeName(specialization.getNode()), specializationTypeName(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 private static String polymorphicTypeProfileFieldName(NodeExecutionData execution) {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
96 return execution.getName() + "Type" + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 private static String nodeFieldName(NodeExecutionData execution) {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
100 return execution.getName() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 private static String specializationStartFieldName() {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
104 return "specialization" + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 private static String excludedFieldName(SpecializationData specialization) {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
108 return "exclude" + specialization.getId() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 private static String executeChildMethodName(NodeExecutionData execution, TypeData type) {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
112 return "execute" + ElementUtils.firstLetterUpperCase(execution.getName()) + (type.isGeneric() ? "" : getTypeId(type.getBoxedType())) + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 private static CodeTree accessParent(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 if (name == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 return CodeTreeBuilder.singleString("root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 return CodeTreeBuilder.createBuilder().string("root.").string(name).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123 private static String assumptionName(String assumption) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 return assumption + "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127 public CodeTypeElement create() {
18774
674c8a6d5e6c Truffle-DSL: fixed wrong visibility of DSL nodes generated by the new layout.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
128 CodeTypeElement clazz = GeneratorUtils.createClass(node, null, modifiers(FINAL), nodeTypeName(node), node.getTemplateType().asType());
674c8a6d5e6c Truffle-DSL: fixed wrong visibility of DSL nodes generated by the new layout.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
129 ElementUtils.setVisibility(clazz.getModifiers(), ElementUtils.getVisibility(node.getTemplateType().getModifiers()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 clazz.getImplements().add(getType(SpecializedNode.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 for (String assumption : node.getAssumptions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133 clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), getType(Assumption.class), assumptionName(assumption)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137 clazz.addOptional(createAccessChildMethod(child));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 for (NodeFieldData field : node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 if (!field.isGenerated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), field.getType(), field.getName()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 if (field.getGetter() != null && field.getGetter().getModifiers().contains(Modifier.ABSTRACT)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), field.getGetter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 method.createBuilder().startReturn().string("this.").string(field.getName()).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 clazz.add(method);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153
18780
f4d78e4a878d Truffle-DSL: fixed create method should have the same visibility as its originating constructor. (GRAAL-365 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18777
diff changeset
154 for (ExecutableElement superConstructor : NodeBaseFactory.findUserConstructors(node.getTemplateType().asType())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 clazz.add(createNodeConstructor(clazz, superConstructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 clazz.add(createNodeField(PRIVATE, execution.getNodeType(), nodeFieldName(execution), Child.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
161
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 for (NodeExecutionData execution : node.getChildExecutions()) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
163 if (resolveSpecializedExecutables(execution, node.findSpecializedTypes(execution), options.polymorphicTypeBoxingElimination()).isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 clazz.add(createNodeField(PRIVATE, getType(Class.class), polymorphicTypeProfileFieldName(execution), CompilationFinal.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171 clazz.add(createNodeField(PRIVATE, getType(boolean.class), excludedFieldName(specialization), CompilationFinal.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175 clazz.add(createNodeField(PRIVATE, TypeSystemNodeFactory.nodeType(node.getTypeSystem()), specializationStartFieldName(), Child.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
176 clazz.add(createMethodGetSpecializationNode());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
177 clazz.add(createDeepCopyMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 clazz.add(createGetCostMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 Collection<TypeData> specializedTypes = node.findSpecializedReturnTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 for (ExecutableTypeData execType : node.getExecutableTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182 if (shouldImplementExecutableType(specializedTypes, execType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183 clazz.add(createExecutableTypeOverride(execType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
186
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
187 SpecializationData initialSpecialization = createSpecializations(clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
188
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
189 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
190 CodeTreeBuilder builder = ((CodeExecutableElement) constructor).appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
191 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
192 builder.string("this.").string(specializationStartFieldName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193 builder.string(" = ").tree(createCallCreateMethod(initialSpecialization, "this", null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
194 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
195 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
196
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
197 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200 private CodeExecutableElement createNodeConstructor(CodeTypeElement clazz, ExecutableElement superConstructor) {
18780
f4d78e4a878d Truffle-DSL: fixed create method should have the same visibility as its originating constructor. (GRAAL-365 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18777
diff changeset
201 CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(), clazz, superConstructor);
f4d78e4a878d Truffle-DSL: fixed create method should have the same visibility as its originating constructor. (GRAAL-365 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18777
diff changeset
202 ElementUtils.setVisibility(constructor.getModifiers(), ElementUtils.getVisibility(superConstructor.getModifiers()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204 List<CodeVariableElement> childParameters = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
207 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208 constructor.getParameters().addAll(superConstructor.getParameters().size(), childParameters);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
210 CodeTreeBuilder builder = constructor.appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211 List<String> childValues = new ArrayList<>(node.getChildren().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
212 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213 String name = child.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215 CreateCastData createCast = node.findCast(child.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
216 if (createCast != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217 CodeTree nameTree = CodeTreeBuilder.singleString(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
218 CodeTreeBuilder callBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
219 callBuilder.string(name).string(" != null ? ");
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
220 callBuilder.tree(callTemplateMethod(null, createCast, nameTree));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
221 callBuilder.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
222 name += "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
223 builder.declaration(child.getNodeType(), name, callBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
224 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
225 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
226 childValues.add(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
227 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
228
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
229 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
230 CreateCastData createCast = node.findCast(execution.getChild().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
231
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
232 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
233 builder.string("this.").string(nodeFieldName(execution)).string(" = ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
234
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
235 String name = childValues.get(node.getChildren().indexOf(execution.getChild()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
236 CodeTreeBuilder accessorBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
237 accessorBuilder.string(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
238
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
239 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240 accessorBuilder.string("[").string(String.valueOf(execution.getIndex())).string("]");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
243 CodeTree accessor = accessorBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
244
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
245 if (createCast != null && execution.getChild().getCardinality().isOne()) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
246 accessor = callTemplateMethod(null, createCast, accessor);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
247 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
248
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
249 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
250 CodeTreeBuilder nullCheck = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
251 nullCheck.string(name).string(" != null ? ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
252 nullCheck.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
253 nullCheck.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
254 accessor = nullCheck.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
255 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
256
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
257 builder.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
258
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
260 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265 private static boolean mayBeExcluded(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266 return !specialization.getExceptions().isEmpty() || !specialization.getExcludedBy().isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
267 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
268
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
269 private SpecializationData createSpecializations(CodeTypeElement clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 if (isSingleSpecializable(reachableSpecializations)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 SpecializationData single = reachableSpecializations.get(0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
274 clazz.add(createSingleSpecialization(single));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 return single;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 } else {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
277 CodeTypeElement baseSpecialization = clazz.add(createBaseSpecialization());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 TypeMirror baseSpecializationType = baseSpecialization.asType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280 Map<SpecializationData, CodeTypeElement> generated = new LinkedHashMap<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
281
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
282 List<SpecializationData> generateSpecializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
283 generateSpecializations.add(node.getUninitializedSpecialization());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
284 if (needsPolymorphic(reachableSpecializations)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285 generateSpecializations.add(node.getPolymorphicSpecialization());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
286 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 generateSpecializations.addAll(reachableSpecializations);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
288
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
289 for (SpecializationData specialization : generateSpecializations) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
290 generated.put(specialization, clazz.add(createSpecialization(specialization, baseSpecializationType)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
292
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
293 baseSpecialization.addOptional(createCreateNext(generated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
294 baseSpecialization.addOptional(createCreateFallback(generated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
295 baseSpecialization.addOptional(createCreatePolymorphic(generated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
296
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297 return node.getUninitializedSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
298 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
300
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
301 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
302
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
303 private CodeTypeElement createBaseSpecialization() {
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
304 CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, ABSTRACT, STATIC), "BaseNode_", TypeSystemNodeFactory.nodeType(typeSystem));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
305
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
306 clazz.addOptional(createSpecializationConstructor(clazz, null, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
307 clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
308
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
309 clazz.addOptional(createUnsupported());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
310 clazz.add(createGetSuppliedChildren());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312 int signatureSize = node.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 Set<Integer> evaluatedCount = getEvaluatedCounts();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314 for (int evaluated : evaluatedCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 if (signatureSize != evaluated || signatureSize == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 clazz.add(createFastPathExecuteMethod(null, evaluated > 0 ? null : genericType, evaluated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
319
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 Collection<TypeData> specializedTypes = node.findSpecializedTypes(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 specializedTypes.add(genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 if (isExecuteChildShared(execution, specializedType)) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
325 clazz.add(createExecuteChildMethod(execution, specializedType));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
326 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
327 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
329
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333 private CodeTypeElement createSingleSpecialization(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
334 CodeTypeElement clazz = createClass(node, specialization, modifiers(PRIVATE, STATIC, FINAL), specializationTypeName(specialization), TypeSystemNodeFactory.nodeType(typeSystem));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
335 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, null, "0"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
336 clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337 TypeData returnType = specialization.getReturnType().getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
338 Set<Integer> evaluatedCount = getEvaluatedCounts();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
339 for (int evaluated : evaluatedCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
340 clazz.add(createFastPathExecuteMethod(specialization, null, evaluated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
341 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
342 if (isTypeBoxingEliminated(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
343 clazz.add(createFastPathExecuteMethod(specialization, returnType, 0));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
344 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
345 clazz.add(createFastPathWrapExecuteMethod(genericType, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
346
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
347 clazz.addOptional(createUnsupported());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
348 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
349 clazz.add(createGetSuppliedChildren());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
350
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
351 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
352 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
353
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
354 private CodeTypeElement createSpecialization(SpecializationData specialization, TypeMirror baseType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
355 CodeTypeElement clazz = createClass(node, specialization, modifiers(PRIVATE, STATIC, FINAL), specializationTypeName(specialization), baseType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
356
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
357 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, specialization, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
358
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
359 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
360 TypeData targetType = p.getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
361 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
362 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
363 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
364 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
365 implicitProfile.getModifiers().add(PRIVATE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
366 implicitProfile.getModifiers().add(FINAL);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
367 clazz.add(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
368 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
369 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
370 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
371
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
372 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
373 clazz.add(createFallbackGuardMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
374 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
375
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
376 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377 clazz.addOptional(createMergeMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
378 clazz.addOptional(createIsSameMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
379
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
380 TypeData returnType = specialization.getReturnType().getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381 int signatureSize = specialization.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383 clazz.add(createFastPathExecuteMethod(specialization, null, signatureSize));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
385 if (isTypeBoxingEliminated(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
386 clazz.add(createFastPathExecuteMethod(specialization, returnType, 0));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 if (signatureSize > 0 && !returnType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 clazz.add(createFastPathWrapExecuteMethod(genericType, returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
391
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 ExecutableTypeData voidExecutableType = node.findExecutableType(typeSystem.getVoidType(), 0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393 if (voidExecutableType != null && isTypeBoxingOptimized(options.voidBoxingOptimization(), returnType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
394 clazz.add(createFastPathWrapVoidMethod(returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
395 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 private Element createDeepCopyMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), getType(Node.class), "deepCopy");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405 builder.startReturn().startStaticCall(getType(SpecializationNode.class), "updateRoot").string("super.deepCopy()").end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 private Element createGetCostMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410 TypeMirror returnType = getType(NodeCost.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
414 builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
415 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
418 private CodeExecutableElement createIsSameMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419 if (!specialization.isSpecialized() || !options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
422
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
423 List<CodeVariableElement> profiles = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
426 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
427 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
428 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429 CodeVariableElement var = createImplicitProfileParameter(execution, parameter.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
431 profiles.add(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
432 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435 if (profiles.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(boolean.class), "isSame");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440 method.addParameter(new CodeVariableElement(getType(SpecializationNode.class), "other"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445 builder.string("super.isSame(other)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
447 for (CodeVariableElement profile : profiles) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 builder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
449 builder.string("this.").string(profile.getName()).string(" == ").string("(").cast(specializationType(specialization)).string("other).").string(profile.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
451
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
452 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
456 private Element createMergeMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
457 if (specialization.getExcludedBy().isEmpty() && !specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
458 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
460 TypeMirror specializationNodeType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), specializationNodeType, "merge");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462 executable.addParameter(new CodeVariableElement(specializationNodeType, "newNode"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
463 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
464 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
465
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
466 if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
467 builder.statement("return polymorphicMerge(newNode)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
468 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
470 for (SpecializationData containedSpecialization : specialization.getExcludedBy()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
471 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472 builder.string("newNode.getClass() == ").typeLiteral(specializationType(containedSpecialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
473 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
474 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
475 builder.statement("removeSame(\"Contained by " + containedSpecialization.createReferenceName() + "\")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
476 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
477 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
478 builder.statement("return super.merge(newNode)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
479 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
482 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
483
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 private Element createFastPathWrapVoidMethod(TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), typeSystem.getVoidType().getPrimitiveType(), TypeSystemNodeFactory.executeName(typeSystem.getVoidType()));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
486 executable.addParameter(new CodeVariableElement(getType(Frame.class), FRAME_VALUE));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
488 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 builder.startCall(TypeSystemNodeFactory.voidBoxingExecuteName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
494
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 private Element createFastPathWrapExecuteMethod(TypeData override, TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), override.getPrimitiveType(), TypeSystemNodeFactory.executeName(override));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
500 executable.addParameter(new CodeVariableElement(getType(Frame.class), FRAME_VALUE));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
501 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
504 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507 builder.startCall(TypeSystemNodeFactory.executeName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
509 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
510 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
511 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
512 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 builder.statement("return ex.getResult()");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
514 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
519
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
520 private boolean needsPolymorphic(List<SpecializationData> reachableSpecializations) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521 if (reachableSpecializations.size() > 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
523 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
524 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525 SpecializationData specialization = reachableSpecializations.get(0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527 if (parameter.getTypeSystemType().hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
528 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
529 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
533 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
534
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
537 if (fallback == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
538 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
539 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
540 CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
541 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
542 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
543 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
544
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
546 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createFallback");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
547 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
548 method.createBuilder().startReturn().tree(createCallCreateMethod(fallback, null, null)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
549 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 SpecializationData polymorphic = node.getPolymorphicSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555 if (generatedPolymorphic == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
556 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
557 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
559 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createPolymorphic");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
560 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
561 method.createBuilder().startReturn().tree(createCallCreateMethod(polymorphic, null, null)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
562 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
563 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
565 private CodeExecutableElement createCreateNext(final Map<SpecializationData, CodeTypeElement> specializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
566 final LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
567
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
568 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), getType(SpecializationNode.class), "createNext", FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
569 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
570
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
571 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
572 SpecializationGroup group = createSpecializationGroups();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
573 CodeTree execution = createGuardAndCast(group, genericType, locals, new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
574 public CodeTree createExecute(SpecializationData specialization, LocalContext values) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
575 CodeTypeElement generatedType = specializationClasses.get(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
576 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
577 throw new AssertionError("No generated type for " + specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
578 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
579 return createSlowPathExecute(specialization, locals);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
580 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
581
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
582 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
583 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
584 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
585 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
586
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
587 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
588
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
589 if (hasFallthrough(group, genericType, locals, false)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
590 builder.returnNull();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
591 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
592 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
593 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
595 private CodeExecutableElement createFallbackGuardMethod() {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
596 boolean frameUsed = node.isFrameUsedByAnyGuard();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
597 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
598
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
599 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
600 locals.removeValue(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
601 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
602
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
603 CodeExecutableElement boundaryMethod = locals.createMethod(modifiers(PRIVATE), getType(boolean.class), "guardFallback", FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
604 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
605 boundaryMethod.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(TruffleBoundary.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
606 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
607
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
608 CodeTreeBuilder builder = boundaryMethod.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
609 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
610 builder.startCall("createNext");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
611 locals.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
612 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
613 builder.string(" == null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
614 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
615 return boundaryMethod;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
616 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
617
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
618 private ExecutableElement createAccessChildMethod(NodeChildData child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
619 if (child.getAccessElement() != null && child.getAccessElement().getModifiers().contains(Modifier.ABSTRACT)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 ExecutableElement getter = (ExecutableElement) child.getAccessElement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), getter);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
622 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
623
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
624 List<NodeExecutionData> executions = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
625 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
626 if (execution.getChild() == child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
627 executions.add(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
629 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
630
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
631 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
632 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
633 builder.startReturn().startNewArray((ArrayType) child.getOriginalType(), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
634 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
635 builder.string(nodeFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
636 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
637 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
638 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
639 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
640 builder.startReturn().string("this.").string(nodeFieldName(execution)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
641 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
642 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
643 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
644 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
645 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
646 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
647 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
648
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
649 private boolean isTypeBoxingEliminated(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
650 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
651 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
652 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
653
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
654 TypeBoxingOptimization optimization = options.monomorphicTypeBoxingOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
655 if (isTypeBoxingOptimized(optimization, specialization.getReturnType().getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
656 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
657 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
658 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
659 if (isTypeBoxingOptimized(optimization, p.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
660 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
661 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
662 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
663 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
664
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
665 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
666
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
667 private Set<Integer> getEvaluatedCounts() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
668 Set<Integer> evaluatedCount = new TreeSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
669 Collection<TypeData> returnSpecializedTypes = node.findSpecializedReturnTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
670 for (ExecutableTypeData execType : node.getExecutableTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
671 if (shouldImplementExecutableType(returnSpecializedTypes, execType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
672 evaluatedCount.add(execType.getEvaluatedCount());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
673 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
674 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
675 return evaluatedCount;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
676 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
677
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
678 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
679
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
680 private Element createUnsupported() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
681 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
682 if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
683 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
684 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
685 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
686
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
687 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), genericType.getPrimitiveType(), "unsupported", FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
688 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
689
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
690 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
691 builder.startReturn();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
692 builder.tree(callTemplateMethod(accessParent(null), fallback, locals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
693 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
694
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
695 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
696 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
697
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
698 private boolean isSingleSpecializable(List<SpecializationData> reachableSpecializations) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
699 if (reachableSpecializations.size() != 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
700 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702 return !reachableSpecializations.get(0).hasRewrite(context);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 private List<SpecializationData> getReachableSpecializations() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 List<SpecializationData> specializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708 if (specialization.isReachable() && //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709 (specialization.isSpecialized() //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
710 || (specialization.isFallback() && optimizeFallback(specialization)))) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711 specializations.add(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
712 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 return specializations;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
715 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
716
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
717 private boolean optimizeFallback(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
718 switch (options.optimizeFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
719 case NEVER:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
721 case DECLARED:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
722 return specialization.getMethod() != null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 case ALWAYS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725 default:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
726 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
728 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
729
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
730 private CodeExecutableElement createExecutableTypeOverride(ExecutableTypeData execType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
731 final String varArgsName = "args";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
732 final TypeData returnType = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 final TypeData executedType = execType.getEvaluatedCount() > 0 ? null : returnType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
734
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
735 CodeExecutableElement method = cloneExecutableTypeOverride(execType, varArgsName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
736
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
737 LocalContext locals = LocalContext.load(this, execType.getSignatureSize());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
738
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
739 // rename varargs parameter
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
740 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
741 for (Parameter parameter : execType.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
742 if (parameter.isTypeVarArgs()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
743 String newName = varArgsName + "[" + parameter.getTypeVarArgsIndex() + "]";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
744 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
745 locals.setValue(execution, locals.getValue(execution).accessWith(CodeTreeBuilder.singleString(newName)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
746 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
747 signatureIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
748 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
749
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
750 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
751
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
752 // create acceptAndExecute
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
753 CodeTreeBuilder executeBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
754 executeBuilder.startCall(specializationStartFieldName(), TypeSystemNodeFactory.executeName(executedType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
755 Parameter frame = execType.getFrame();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
756 if (frame == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
757 executeBuilder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
758 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
759 executeBuilder.string(frame.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
760 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 locals.addReferencesTo(executeBuilder);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
762 executeBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
763
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
764 CodeTreeBuilder contentBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
765 contentBuilder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
766 contentBuilder.tree(TypeSystemCodeGenerator.expect(executedType, returnType, executeBuilder.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
767 contentBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
769 // try catch assert if unexpected value is not expected
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770 if (!execType.hasUnexpectedValue(context) && !returnType.isGeneric() && !returnType.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
772 builder.tree(contentBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774 builder.startThrow().startNew(getType(AssertionError.class)).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
776 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777 builder.tree(contentBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
778 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
779
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783 private CodeExecutableElement cloneExecutableTypeOverride(ExecutableTypeData execType, final String varArgsName) throws AssertionError {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), execType.getMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
786 method.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 if (!execType.getMethod().isVarArgs() && execType.getParameters().size() != method.getParameters().size()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
790 throw new AssertionError("Should be verified in the parser");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
791 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
792
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
793 // align argument names
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 int index = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 for (Parameter parameter : execType.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 CodeVariableElement var = (CodeVariableElement) method.getParameters().get(index);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 if (parameter.isTypeVarArgs()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799 var.setName(varArgsName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
800 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 var.setName(LocalVariable.fromParameter(parameter).createParameter().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
808
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
809 private boolean shouldImplementExecutableType(Collection<TypeData> specializedTypes, ExecutableTypeData execType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 TypeData type = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 Set<Modifier> modifiers = execType.getMethod().getModifiers();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 if (modifiers.contains(FINAL) || modifiers.contains(STATIC) || modifiers.contains(PRIVATE)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 } else if (execType.isAbstract()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 } else if (type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
818 } else if (type.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
820 if (isTypeBoxingOptimized(options.voidBoxingOptimization(), specializedType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
821 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
822 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
823 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
824 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
825 } else if (!specializedTypes.contains(type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 } else if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
831 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
832
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 private Element createMethodGetSpecializationNode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
834 TypeMirror returntype = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returntype, "getSpecializationNode");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 method.createBuilder().startReturn().string(specializationStartFieldName()).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
838 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 private TypeMirror getType(Class<?> clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 return context.getType(clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844 private CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846 childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847 setVisibility(childField.getModifiers(), visibility);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 return childField;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
851 private static List<ExecutableTypeData> resolveSpecializedExecutables(NodeExecutionData execution, Collection<TypeData> types, TypeBoxingOptimization optimization) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 if (optimization == TypeBoxingOptimization.NONE) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853 return Collections.emptyList();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
854 } else if (types.isEmpty()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
855 return Collections.emptyList();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 List<ExecutableTypeData> executables = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859 for (TypeData type : types) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 if (!isTypeBoxingOptimized(optimization, type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
862 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
863 ExecutableTypeData foundType = execution.getChild().getNodeData().findExecutableType(type, execution.getChild().getExecuteWith().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 if (foundType != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
865 executables.add(foundType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
866 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
867 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
868 return executables;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
869 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
870
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
871 private static CodeTree callTemplateMethod(CodeTree receiver, TemplateMethod method, CodeTree... boundValues) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
872 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873 if (method.getMethod().getModifiers().contains(STATIC)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874 builder.startStaticCall(method.getMethod().getEnclosingElement().asType(), method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
876 builder.startCall(receiver, method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 int index = -1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
879 for (Parameter parameter : method.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
881 if (index < boundValues.length) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
882 CodeTree tree = boundValues[index];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
883 if (tree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
884 builder.tree(tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
885 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
886 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
887 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
888 builder.string(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
892 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
893
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
894 private static CodeTree callTemplateMethod(CodeTree receiver, TemplateMethod method, LocalContext currentValues) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
895 CodeTree[] bindings = new CodeTree[method.getParameters().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
896
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
897 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898 for (int i = 0; i < bindings.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 Parameter parameter = method.getParameters().get(i);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
900
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
901 LocalVariable var = currentValues.get(parameter, signatureIndex);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
902 if (var == null) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
903 var = currentValues.get(parameter.getLocalName());
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
904 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
905
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
906 if (var != null) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
907 CodeTree valueReference = var.createReference();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
908 if (parameter.getTypeSystemType() != null && var.getType() != null && var.getType().needsCastTo(parameter.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
909 valueReference = TypeSystemCodeGenerator.cast(parameter.getTypeSystemType(), valueReference);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
910 } else if (ElementUtils.needsCastTo(var.getTypeMirror(), parameter.getType())) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
911 valueReference = CodeTreeBuilder.createBuilder().cast(parameter.getType(), valueReference).build();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
912 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 bindings[i] = valueReference;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
915
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 if (parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917 signatureIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
918 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
920 return callTemplateMethod(receiver, method, bindings);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
922
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 private SpecializationGroup createSpecializationGroups() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
924 return SpecializationGroup.create(getReachableSpecializations());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
925 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
926
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
927 private CodeTree createSlowPathExecute(SpecializationData specialization, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
928 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
930 return builder.returnNull().build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
932 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
933 builder.tree(createTransferToInterpreterAndInvalidate());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
934 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
935 for (SpecializationData otherSpeciailzation : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 if (otherSpeciailzation == specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
937 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
938 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
939 if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
940 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
941 builder.tree(accessParent(excludedFieldName(otherSpeciailzation)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
942 builder.string(" = true");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
947 builder.startReturn().tree(createCallCreateMethod(specialization, null, currentValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
948
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
949 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
950 CodeTreeBuilder checkHasSeenBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
951 checkHasSeenBuilder.startIf().string("!").tree(accessParent(excludedFieldName(specialization))).end().startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
952 checkHasSeenBuilder.tree(builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 checkHasSeenBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 return checkHasSeenBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
955 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
956 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
959 private static boolean hasFallthrough(SpecializationGroup group, TypeData forType, LocalContext currentValues, boolean fastPath) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 for (TypeGuard guard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
961 if (currentValues.getValue(guard.getSignatureIndex()) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
962 // not evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
963 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
964 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
965 LocalVariable value = currentValues.getValue(guard.getSignatureIndex());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
966 if (value.getType().needsCastTo(guard.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
969 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
970
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
971 List<GuardExpression> expressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
972 expressions.removeAll(group.findElseConnectableGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
973 if (!expressions.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
975 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
976
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
977 if ((!fastPath || forType.isGeneric()) && !group.getAssumptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
978 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 if (!fastPath && group.getSpecialization() != null && !group.getSpecialization().getExceptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
982 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
983 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
984
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
985 if (!group.getChildren().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 return hasFallthrough(group.getChildren().get(group.getChildren().size() - 1), forType, currentValues, fastPath);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
987 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
988
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
989 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
990 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
991
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 private Element createGetSuppliedChildren() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
993 ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
994
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
995 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), nodeArray, "getSuppliedChildren");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
997
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
998 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
999
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1000 builder.startReturn().startNewArray(nodeArray, null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 for (int i = 0; i < node.getChildExecutions().size(); i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1002 NodeExecutionData execution = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1005 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006 builder.tree(accessParent(nodeFieldName(execution)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1007 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1008 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1009
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1010 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1011 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1012
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1013 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1014
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1015 private CodeTree createCallCreateMethod(SpecializationData specialization, String rootName, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1016 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1017
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1018 TypeMirror specializationType = specializationType(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019 if (options.useLazyClassLoading()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 builder.startStaticCall(specializationType(specialization), "create");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1021 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1022 builder.startNew(specializationType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1023 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1024 if (rootName != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1025 builder.string(rootName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1026 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1027 builder.string("root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1028 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1029 if (currentValues != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1030 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1031 LocalVariable local = currentValues.get(p.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1032 CodeVariableElement var = createImplicitProfileParameter(p.getSpecification().getExecution(), p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1033 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1034 builder.tree(local.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1035 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1036 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1037 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1038 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1039
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1040 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1041 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1042
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1043 private Element createSpecializationCreateMethod(SpecializationData specialization, CodeExecutableElement constructor) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1044 if (!options.useLazyClassLoading()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1045 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1046 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1047
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1048 CodeExecutableElement executable = CodeExecutableElement.clone(context.getEnvironment(), constructor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1049
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1050 TypeMirror specializationType = specializationType(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1051
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1052 executable.setReturnType(TypeSystemNodeFactory.nodeType(typeSystem));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1053 executable.setSimpleName(CodeNames.of("create"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1054 executable.getModifiers().add(STATIC);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1055
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1056 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1057 builder.startReturn().startNew(specializationType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1058 for (VariableElement parameter : executable.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1059 builder.string(parameter.getSimpleName().toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1060 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1061 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1062 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1063 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1064
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1065 private static String implicitClassFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1066 return execution.getName() + "ImplicitType";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1067 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1068
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1069 private static String implicitNodeFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1070 return execution.getName() + "Cast";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1071 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1072
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1073 private CodeExecutableElement createSpecializationConstructor(CodeTypeElement clazz, SpecializationData specialization, String constantIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1074 CodeExecutableElement constructor = new CodeExecutableElement(modifiers(), null, clazz.getSimpleName().toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1075
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1076 constructor.addParameter(new CodeVariableElement(nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1077 CodeTreeBuilder builder = constructor.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1078
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1079 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1080 if (constantIndex == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1081 builder.statement("super(index)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1082 constructor.addParameter(new CodeVariableElement(getType(int.class), "index"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1083 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1084 builder.startStatement().startSuperCall().string(constantIndex).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1085 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1086 builder.statement("this.root = root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1087 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1088 int index = resolveSpecializationIndex(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1089 builder.startStatement().startSuperCall().string("root").string(String.valueOf(index)).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1090
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1091 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1092 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1093
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1094 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1095 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1096 LocalVariable var = LocalVariable.fromParameter(p).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1097
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1098 String implicitFieldName = implicitProfile.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1099 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1100 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1101 CodeTree implicitType = TypeSystemCodeGenerator.implicitType(p.getTypeSystemType(), var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1102 builder.startStatement().string("this.").string(implicitFieldName).string(" = ").tree(implicitType).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1103 } else if (options.implicitCastOptimization().isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1104 // use node that supports polymorphism
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1105 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1106 builder.startStatement().string("this.").string(implicitFieldName).string(" = ").tree(ImplicitCastNodeFactory.create(p.getTypeSystemType(), var.createReference())).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1107 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1108 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1109 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1110 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1111 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1112 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1113
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1114 if (constructor.getParameters().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 // do not generate default constructor
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1116 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1118 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1120
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1121 // TODO this logic can be inlined to the parser as soon as the old NodeGen layout is gone
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1122 private static int resolveSpecializationIndex(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1124 return Integer.MAX_VALUE - 1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 } else if (specialization.isUninitialized()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1126 return Integer.MAX_VALUE;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1127 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1128 return 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130 return specialization.getIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1131 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1132 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1133
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1134 private CodeTree createCallNext(TypeData forType, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1135 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1136 builder.startCall("next", TypeSystemNodeFactory.executeName(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1137 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1138 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1139 return TypeSystemCodeGenerator.expect(genericType, forType, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1140 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1141
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1142 private static CodeTree createCallDelegate(String methodName, String reason, TypeData forType, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1143 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1144 builder.startCall(methodName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1145 if (reason != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1146 builder.doubleQuote(reason);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1147 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1148 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1149 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1150
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1151 TypeData executedType = forType.getTypeSystem().getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1152 return TypeSystemCodeGenerator.expect(executedType, forType, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1153 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1155 private Set<ExecutableTypeData> findSpecializedExecutableTypes(NodeExecutionData execution, TypeData type) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1156 ExecutableTypeData executableType = resolveExecutableType(execution.getChild(), type);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1157 Set<ExecutableTypeData> executedTypes = new HashSet<>();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1158 executedTypes.add(executableType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1159 if (type.hasImplicitSourceTypes()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1160 executedTypes.addAll(resolveSpecializedExecutables(execution, type.getImplicitSourceTypes(), options.implicitTypeBoxingOptimization()));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1161 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1162 return executedTypes;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1163 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1164
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1165 private ExecutableTypeData resolveExecutableType(NodeChildData child, TypeData type) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1166 int executeWithCount = child.getExecuteWith().size();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1167 ExecutableTypeData executableType = child.getNodeData().findExecutableType(type, executeWithCount);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1168 if (executableType == null) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1169 executableType = child.getNodeData().findAnyGenericExecutableType(context, executeWithCount);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1170 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1171 return executableType;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1172 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1173
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1174 private boolean hasUnexpectedResult(NodeExecutionData execution, TypeData type) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1175 for (ExecutableTypeData executableType : findSpecializedExecutableTypes(execution, type)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1176 if (executableType != null && executableType.hasUnexpectedValue(context)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1177 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1178 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1179 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1180 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1181 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1182
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1183 private Element createFastPathExecuteMethod(SpecializationData specialization, final TypeData forType, int evaluatedArguments) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1184 TypeData type = forType == null ? genericType : forType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1185 LocalContext currentLocals = LocalContext.load(this, evaluatedArguments);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1186
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1187 CodeExecutableElement executable = currentLocals.createMethod(modifiers(PUBLIC), type.getPrimitiveType(), TypeSystemNodeFactory.executeName(forType), FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1188 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1189
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1190 if (!type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1191 executable.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1192 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1193
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1194 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1195
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1196 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1197 LocalVariable var = currentLocals.getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1198 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1199 TypeData targetType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1200 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1201 targetType = genericType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1202 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1203 targetType = specialization.findParameterOrDie(execution).getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1204 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1205 LocalVariable shortCircuit = resolveShortCircuit(specialization, execution, currentLocals);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1206 LocalVariable value = currentLocals.createValue(execution, targetType).nextName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1207 builder.tree(createAssignExecuteChild(execution, type, value, shortCircuit, currentLocals));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1208 currentLocals.setValue(execution, value);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1209 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1210 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1211
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 LocalContext originalValues = currentLocals.copy();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1213 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1214 builder.startReturn().tree(createCallDelegate("acceptAndExecute", null, type, currentLocals)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1215 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1216 builder.startReturn().tree(createCallNext(type, currentLocals)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1217 } else if (specialization.isUninitialized()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1218 builder.startReturn().tree(createCallDelegate("uninitialized", null, type, currentLocals)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1219 } else {
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1220 final TypeData finalType = type;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1221 SpecializationGroup group = SpecializationGroup.create(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1222 SpecializationExecution executionFactory = new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1223 public CodeTree createExecute(SpecializationData s, LocalContext values) {
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1224 return createFastPathExecute(finalType, s, values);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1225 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1226
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1227 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1228 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1229 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1230 };
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1231 builder.tree(createGuardAndCast(group, type, currentLocals, executionFactory));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1232 if (hasFallthrough(group, type, originalValues, true) || group.getSpecialization().isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1233 builder.startReturn().tree(createCallNext(type, originalValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1234 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1235 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1236
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1237 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1238 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1239
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1240 private LocalVariable resolveShortCircuit(SpecializationData specialization, NodeExecutionData execution, LocalContext currentLocals) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241 LocalVariable shortCircuit = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 SpecializationData resolvedSpecialization = specialization;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1243 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244 resolvedSpecialization = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1245 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1248 ShortCircuitData shortCircuitData = resolvedSpecialization.getShortCircuits().get(calculateShortCircuitIndex(execution));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1249 CodeTree access = callTemplateMethod(accessParent(null), shortCircuitData, currentLocals);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 shortCircuit = currentLocals.createShortCircuitValue(execution).accessWith(access);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1251 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1252 return shortCircuit;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1253 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1254
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1255 private int calculateShortCircuitIndex(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1256 int shortCircuitIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1257 for (NodeExecutionData otherExectuion : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1258 if (otherExectuion.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1259 if (otherExectuion == execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1260 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1261 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1262 shortCircuitIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1263 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1264 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1265 return shortCircuitIndex;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1266 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1267
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1268 private CodeTree createFastPathExecute(final TypeData forType, SpecializationData specialization, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1269 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1270 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1271 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272 builder.startIf().startCall("guardFallback");
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1273 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1274 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1275 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276 currentValues.addReferencesTo(builder);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1277
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1278 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1279 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1280 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1283 CodeTreeBuilder execute = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1284 execute.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1285 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1286 execute.startCall("unsupported");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1287 currentValues.addReferencesTo(execute, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1288 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1289 } else {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1290 execute.tree(callTemplateMethod(accessParent(null), specialization, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1291 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1292 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 builder.tree(createFastPathTryCatchRewriteException(specialization, forType, currentValues, execute.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1295 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1296 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1298
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1299 private CodeTree createGuardAndCast(SpecializationGroup group, TypeData forType, LocalContext currentValues, SpecializationExecution execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1302 Set<TypeGuard> castGuards;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1303 if (execution.isFastPath()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1304 castGuards = null; // cast all
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1305 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1306 castGuards = new HashSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1307 for (TypeGuard castGuard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1308 if (isTypeGuardUsedInAnyGuardBelow(group, currentValues, castGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1309 castGuards.add(castGuard);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1310 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1311 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1312 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1313 CodeTree[] checkAndCast = createTypeCheckAndCast(group.getTypeGuards(), castGuards, currentValues, execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1314 CodeTree check = checkAndCast[0];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1315 CodeTree cast = checkAndCast[1];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1316
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1317 List<GuardExpression> elseGuardExpressions = group.findElseConnectableGuards();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1318 List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1319 guardExpressions.removeAll(elseGuardExpressions);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1320 CodeTree methodGuards = createMethodGuardCheck(guardExpressions, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1321
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1322 if (!group.getAssumptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1323 if (execution.isFastPath() && !forType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1324 cast = appendAssumptionFastPath(cast, group.getAssumptions(), forType, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1325 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1326 methodGuards = appendAssumptionSlowPath(methodGuards, group.getAssumptions());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1327 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1328 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1329
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1330 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1331 if (!check.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1332 builder.startIf();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1333 builder.tree(check).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1334 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1335 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1336 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1337 if (!cast.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1338 builder.tree(cast);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1339 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1340 boolean elseIf = !elseGuardExpressions.isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1341 if (!methodGuards.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1342 builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1343 builder.tree(methodGuards).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1344 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1345 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1346 } else if (elseIf) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1347 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1348 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1349 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1350
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1351 boolean reachable = isReachableGroup(group, ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1352 if (reachable) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1354 builder.tree(createGuardAndCast(child, forType, currentValues.copy(), execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1355 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1356 SpecializationData specialization = group.getSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1357 if (specialization != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1358 builder.tree(execution.createExecute(specialization, currentValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1359 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1360 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1361 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1362
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1363 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1364 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1365
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1366 private static CodeTree appendAssumptionSlowPath(CodeTree methodGuards, List<String> assumptions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1367 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1368
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1369 builder.tree(methodGuards);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1370 String connect = methodGuards.isEmpty() ? "" : " && ";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1371 for (String assumption : assumptions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1372 builder.string(connect);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1373 builder.startCall(accessParent(assumptionName(assumption)), "isValid").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1374 connect = " && ";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1375 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1376
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1377 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1378 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1379
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1380 private CodeTree appendAssumptionFastPath(CodeTree casts, List<String> assumptions, TypeData forType, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1381 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1382 builder.tree(casts);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1383 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1384 for (String assumption : assumptions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1385 builder.startStatement().startCall(accessParent(assumptionName(assumption)), "check").end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1386 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1387 builder.end().startCatchBlock(getType(InvalidAssumptionException.class), "ae");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1388 builder.startReturn().tree(createCallNext(forType, currentValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1389 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1390 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1391 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1392
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1393 private static boolean isReachableGroup(SpecializationGroup group, int ifCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1394 if (ifCount != 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1395 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1396 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1397 SpecializationGroup previous = group.getPreviousGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1398 if (previous == null || previous.findElseConnectableGuards().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1399 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1400 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1401
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1402 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1403 * Hacky else case. In this case the specialization is not reachable due to previous else
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1404 * branch. This is only true if the minimum state is not checked.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1405 */
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1406 if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() && previous.getAssumptions().isEmpty() &&
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1407 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1408 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1409 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1410
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1411 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1412 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1413
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1414 private boolean isTypeGuardUsedInAnyGuardBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1415 NodeExecutionData execution = node.getChildExecutions().get(typeGuard.getSignatureIndex());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1416
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1417 for (GuardExpression guard : group.getGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1418 List<Parameter> guardParameters = guard.getResolvedGuard().findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1419 TypeData sourceType = currentValues.getValue(typeGuard.getSignatureIndex()).getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1420
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1421 for (Parameter guardParameter : guardParameters) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1422 if (sourceType.needsCastTo(guardParameter.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1423 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1424 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1425 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1426 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1427
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1428 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1429 if (isTypeGuardUsedInAnyGuardBelow(child, currentValues, typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1430 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1431 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1432 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1433
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1434 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1435 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1436
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1437 private CodeExecutableElement createExecuteChildMethod(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1438 LocalContext locals = LocalContext.load(this, 0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1439
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1440 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), targetType.getPrimitiveType(), executeChildMethodName(execution, targetType), FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1441 if (hasUnexpectedResult(execution, targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1442 method.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1443 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1444
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1445 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1446 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1447 method.addParameter(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1448 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1449
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1450 for (int i = 0; i < execution.getChild().getExecuteWith().size(); i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1451 NodeExecutionData executeWith = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1452 LocalVariable var = locals.createValue(executeWith, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1453 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1454 locals.setValue(executeWith, var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1455 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1456
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1457 CodeTreeBuilder builder = method.createBuilder();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1458 CodeTree executeChild = createExecuteChild(execution, locals.createValue(execution, targetType), locals, true);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1459 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1460 builder.statement(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1461 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1462 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1463 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1464 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1465 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1466
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1467 private CodeVariableElement createImplicitProfileParameter(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1468 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1469 switch (options.implicitCastOptimization()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1470 case NONE:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1471 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1472 case DUPLICATE_TAIL:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1473 return new CodeVariableElement(getType(Class.class), implicitClassFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1474 case MERGE_CASTS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1475 return new CodeVariableElement(ImplicitCastNodeFactory.type(targetType), implicitNodeFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1476 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1477 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1478 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1479 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1480
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1481 private boolean isExecuteChildShared(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1482 if (targetType.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1483 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1484 } else if (targetType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1485 if (isSingleSpecializable(getReachableSpecializations())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1486 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1487 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1488 return resolveSpecializedExecutables(execution, node.findSpecializedTypes(execution), options.polymorphicTypeBoxingElimination()).size() >= 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1489 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1490 if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1491 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1492 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1493 if (!targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1494 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1495 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1496
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1497 int uses = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1498 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1499 List<Parameter> parameters = specialization.findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1500 for (Parameter parameter : parameters) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1501 if (targetType.equals(parameter.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1502 uses++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1503 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1504 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1505 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1506 if (uses > 1) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1507 return resolveSpecializedExecutables(execution, targetType.getImplicitSourceTypes(), options.implicitTypeBoxingOptimization()).size() > 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1508 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1509 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1510 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1511 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1512 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1513
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1514 private CodeTree createAssignExecuteChild(NodeExecutionData execution, TypeData returnType, LocalVariable targetValue, LocalVariable shortCircuit, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1515 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1516 boolean hasUnexpected = hasUnexpectedResult(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1517
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1518 CodeTree executeChild;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1519 if (isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1520 executeChild = createCallSharedExecuteChild(execution, targetValue, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1521 } else {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1522 executeChild = createExecuteChild(execution, targetValue, currentValues, false);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1523 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1524
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1525 builder.tree(createTryExecuteChild(targetValue, executeChild, shortCircuit == null, hasUnexpected));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1526 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1527 if (hasUnexpected) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1528 builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1529
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1530 LocalContext slowPathValues = currentValues.copy();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1531 slowPathValues.setValue(execution, targetValue.makeGeneric().accessWith(CodeTreeBuilder.singleString("ex.getResult()")));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1532 boolean found = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1533 for (NodeExecutionData otherExecution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1534 if (found) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1535 LocalVariable childEvaluatedValue = slowPathValues.createValue(otherExecution, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1536 LocalVariable genericShortCircuit = resolveShortCircuit(null, otherExecution, slowPathValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1537 builder.tree(createAssignExecuteChild(otherExecution, genericType, childEvaluatedValue, genericShortCircuit, slowPathValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1538 slowPathValues.setValue(otherExecution, childEvaluatedValue);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1539 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1540 // skip forward already evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1541 found = execution == otherExecution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1542 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1543 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1544 builder.startReturn().tree(createCallNext(returnType, slowPathValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1545 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1546 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1547
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1548 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1549 currentValues.setShortCircuitValue(execution, shortCircuit.accessWith(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1550 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1551 return createShortCircuit(targetValue, shortCircuit, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1552 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1553
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1554 private static CodeTree createShortCircuit(LocalVariable targetValue, LocalVariable shortCircuitValue, CodeTree tryExecute) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1555 if (shortCircuitValue == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1556 return tryExecute;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1557 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1558
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1559 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1560
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1561 builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1562 builder.tree(targetValue.createDeclaration(builder.create().defaultValue(targetValue.getTypeMirror()).build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1563
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1564 builder.startIf().string(shortCircuitValue.getName()).end().startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1565 builder.tree(tryExecute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1566 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1567
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1568 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1569 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1570
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1571 private static CodeTree createTryExecuteChild(LocalVariable value, CodeTree executeChild, boolean needDeclaration, boolean hasTry) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1572 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1573 boolean hasDeclaration = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1574 if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1575 builder.tree(value.createDeclaration(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1576 hasDeclaration = true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1577 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1578
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1579 if (hasTry) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1580 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1581 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1582 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1583 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1584
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1585 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1586 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1587 if (hasDeclaration || !needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1588 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1589 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1590 builder.type(value.getTypeMirror()).string(" ").tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1591 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1592 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1593 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1594 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1595 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1596
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1597 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1598
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1599 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1600 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1601
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1602 private CodeTree createCallSharedExecuteChild(NodeExecutionData execution, LocalVariable targetValue, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1603 if (!isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1604 throw new AssertionError("Execute child not shared with method but called.");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1605 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1606
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1607 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1608 builder.tree(targetValue.createReference()).string(" = ");
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1609 builder.startCall(executeChildMethodName(execution, targetValue.getType()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1610 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1611
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1612 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1613 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1614 builder.string(implicitProfile.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1615 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1616 for (int i = 0; i < execution.getChild().getExecuteWith().size(); i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1617 builder.tree(currentValues.getValue(i).createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1618 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1619 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1620 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1621 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1622
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1623 private CodeTree createExecuteChild(NodeExecutionData execution, LocalVariable target, LocalContext currentValues, boolean shared) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1624 final CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1625
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1626 CodeTree assignment = createAssignmentStart(target, shared);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1627
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1628 final Set<ExecutableTypeData> executableTypes = findSpecializedExecutableTypes(execution, target.getType());
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1629 if (executableTypes.isEmpty()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1630 throw new AssertionError(); // cannot execute child
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1631 } else if (executableTypes.size() == 1) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1632 ExecutableTypeData executableType = executableTypes.iterator().next();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1633 if (target.getType().isGeneric() && executableType.getEvaluatedCount() == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1634 return createPolymorphicExecuteChild(execution, target, currentValues, shared);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1635 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1636 builder.tree(assignment);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1637 builder.tree(createSingleExecute(execution, target, currentValues, executableType));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1638 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1639 } else {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1640 if (options.implicitCastOptimization().isNone()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1641 throw new AssertionError("findSpecializedExecutableTypes is always 1 if implicit cast opt is disabled");
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1642 } else if (options.implicitCastOptimization().isDuplicateTail()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1643 builder.tree(createExecuteChildDuplicateTail(builder, execution, assignment, target, currentValues));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1644 } else if (options.implicitCastOptimization().isMergeCasts()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1645 // TODO
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1646 throw new UnsupportedOperationException();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1647 } else {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1648 throw new AssertionError();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1649 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1650 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1651 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1652 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1653
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1654 private static CodeTree createSingleExecute(NodeExecutionData execution, LocalVariable target, LocalContext currentValues, ExecutableTypeData executableType) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1655 CodeTree accessChild = accessParent(nodeFieldName(execution));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1656 CodeTree execute = callTemplateMethod(accessChild, executableType, currentValues);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1657 return TypeSystemCodeGenerator.expect(executableType.getType(), target.getType(), execute);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1658 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1659
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1660 private CodeTree createPolymorphicExecuteChild(NodeExecutionData execution, LocalVariable target, LocalContext currentValues, boolean shared) throws AssertionError {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1661 ExecutableTypeData genericExecutableType = execution.getChild().getNodeData().findAnyGenericExecutableType(context, execution.getChild().getExecuteWith().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1662 if (genericExecutableType == null) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1663 throw new AssertionError("At least one generic executable method must be available.");
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1664 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1665
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1666 Set<TypeData> specializedTypes = new HashSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1667 for (TypeData type : node.findSpecializedTypes(execution)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1668 specializedTypes.addAll(type.getImplicitSourceTypes());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1669 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1670
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1671 List<ExecutableTypeData> specializedExecutables = resolveSpecializedExecutables(execution, specializedTypes, options.polymorphicTypeBoxingElimination());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1672 Collections.sort(specializedExecutables, new Comparator<ExecutableTypeData>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1673 public int compare(ExecutableTypeData o1, ExecutableTypeData o2) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1674 return o1.getType().compareTo(o2.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1675 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1676 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1677
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1678 CodeTree assignment = createAssignmentStart(target, shared);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1679 CodeTree executeGeneric = createSingleExecute(execution, target, currentValues, genericExecutableType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1680
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1681 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1682 if (specializedExecutables.isEmpty() || isSingleSpecializable(getReachableSpecializations())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1683 builder.tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1684 builder.tree(executeGeneric);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1685 } else {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1686 final CodeTreeBuilder polyChainBuilder = builder.create();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1687 final String profileField = polymorphicTypeProfileFieldName(execution);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1688 final String valueFieldName = "_value";
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1689
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1690 builder.declaration(getType(Class.class), profileField, accessParent(profileField));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1691
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1692 boolean encounteredUnexpectedResult = false;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1693 boolean hasSpecializedTypes = false;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1694 for (ExecutableTypeData executableType : specializedExecutables) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1695 hasSpecializedTypes = polyChainBuilder.startIf(hasSpecializedTypes);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1696 polyChainBuilder.string(profileField);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1697 polyChainBuilder.string(" == ").typeLiteral(executableType.getType().getPrimitiveType());
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1698 polyChainBuilder.end();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1699 polyChainBuilder.startBlock();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1700 polyChainBuilder.startStatement();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1701 polyChainBuilder.tree(assignment);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1702 polyChainBuilder.tree(createSingleExecute(execution, target, currentValues, executableType)).end();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1703 polyChainBuilder.end();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1704 encounteredUnexpectedResult |= executableType.hasUnexpectedValue(context);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1705 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1706
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1707 // else if null -> specialize
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1708 polyChainBuilder.startElseIf().string(profileField).string(" == null").end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1709 polyChainBuilder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1710 polyChainBuilder.tree(createTransferToInterpreterAndInvalidate());
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1711 polyChainBuilder.declaration(genericExecutableType.getType().getPrimitiveType(), valueFieldName, executeGeneric);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1712
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1713 hasSpecializedTypes = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1714 for (ExecutableTypeData executableType : specializedExecutables) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1715 hasSpecializedTypes = polyChainBuilder.startIf(hasSpecializedTypes);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1716 polyChainBuilder.tree(TypeSystemCodeGenerator.check(executableType.getType(), CodeTreeBuilder.singleString(valueFieldName)));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1717 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1718 polyChainBuilder.startBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1719 polyChainBuilder.startStatement().tree(accessParent(profileField)).string(" = ").typeLiteral(executableType.getType().getPrimitiveType()).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1720 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1721 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1722
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1723 polyChainBuilder.startElseBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1724 polyChainBuilder.startStatement().tree(accessParent(profileField)).string(" = ").typeLiteral(genericType.getPrimitiveType()).end();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1725 polyChainBuilder.end();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1726 polyChainBuilder.startReturn().string(valueFieldName).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1727 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1728
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1729 // else -> execute generic
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1730 polyChainBuilder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1731 polyChainBuilder.startStatement().tree(assignment).tree(executeGeneric).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1732 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1733
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1734 CodeTree executePolymorphic = polyChainBuilder.build();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1735 if (encounteredUnexpectedResult) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1736 builder.startTryBlock();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1737 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1738 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1739 builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1740 builder.startStatement().tree(accessParent(profileField)).string(" = ").typeLiteral(genericType.getPrimitiveType()).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1741 builder.startReturn().string("ex.getResult()").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1742 builder.end();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1743 } else {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1744 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1745 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1746 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1747 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1748 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1749
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1750 private static CodeTree createAssignmentStart(LocalVariable target, boolean shared) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1751 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1752 if (shared) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1753 builder.string("return ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1754 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1755 builder.string(target.getName()).string(" = ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1756 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1757 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1758 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1759
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1760 private CodeTree createExecuteChildDuplicateTail(CodeTreeBuilder parent, NodeExecutionData execution, CodeTree assignment, LocalVariable target, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1761 CodeTreeBuilder builder = parent.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1762 List<TypeData> sourceTypes = target.getType().getImplicitSourceTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1763 String implicitClassFieldName = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1764 String nodeFieldName = nodeFieldName(execution);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1765 List<ExecutableTypeData> executableTypes = resolveSpecializedExecutables(execution, sourceTypes, options.implicitTypeBoxingOptimization());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1766
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1767 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1768 for (ExecutableTypeData executableType : executableTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1769 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1770 builder.string(implicitClassFieldName).string(" == ").typeLiteral(executableType.getType().getBoxedType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1771 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1772 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1773 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1774
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1775 CodeTree execute = callTemplateMethod(accessParent(nodeFieldName), executableType, currentValues);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1776 ImplicitCastData cast = typeSystem.lookupCast(executableType.getType(), target.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1777 if (cast != null) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1778 execute = callTemplateMethod(null, cast, execute);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1779 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1780 builder.tree(execute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1781 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1782 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1783 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1784
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1785 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1786 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1787 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1788
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1789 LocalVariable genericValue = target.makeGeneric().nextName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1790 LocalVariable genericShortCircuit = resolveShortCircuit(null, execution, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1791
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1792 builder.tree(createAssignExecuteChild(execution, genericValue.getType(), genericValue, genericShortCircuit, currentValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1793 if (executableTypes.size() == sourceTypes.size()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1794 builder.startThrow().startNew(getType(UnexpectedResultException.class)).tree(genericValue.createReference()).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1795 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1796 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1797 builder.tree(TypeSystemCodeGenerator.implicitExpect(target.getType(), genericValue.createReference(), implicitClassFieldName));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1798 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1799 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1800
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1801 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1802 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1803 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1804 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1805 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1806
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1807 private static CodeTree createFastPathTryCatchRewriteException(SpecializationData specialization, TypeData forType, LocalContext currentValues, CodeTree execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1808 if (specialization.getExceptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1809 return execution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1810 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1811 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1812 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1813 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1814 TypeMirror[] exceptionTypes = new TypeMirror[specialization.getExceptions().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1815 for (int i = 0; i < exceptionTypes.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1816 exceptionTypes[i] = specialization.getExceptions().get(i).getJavaClass();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1817 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1818 builder.end().startCatchBlock(exceptionTypes, "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1819 builder.startStatement().tree(accessParent(excludedFieldName(specialization))).string(" = true").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1820 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1821 builder.tree(createCallDelegate("remove", "threw rewrite exception", forType, currentValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1822 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1823 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1824 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1825 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1826
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1827 private static CodeTree createMethodGuardCheck(List<GuardExpression> guardExpressions, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1828 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1829 String and = "";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1830 for (GuardExpression guard : guardExpressions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1831 builder.string(and);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1832 if (guard.isNegated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1833 builder.string("!");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1834 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1835 builder.tree(callTemplateMethod(accessParent(null), guard.getResolvedGuard(), currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1836 and = " && ";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1837 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1838 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1839 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1840
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1841 private CodeTree[] createTypeCheckAndCast(List<TypeGuard> typeGuards, Set<TypeGuard> castGuards, LocalContext currentValues, SpecializationExecution specializationExecution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1842 CodeTreeBuilder checksBuilder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1843 CodeTreeBuilder castsBuilder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1844 for (TypeGuard typeGuard : typeGuards) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1845 int signatureIndex = typeGuard.getSignatureIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1846 LocalVariable value = currentValues.getValue(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1847 TypeData targetType = typeGuard.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1848 if (!value.getType().needsCastTo(targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1849 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1850 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1851 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1852 if (!checksBuilder.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1853 checksBuilder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1854 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1855
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1856 CodeTreeBuilder checkBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1857 CodeTreeBuilder castBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1858
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1859 LocalVariable shortCircuit = currentValues.getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1860 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1861 checkBuilder.string("(");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1862 CodeTreeBuilder referenceBuilder = checkBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1863 if (!shortCircuit.getType().isPrimitive()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1864 referenceBuilder.string("(boolean) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1865 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1866 referenceBuilder.tree(shortCircuit.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1867 checkBuilder.string("!").tree(referenceBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1868 checkBuilder.string(" || ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1869 castBuilder.tree(referenceBuilder.build()).string(" ? ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1870 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1871
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1872 List<ImplicitCastData> sourceTypes = typeSystem.lookupByTargetType(targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1873 CodeTree valueReference = value.createReference();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1874 if (sourceTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1875 checkBuilder.tree(TypeSystemCodeGenerator.check(targetType, value.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1876 castBuilder.tree(TypeSystemCodeGenerator.cast(targetType, valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1877 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1878 ImplicitCastOptimization opt = options.implicitCastOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1879 if (specializationExecution.isFastPath() && !opt.isNone()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1880 if (opt.isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1881 String typeHintField = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1882 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1883 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1884 } else if (opt.isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1885 checkBuilder.tree(ImplicitCastNodeFactory.check(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1886 castBuilder.tree(ImplicitCastNodeFactory.cast(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1887 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1888 throw new AssertionError("implicit cast opt");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1889 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1890 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1891 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1892 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1893 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1894 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1895
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1896 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1897 checkBuilder.string(")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1898 castBuilder.string(" : ").defaultValue(targetType.getPrimitiveType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1899 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1900
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1901 if (castGuards == null || castGuards.contains(typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1902 LocalVariable castVariable = currentValues.getValue(execution).nextName().newType(typeGuard.getType()).accessWith(null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1903 currentValues.setValue(execution, castVariable);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1904 castsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1905 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1906
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1907 checksBuilder.tree(checkBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1908 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1909 return new CodeTree[]{checksBuilder.build(), castsBuilder.build()};
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1910 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1911
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1912 public static final class LocalContext {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1913
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1914 private final NodeGenFactory factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1915 private final Map<String, LocalVariable> values = new HashMap<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1916
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1917 private LocalContext(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1918 this.factory = factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1919 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1920
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1921 public CodeExecutableElement createMethod(Set<Modifier> modifiers, TypeMirror returnType, String name, String... optionalArguments) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1922 CodeExecutableElement method = new CodeExecutableElement(modifiers, returnType, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1923 addParametersTo(method, optionalArguments);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1924 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1925 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1926
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1927 public static LocalContext load(NodeGenFactory factory, int signatureSize) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1928 LocalContext context = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1929 context.loadValues(signatureSize);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1930 return context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1931 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1932
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1933 public static LocalContext load(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1934 return load(factory, factory.node.getSignatureSize());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1935 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1936
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1937 public LocalContext copy() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1938 LocalContext copy = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1939 copy.values.putAll(values);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1940 return copy;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1941 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1942
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1943 private static String fieldValueName(NodeFieldData field) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1944 return field.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1945 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1946
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1947 @SuppressWarnings("static-method")
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1948 public LocalVariable createValue(NodeExecutionData execution, TypeData type) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1949 return new LocalVariable(type, type.getPrimitiveType(), valueName(execution), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1950 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1951
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1952 public LocalVariable createShortCircuitValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1953 return new LocalVariable(factory.typeSystem.getBooleanType(), factory.getType(boolean.class), shortCircuitName(execution), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1954 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1955
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1956 private static String valueName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1957 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1958 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1959
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1960 private static String shortCircuitName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1961 return "has" + ElementUtils.firstLetterUpperCase(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1962 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1963
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1964 public LocalVariable get(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1965 return values.get(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1966 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1967
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1968 public LocalVariable get(Parameter parameter, int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1969 LocalVariable var = get(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1970 if (var == null && parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1971 // lookup by signature index for executeWith
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1972 NodeExecutionData execution = factory.node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1973 var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1974 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1975 return var;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1976 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1977
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1978 public LocalVariable getValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1979 return get(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1980 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1981
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1982 public LocalVariable getValue(int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1983 return getValue(factory.node.getChildExecutions().get(signatureIndex));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1984 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1985
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1986 public void removeValue(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1987 values.remove(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1988 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1989
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1990 public void setValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1991 values.put(valueName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1992 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1993
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1994 public void setShortCircuitValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1995 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1996 return;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1997 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1998 values.put(shortCircuitName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1999 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2000
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2001 private boolean needsVarargs(boolean requireLoaded) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2002 int size = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2003 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2004 if (requireLoaded && getValue(execution) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2005 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2006 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2007 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2008 size += 2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2009 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2010 size++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2011 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2012 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2013 return size > 4;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2014 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2015
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2016 private void loadValues(int evaluatedArguments) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2017 values.put(FRAME_VALUE, new LocalVariable(null, factory.getType(Frame.class), FRAME_VALUE, null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2018
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2019 for (NodeFieldData field : factory.node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2020 String fieldName = fieldValueName(field);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2021 values.put(fieldName, new LocalVariable(null, field.getType(), fieldName, NodeGenFactory.accessParent(field.getName())));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2022 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2023
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2024 boolean varargs = needsVarargs(false);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2025 for (int i = 0; i < evaluatedArguments; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2026 NodeExecutionData execution = factory.node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2027 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2028 LocalVariable shortCircuit = createShortCircuitValue(execution).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2029 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2030 shortCircuit = shortCircuit.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2031 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2032 values.put(shortCircuit.getName(), shortCircuit);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2033 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2034 LocalVariable value = createValue(execution, factory.genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2035 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2036 value = value.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2037 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2038 values.put(value.getName(), value);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2039 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2040 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2041
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2042 private static CodeTree createReadVarargs(int i) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2043 return CodeTreeBuilder.createBuilder().string("args_[").string(String.valueOf(i)).string("]").build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2044 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2045
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2046 public void addReferencesTo(CodeTreeBuilder builder, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2047 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2048 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2049 if (local == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2050 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2051 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2052 builder.tree(local.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2053 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2054 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2055
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2056 List<NodeExecutionData> executions = factory.node.getChildExecutions();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2057 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2058 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2059 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2060 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2061 builder.tree(shortCircuitVar.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2062 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2063 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2064 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2065 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2066 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2067 if (executions.size() == 1 && ElementUtils.typeEquals(var.getTypeMirror(), factory.getType(Object[].class))) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2068 // if the current type is Object[] do not use varargs for a single argument
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2069 builder.string("(Object) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2070 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2071 builder.tree(var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2072 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2073 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2074 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2075 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2076
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2077 public void addParametersTo(CodeExecutableElement method, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2078 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2079 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2080 if (local != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2081 method.addParameter(local.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2082 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2083 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2084 if (needsVarargs(true)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2085 method.addParameter(new CodeVariableElement(factory.getType(Object[].class), "args_"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2086 method.setVarArgs(true);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2087 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2088 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2089 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2090 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2091 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2092 method.addParameter(shortCircuitVar.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2093 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2094 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2095
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2096 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2097 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2098 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2099 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2100 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2101 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2102 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2103
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2104 private LocalVariable getShortCircuit(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2105 return values.get(shortCircuitName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2106 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2107
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2108 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2109
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2110 public static final class LocalVariable {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2111
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2112 private final TypeData type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2113 private final TypeMirror typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2114 private final CodeTree accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2115 private final String name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2116
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2117 public static LocalVariable fromParameter(Parameter parameter) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2118 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2119 String name = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2120 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2121 name = parameter.getLocalName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2122 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2123 name = createName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2124 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2125 return new LocalVariable(parameter.getTypeSystemType(), parameter.getType(), name, null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2126 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2127
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2128 private LocalVariable(TypeData type, TypeMirror typeMirror, String name, CodeTree accessorTree) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2129 Objects.requireNonNull(typeMirror);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2130 this.typeMirror = typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2131 this.accessorTree = accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2132 this.type = type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2133 this.name = name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2134 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2135
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2136 public TypeData getType() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2137 return type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2138 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2139
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2140 public String getShortCircuitName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2141 return "has" + ElementUtils.firstLetterUpperCase(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2142 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2143
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2144 public String getName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2145 return name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2146 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2147
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2148 private static String createNextName(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2149 return name + "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2150 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2151
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2152 private static String createName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2153 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2154 return "<error>";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2155 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2156 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2157 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2158
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2159 public TypeMirror getTypeMirror() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2160 return typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2161 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2162
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2163 public CodeVariableElement createParameter() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2164 return new CodeVariableElement(getTypeMirror(), getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2165 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2166
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2167 public CodeTree createDeclaration(CodeTree init) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2168 return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2169 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2170
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2171 public CodeTree createReference() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2172 if (accessorTree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2173 return accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2174 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2175 return CodeTreeBuilder.singleString(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2176 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2177 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2178
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2179 public LocalVariable newType(TypeData newType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2180 return new LocalVariable(newType, newType.getPrimitiveType(), name, accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2181 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2182
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2183 public LocalVariable accessWith(CodeTree tree) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2184 return new LocalVariable(type, typeMirror, name, tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2185 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2186
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2187 public LocalVariable nextName() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2188 return new LocalVariable(type, typeMirror, createNextName(name), accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2189 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2190
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2191 public LocalVariable makeGeneric() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2192 return newType(type.getTypeSystem().getGenericTypeData());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2193 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2194
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2195 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2196
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2197 private interface SpecializationExecution {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2198
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2199 boolean isFastPath();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2200
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2201 CodeTree createExecute(SpecializationData specialization, LocalContext currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2202
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2203 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2204
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2205 }