annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 18787:6fe1d34a7b6e

Truffle-DSL: added bounds check for unrolling child arrays.
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 20:23:22 +0100
parents 93016f2f3f16
children 714f4931b02c
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;
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
62 private final boolean singleSpecializable;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 public NodeGenFactory(ProcessorContext context, NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 this.context = context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 this.node = node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 this.typeSystem = node.getTypeSystem();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 this.genericType = typeSystem.getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 this.options = typeSystem.getOptions();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
70 this.singleSpecializable = isSingleSpecializableImpl();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 public static String nodeTypeName(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 return resolveNodeId(node) + "NodeGen";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 private static String resolveNodeId(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 String nodeid = node.getNodeId();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 nodeid = nodeid.substring(0, nodeid.length() - 4);
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 return nodeid;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 public static TypeMirror nodeType(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 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
87 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 private static String specializationTypeName(SpecializationData specialization) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
90 String id;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
91 if (specialization == null) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
92 id = "Base";
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
93 } else {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
94 id = specialization.getId();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
95 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
96 return id + "Node_";
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
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
99 private TypeMirror specializationType(SpecializationData specialization) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
100 return new GeneratedTypeMirror(ElementUtils.getPackageName(node.getTemplateType()) + "." + nodeTypeName(node), specializationTypeName(specialization));
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 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
104 return execution.getName() + "Type" + 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 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
108 return execution.getName() + 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 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
112 return "specialization" + 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 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
116 return "exclude" + specialization.getId() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 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
120 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
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 CodeTree accessParent(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 if (name == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 return CodeTreeBuilder.singleString("root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127 return CodeTreeBuilder.createBuilder().string("root.").string(name).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
128 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 private static String assumptionName(String assumption) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 return assumption + "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133 }
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 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
136 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
137 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
138 clazz.getImplements().add(getType(SpecializedNode.class));
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 (String assumption : node.getAssumptions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 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
142 }
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 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 clazz.addOptional(createAccessChildMethod(child));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 for (NodeFieldData field : node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 if (!field.isGenerated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 continue;
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 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
154 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
155 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), field.getGetter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 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
158 clazz.add(method);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 }
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
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
162 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
163 clazz.add(createNodeConstructor(clazz, superConstructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 }
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 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 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
168 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 for (NodeExecutionData execution : node.getChildExecutions()) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
171 if (!resolvePolymorphicExecutables(execution).isEmpty()) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
172 clazz.add(createNodeField(PRIVATE, getType(Class.class), polymorphicTypeProfileFieldName(execution), CompilationFinal.class));
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
176 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
177 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 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
179 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182 clazz.add(createMethodGetSpecializationNode());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183 clazz.add(createDeepCopyMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 clazz.add(createGetCostMethod());
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 Collection<TypeData> specializedTypes = node.findSpecializedReturnTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
187 for (ExecutableTypeData execType : node.getExecutableTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
188 if (shouldImplementExecutableType(specializedTypes, execType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
189 clazz.add(createExecutableTypeOverride(execType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
190 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
191 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
192
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
193 SpecializationData specializationStart = createSpecializations(clazz);
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
194 SpecializationData finalSpecialization = singleSpecializable ? specializationStart : null;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
195
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
196 clazz.add(createNodeField(PRIVATE, specializationType(finalSpecialization), specializationStartFieldName(), Child.class));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
197
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 CodeTreeBuilder builder = ((CodeExecutableElement) constructor).appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
201 builder.string("this.").string(specializationStartFieldName());
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
202 builder.string(" = ").tree(createCallCreateMethod(specializationStart, "this", null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206 return clazz;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209 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
210 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
211 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
212
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213 List<CodeVariableElement> childParameters = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
216 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217 constructor.getParameters().addAll(superConstructor.getParameters().size(), childParameters);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
218
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
219 CodeTreeBuilder builder = constructor.appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
220 List<String> childValues = new ArrayList<>(node.getChildren().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
221 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
222 String name = child.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
223 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
224 CreateCastData createCast = node.findCast(child.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
225 if (createCast != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
226 CodeTree nameTree = CodeTreeBuilder.singleString(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
227 CodeTreeBuilder callBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
228 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
229 callBuilder.tree(callTemplateMethod(null, createCast, nameTree));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
230 callBuilder.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
231 name += "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
232 builder.declaration(child.getNodeType(), name, callBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
233 }
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 childValues.add(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
236 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
237
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
238 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
239 CreateCastData createCast = node.findCast(execution.getChild().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242 builder.string("this.").string(nodeFieldName(execution)).string(" = ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
243
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
244 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
245 CodeTreeBuilder accessorBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
246 accessorBuilder.string(name);
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 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
249 accessorBuilder.string("[").string(String.valueOf(execution.getIndex())).string("]");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
250 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
251
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
252 CodeTree accessor = accessorBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
253
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
254 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
255 accessor = callTemplateMethod(null, createCast, accessor);
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
258 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 CodeTreeBuilder nullCheck = builder.create();
18787
6fe1d34a7b6e Truffle-DSL: added bounds check for unrolling child arrays.
Christian Humer <christian.humer@gmail.com>
parents: 18785
diff changeset
260 nullCheck.string(name).string(" != null && ").string(String.valueOf(execution.getIndex())).string(" < ").string(name).string(".length").string(" ? ");
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261 nullCheck.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 nullCheck.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 accessor = nullCheck.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266 builder.tree(accessor);
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 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
269 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
274 private static boolean mayBeExcluded(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 return !specialization.getExceptions().isEmpty() || !specialization.getExcludedBy().isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 private SpecializationData createSpecializations(CodeTypeElement clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
281 if (singleSpecializable) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
282 SpecializationData single = reachableSpecializations.get(0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
283 clazz.add(createSingleSpecialization(single));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
284 return single;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285 } 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
286 CodeTypeElement baseSpecialization = clazz.add(createBaseSpecialization());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 TypeMirror baseSpecializationType = baseSpecialization.asType();
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 Map<SpecializationData, CodeTypeElement> generated = new LinkedHashMap<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
290
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 List<SpecializationData> generateSpecializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
292 generateSpecializations.add(node.getUninitializedSpecialization());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
293 if (needsPolymorphic(reachableSpecializations)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
294 generateSpecializations.add(node.getPolymorphicSpecialization());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
295 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
296 generateSpecializations.addAll(reachableSpecializations);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
298 for (SpecializationData specialization : generateSpecializations) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299 generated.put(specialization, clazz.add(createSpecialization(specialization, baseSpecializationType)));
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
302 baseSpecialization.addOptional(createCreateNext(generated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
303 baseSpecialization.addOptional(createCreateFallback(generated));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
304 baseSpecialization.addOptional(createCreatePolymorphic(generated));
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 return node.getUninitializedSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
307 }
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
310 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311
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
312 private CodeTypeElement createBaseSpecialization() {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
313 CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, ABSTRACT, STATIC), specializationTypeName(null), TypeSystemNodeFactory.nodeType(typeSystem));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 clazz.addOptional(createSpecializationConstructor(clazz, null, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 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
317
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 clazz.addOptional(createUnsupported());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
319 clazz.add(createGetSuppliedChildren());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 int signatureSize = node.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 Set<Integer> evaluatedCount = getEvaluatedCounts();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 for (int evaluated : evaluatedCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 if (signatureSize != evaluated || signatureSize == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325 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
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 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330 Collection<TypeData> specializedTypes = node.findSpecializedTypes(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 specializedTypes.add(genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333 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
334 clazz.add(createExecuteChildMethod(execution, specializedType));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
335 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
336 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
338
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
339 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
340 }
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 private CodeTypeElement createSingleSpecialization(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
343 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
344 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, null, "0"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
345 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
346 TypeData returnType = specialization.getReturnType().getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
347 Set<Integer> evaluatedCount = getEvaluatedCounts();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
348
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
349 TypeData specializedType = returnType;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
350 if (!isTypeBoxingEliminated(specialization)) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
351 specializedType = genericType;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
352 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
353
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
354 for (int evaluated : evaluatedCount) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
355 if (evaluated != 0) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
356 clazz.add(createFastPathExecuteMethod(specialization, null, evaluated));
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
357 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
358 }
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
359
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
360 clazz.add(createFastPathExecuteMethod(specialization, specializedType, 0));
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
361 if (!specializedType.isGeneric()) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
362 clazz.add(createFastPathWrapExecuteMethod(genericType, returnType));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
363 }
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
364
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
365 ExecutableTypeData voidExecutableType = node.findExecutableType(typeSystem.getVoidType(), 0);
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
366 if (voidExecutableType != null && isTypeBoxingOptimized(options.voidBoxingOptimization(), returnType)) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
367 clazz.add(createFastPathWrapVoidMethod(returnType));
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
368 }
18761
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 clazz.addOptional(createUnsupported());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
371 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
372 clazz.add(createGetSuppliedChildren());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
373
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
374 return clazz;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377 private CodeTypeElement createSpecialization(SpecializationData specialization, TypeMirror baseType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
378 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
379
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
380 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, specialization, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383 TypeData targetType = p.getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
385 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
386 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 implicitProfile.getModifiers().add(PRIVATE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 implicitProfile.getModifiers().add(FINAL);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 clazz.add(implicitProfile);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
394
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
395 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 clazz.add(createFallbackGuardMethod());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400 clazz.addOptional(createMergeMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 clazz.addOptional(createIsSameMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 TypeData returnType = specialization.getReturnType().getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 int signatureSize = specialization.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 clazz.add(createFastPathExecuteMethod(specialization, null, signatureSize));
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 if (isTypeBoxingEliminated(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 clazz.add(createFastPathExecuteMethod(specialization, returnType, 0));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 if (signatureSize > 0 && !returnType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 clazz.add(createFastPathWrapExecuteMethod(genericType, returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
414
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
415 ExecutableTypeData voidExecutableType = node.findExecutableType(typeSystem.getVoidType(), 0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 if (voidExecutableType != null && isTypeBoxingOptimized(options.voidBoxingOptimization(), returnType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417 clazz.add(createFastPathWrapVoidMethod(returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
418 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 return clazz;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 private Element createDeepCopyMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425 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
426 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
427 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
428 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
429 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
431
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
432 private Element createGetCostMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 TypeMirror returnType = getType(NodeCost.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435 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
436 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 private CodeExecutableElement createIsSameMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 if (!specialization.isSpecialized() || !options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446 List<CodeVariableElement> profiles = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
447 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
449 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 continue;
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 CodeVariableElement var = createImplicitProfileParameter(execution, parameter.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454 profiles.add(var);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
457
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
458 if (profiles.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
460 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462 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
463 method.addParameter(new CodeVariableElement(getType(SpecializationNode.class), "other"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
464 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
465 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
466
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
467 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
468 builder.string("super.isSame(other)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
470 for (CodeVariableElement profile : profiles) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
471 builder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472 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
473 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
474
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
475 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
476 return method;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
479 private Element createMergeMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480 if (specialization.getExcludedBy().isEmpty() && !specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 return null;
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 TypeMirror specializationNodeType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), specializationNodeType, "merge");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 executable.addParameter(new CodeVariableElement(specializationNodeType, "newNode"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486 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
487 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
488
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489 if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 builder.statement("return polymorphicMerge(newNode)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 for (SpecializationData containedSpecialization : specialization.getExcludedBy()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
494 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 builder.string("newNode.getClass() == ").typeLiteral(specializationType(containedSpecialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 builder.statement("removeSame(\"Contained by " + containedSpecialization.createReferenceName() + "\")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
501 builder.statement("return super.merge(newNode)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
504 return executable;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507 private Element createFastPathWrapVoidMethod(TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 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
509 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
510 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
511 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
512 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 builder.startCall(TypeSystemNodeFactory.voidBoxingExecuteName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
514 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518 return executable;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521 private Element createFastPathWrapExecuteMethod(TypeData override, TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 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
523 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
524 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
525 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
528 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
529 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530 builder.startCall(TypeSystemNodeFactory.executeName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
533 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
534 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536 builder.statement("return ex.getResult()");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
537 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
538 }
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 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
541 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
542
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
543 private boolean needsPolymorphic(List<SpecializationData> reachableSpecializations) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
544 if (reachableSpecializations.size() > 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
546 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
547 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
548 SpecializationData specialization = reachableSpecializations.get(0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
549 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 if (parameter.getTypeSystemType().hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
556 }
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 private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
559 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
560 if (fallback == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
561 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
562 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
563 CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
565 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
566 }
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 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
569 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
570 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
571 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
572 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
573 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
574
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
575 private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
576 SpecializationData polymorphic = node.getPolymorphicSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
577 CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
578 if (generatedPolymorphic == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
579 return null;
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 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
582 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
583 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
584 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
585 return method;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
588 private CodeExecutableElement createCreateNext(final Map<SpecializationData, CodeTypeElement> specializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
589 final LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
590
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
591 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
592 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
593
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
595 SpecializationGroup group = createSpecializationGroups();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
596 CodeTree execution = createGuardAndCast(group, genericType, locals, new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
597 public CodeTree createExecute(SpecializationData specialization, LocalContext values) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
598 CodeTypeElement generatedType = specializationClasses.get(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
599 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
600 throw new AssertionError("No generated type for " + specialization);
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 return createSlowPathExecute(specialization, locals);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
603 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
604
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
605 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
606 return false;
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 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
609
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
610 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
611
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
612 if (hasFallthrough(group, genericType, locals, false)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
613 builder.returnNull();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
614 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
615 return method;
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 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
619 boolean frameUsed = node.isFrameUsedByAnyGuard();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
622 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
623 locals.removeValue(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
624 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
625
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
626 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
627 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 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
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 = boundaryMethod.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
632 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
633 builder.startCall("createNext");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
634 locals.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
635 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
636 builder.string(" == null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
637 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
638 return boundaryMethod;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
639 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
640
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
641 private ExecutableElement createAccessChildMethod(NodeChildData child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
642 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
643 ExecutableElement getter = (ExecutableElement) child.getAccessElement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
644 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), getter);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
645 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
646
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
647 List<NodeExecutionData> executions = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
648 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
649 if (execution.getChild() == child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
650 executions.add(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
651 }
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 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
655 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
656 builder.startReturn().startNewArray((ArrayType) child.getOriginalType(), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
657 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
658 builder.string(nodeFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
659 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
660 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
661 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
662 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
663 builder.startReturn().string("this.").string(nodeFieldName(execution)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
664 break;
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 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
668 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
669 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
670 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
671
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
672 private boolean isTypeBoxingEliminated(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
673 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
674 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
675 }
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 TypeBoxingOptimization optimization = options.monomorphicTypeBoxingOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
678 if (isTypeBoxingOptimized(optimization, specialization.getReturnType().getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
679 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
680 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
681 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
682 if (isTypeBoxingOptimized(optimization, p.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
683 return true;
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
686 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
687
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
688 }
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 private Set<Integer> getEvaluatedCounts() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
691 Set<Integer> evaluatedCount = new TreeSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
692 Collection<TypeData> returnSpecializedTypes = node.findSpecializedReturnTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
693 for (ExecutableTypeData execType : node.getExecutableTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
694 if (shouldImplementExecutableType(returnSpecializedTypes, execType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
695 evaluatedCount.add(execType.getEvaluatedCount());
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 return evaluatedCount;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
699 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
700
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703 private Element createUnsupported() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
710 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
711 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
712
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 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
715 builder.tree(callTemplateMethod(accessParent(null), fallback, locals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
716 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
717
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
718 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
719 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
721 private boolean isSingleSpecializableImpl() {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
722 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 if (reachableSpecializations.size() != 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725 }
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
726 for (Parameter parameter : reachableSpecializations.get(0).getSignatureParameters()) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
727 TypeData type = parameter.getTypeSystemType();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
728 if (type != null && type.hasImplicitSourceTypes()) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
729 return false;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
730 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
731 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
732 return true;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 }
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 private List<SpecializationData> getReachableSpecializations() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
736 List<SpecializationData> specializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
737 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
738 if (specialization.isReachable() && //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
739 (specialization.isSpecialized() //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
740 || (specialization.isFallback() && optimizeFallback(specialization)))) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
741 specializations.add(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
742 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
743 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
744 return specializations;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
745 }
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 private boolean optimizeFallback(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
748 switch (options.optimizeFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
749 case NEVER:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
750 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
751 case DECLARED:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
752 return specialization.getMethod() != null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
753 case ALWAYS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
754 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
755 default:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
756 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
757 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
758 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
759
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
760 private CodeExecutableElement createExecutableTypeOverride(ExecutableTypeData execType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 final String varArgsName = "args";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
762 final TypeData returnType = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
763 final TypeData executedType = execType.getEvaluatedCount() > 0 ? null : returnType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
764
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
765 CodeExecutableElement method = cloneExecutableTypeOverride(execType, varArgsName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
766
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
767 LocalContext locals = LocalContext.load(this, execType.getSignatureSize());
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 // rename varargs parameter
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 for (Parameter parameter : execType.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
772 if (parameter.isTypeVarArgs()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 String newName = varArgsName + "[" + parameter.getTypeVarArgsIndex() + "]";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 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
776 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777 signatureIndex++;
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 CodeTreeBuilder builder = method.createBuilder();
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 // create acceptAndExecute
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783 CodeTreeBuilder executeBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 executeBuilder.startCall(specializationStartFieldName(), TypeSystemNodeFactory.executeName(executedType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 Parameter frame = execType.getFrame();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
786 if (frame == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 executeBuilder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 executeBuilder.string(frame.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
790 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
791 locals.addReferencesTo(executeBuilder);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
792 executeBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
793
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 CodeTreeBuilder contentBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 contentBuilder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 contentBuilder.tree(TypeSystemCodeGenerator.expect(executedType, returnType, executeBuilder.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 contentBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799 // 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
800 if (!execType.hasUnexpectedValue(context) && !returnType.isGeneric() && !returnType.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 builder.tree(contentBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 builder.startThrow().startNew(getType(AssertionError.class)).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 builder.tree(contentBuilder.build());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 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
814 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), execType.getMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 method.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
818
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 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
820 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
821 }
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 // align argument names
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
824 int index = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
825 for (Parameter parameter : execType.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 CodeVariableElement var = (CodeVariableElement) method.getParameters().get(index);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 if (parameter.isTypeVarArgs()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 var.setName(varArgsName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830 break;
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 var.setName(LocalVariable.fromParameter(parameter).createParameter().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
834 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837 }
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 private boolean shouldImplementExecutableType(Collection<TypeData> specializedTypes, ExecutableTypeData execType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 TypeData type = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 Set<Modifier> modifiers = execType.getMethod().getModifiers();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 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
843 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844 } else if (execType.isAbstract()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846 } else if (type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 } else if (type.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850 if (isTypeBoxingOptimized(options.voidBoxingOptimization(), specializedType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
854 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 } else if (!specializedTypes.contains(type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857 } else if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 }
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 private Element createMethodGetSpecializationNode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 TypeMirror returntype = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
865 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returntype, "getSpecializationNode");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
866 method.createBuilder().startReturn().string(specializationStartFieldName()).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
867 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
868 }
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 private TypeMirror getType(Class<?> clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
871 return context.getType(clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
872 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874 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
875 CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
876 childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 setVisibility(childField.getModifiers(), visibility);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 return childField;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
879 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880
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
881 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
882 if (optimization == TypeBoxingOptimization.NONE) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
883 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
884 } 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
885 return Collections.emptyList();
18761
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 List<ExecutableTypeData> executables = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889 for (TypeData type : types) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890 if (!isTypeBoxingOptimized(optimization, type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891 continue;
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 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
894 if (foundType != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
895 executables.add(foundType);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898 return executables;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
900
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
901 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
902 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
903 if (method.getMethod().getModifiers().contains(STATIC)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
904 builder.startStaticCall(method.getMethod().getEnclosingElement().asType(), method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
905 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
906 builder.startCall(receiver, method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
907 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
908 int index = -1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
909 for (Parameter parameter : method.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
910 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
911 if (index < boundValues.length) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
912 CodeTree tree = boundValues[index];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 if (tree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 builder.tree(tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
915 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
918 builder.string(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
920 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 return builder.build();
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
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
924 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
925 CodeTree[] bindings = new CodeTree[method.getParameters().size()];
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 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
928 for (int i = 0; i < bindings.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 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
930
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 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
932 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
933 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
934 }
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
935
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 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
937 CodeTree valueReference = var.createReference();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
938 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
939 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
940 } 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
941 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
942 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943 bindings[i] = valueReference;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 }
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
945
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946 if (parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
947 signatureIndex++;
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 }
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
950 return callTemplateMethod(receiver, method, bindings);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
951 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
952
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 private SpecializationGroup createSpecializationGroups() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 return SpecializationGroup.create(getReachableSpecializations());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957 private CodeTree createSlowPathExecute(SpecializationData specialization, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
959 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 return builder.returnNull().build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
961 }
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
962 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
963 builder.tree(createTransferToInterpreterAndInvalidate());
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 for (SpecializationData otherSpeciailzation : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
966 if (otherSpeciailzation == specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 continue;
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 if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
970 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
971 builder.tree(accessParent(excludedFieldName(otherSpeciailzation)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
972 builder.string(" = true");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
973 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 }
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 builder.startReturn().tree(createCallCreateMethod(specialization, null, currentValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
978
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 CodeTreeBuilder checkHasSeenBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 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
982 checkHasSeenBuilder.tree(builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
983 checkHasSeenBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
984 return checkHasSeenBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
985 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 return builder.build();
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 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
990 for (TypeGuard guard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
991 if (currentValues.getValue(guard.getSignatureIndex()) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 // not evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
993 return true;
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 LocalVariable value = currentValues.getValue(guard.getSignatureIndex());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996 if (value.getType().needsCastTo(guard.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
997 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
998 }
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 List<GuardExpression> expressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1002 expressions.removeAll(group.findElseConnectableGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003 if (!expressions.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004 return true;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1007 if ((!fastPath || forType.isGeneric()) && !group.getAssumptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1008 return true;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1011 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
1012 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1013 }
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 if (!group.getChildren().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1016 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
1017 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1018
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1021
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1022 private Element createGetSuppliedChildren() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1023 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
1024
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1025 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
1026 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
1027
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1028 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1029
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1030 builder.startReturn().startNewArray(nodeArray, null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1031 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
1032 NodeExecutionData execution = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1033 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1034 builder.nullLiteral();
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 builder.tree(accessParent(nodeFieldName(execution)));
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().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 method;
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 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1044
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1045 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
1046 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
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 TypeMirror specializationType = specializationType(specialization);
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1049 if (useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1050 builder.startStaticCall(specializationType(specialization), "create");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1051 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1052 builder.startNew(specializationType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1053 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1054 if (rootName != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1055 builder.string(rootName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1056 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1057 builder.string("root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1058 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1059 if (currentValues != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1060 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1061 LocalVariable local = currentValues.get(p.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1062 CodeVariableElement var = createImplicitProfileParameter(p.getSpecification().getExecution(), p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1063 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1064 builder.tree(local.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1065 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1066 }
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 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1069
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1070 return builder.build();
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 Element createSpecializationCreateMethod(SpecializationData specialization, CodeExecutableElement constructor) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1074 if (!useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1075 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1076 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1077
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1078 CodeExecutableElement executable = CodeExecutableElement.clone(context.getEnvironment(), constructor);
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1079 executable.setReturnType(specializationType(null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1080 executable.setSimpleName(CodeNames.of("create"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1081 executable.getModifiers().add(STATIC);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1082
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1083 CodeTreeBuilder builder = executable.createBuilder();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1084 builder.startReturn().startNew(specializationType(specialization));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1085 for (VariableElement parameter : executable.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1086 builder.string(parameter.getSimpleName().toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1087 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1088 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1089 return executable;
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
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1092 private boolean useLazyClassLoading() {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1093 return options.useLazyClassLoading() && !singleSpecializable;
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1094 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1095
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1096 private static String implicitClassFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1097 return execution.getName() + "ImplicitType";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1098 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1099
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1100 private static String implicitNodeFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1101 return execution.getName() + "Cast";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1102 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1103
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1104 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
1105 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
1106
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1107 constructor.addParameter(new CodeVariableElement(nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1108 CodeTreeBuilder builder = constructor.createBuilder();
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 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1111 if (constantIndex == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1112 builder.statement("super(index)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1113 constructor.addParameter(new CodeVariableElement(getType(int.class), "index"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1114 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 builder.startStatement().startSuperCall().string(constantIndex).end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1116 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 builder.statement("this.root = root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1118 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 int index = resolveSpecializationIndex(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1120 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
1121
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1122 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1124
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1126 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1127 LocalVariable var = LocalVariable.fromParameter(p).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1128
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 String implicitFieldName = implicitProfile.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1131 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1132 CodeTree implicitType = TypeSystemCodeGenerator.implicitType(p.getTypeSystemType(), var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1133 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
1134 } else if (options.implicitCastOptimization().isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1135 // use node that supports polymorphism
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1136 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1137 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
1138 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1139 throw new AssertionError();
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1143 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1144
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1145 if (constructor.getParameters().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1146 // do not generate default constructor
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1147 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1148 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1149 return constructor;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1152 // 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
1153 private static int resolveSpecializationIndex(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1155 return Integer.MAX_VALUE - 1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1156 } else if (specialization.isUninitialized()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1157 return Integer.MAX_VALUE;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1158 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1159 return 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1160 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1161 return specialization.getIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1162 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1163 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1164
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1165 private CodeTree createCallNext(TypeData forType, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1166 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1167 if (singleSpecializable) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1168 builder.startCall("unsupported");
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1169 } else {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1170 builder.startCall("next", TypeSystemNodeFactory.executeName(null));
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1171 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1172 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1173 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1174 return TypeSystemCodeGenerator.expect(genericType, forType, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1175 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1176
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1177 private CodeTree createCallRemove(String reason, TypeData forType, LocalContext currentValues) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1178 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1179 if (singleSpecializable) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1180 builder.startCall("unsupported");
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1181 } else {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1182 builder.startCall("remove");
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1183 builder.doubleQuote(reason);
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1184 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1185 currentValues.addReferencesTo(builder, FRAME_VALUE);
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1186 builder.end();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1187 return TypeSystemCodeGenerator.expect(genericType, forType, builder.build());
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1188 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1189
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1190 private static CodeTree createCallDelegate(String methodName, TypeData forType, LocalContext currentValues) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1191 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1192 builder.startCall(methodName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1193 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1194 builder.end();
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 TypeData executedType = forType.getTypeSystem().getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1197 return TypeSystemCodeGenerator.expect(executedType, forType, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1198 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1199
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
1200 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
1201 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
1202 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
1203 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
1204 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
1205 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
1206 }
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
1207 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
1208 }
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
1209
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
1210 private ExecutableTypeData resolveExecutableType(NodeChildData child, TypeData type) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1211 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
1212 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
1213 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
1214 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
1215 }
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
1216 return executableType;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1217 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1218
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1219 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
1220 for (ExecutableTypeData executableType : findSpecializedExecutableTypes(execution, type)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1221 if (executableType != null && executableType.hasUnexpectedValue(context)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1222 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1223 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1224 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1225 return false;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1228 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
1229 TypeData type = forType == null ? genericType : forType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1230 LocalContext currentLocals = LocalContext.load(this, evaluatedArguments);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1231
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1232 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
1233 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
1234
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1235 if (!type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1236 executable.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1237 }
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 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1240
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 LocalVariable var = currentLocals.getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1243 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244 TypeData targetType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1245 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246 targetType = genericType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1248 targetType = specialization.findParameterOrDie(execution).getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 LocalVariable shortCircuit = resolveShortCircuit(specialization, execution, currentLocals);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1251 LocalVariable value = currentLocals.createValue(execution, targetType).nextName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1252 builder.tree(createAssignExecuteChild(execution, type, value, shortCircuit, currentLocals));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1253 currentLocals.setValue(execution, value);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1256
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1257 LocalContext originalValues = currentLocals.copy();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1258 if (specialization == null) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1259 builder.startReturn().tree(createCallDelegate("acceptAndExecute", type, currentLocals)).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1260 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1261 builder.startReturn().tree(createCallNext(type, currentLocals)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1262 } else if (specialization.isUninitialized()) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1263 builder.startReturn().tree(createCallDelegate("uninitialized", type, currentLocals)).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1264 } else {
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1265 final TypeData finalType = type;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1266 SpecializationGroup group = SpecializationGroup.create(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1267 SpecializationExecution executionFactory = new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1268 public CodeTree createExecute(SpecializationData s, LocalContext values) {
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1269 return createFastPathExecute(finalType, s, values);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1270 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1271
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1273 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1274 }
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 builder.tree(createGuardAndCast(group, type, currentLocals, executionFactory));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1277 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
1278 builder.startReturn().tree(createCallNext(type, originalValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1279 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1280 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1283 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1284
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1285 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
1286 LocalVariable shortCircuit = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1287 SpecializationData resolvedSpecialization = specialization;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1288 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1289 resolvedSpecialization = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1290 }
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 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 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
1294 CodeTree access = callTemplateMethod(accessParent(null), shortCircuitData, currentLocals);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1295 shortCircuit = currentLocals.createShortCircuitValue(execution).accessWith(access);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1296 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 return shortCircuit;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 private int calculateShortCircuitIndex(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301 int shortCircuitIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1302 for (NodeExecutionData otherExectuion : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1303 if (otherExectuion.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1304 if (otherExectuion == execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1305 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1306 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1307 shortCircuitIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1308 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1309 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1310 return shortCircuitIndex;
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 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
1314 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1315 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1316 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1317 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
1318 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1319 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1320 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1321 currentValues.addReferencesTo(builder);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1322
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1323 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1324 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1325 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1326 ifCount++;
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 CodeTreeBuilder execute = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1329 execute.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1330 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1331 execute.startCall("unsupported");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1332 currentValues.addReferencesTo(execute, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1333 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1334 } 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
1335 execute.tree(callTemplateMethod(accessParent(null), specialization, currentValues));
18761
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 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1338 builder.tree(createFastPathTryCatchRewriteException(specialization, forType, currentValues, execute.build()));
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 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1341 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1342 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1343
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1344 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
1345 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1346
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1347 Set<TypeGuard> castGuards;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1348 if (execution.isFastPath()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1349 castGuards = null; // cast all
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1350 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1351 castGuards = new HashSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1352 for (TypeGuard castGuard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 if (isTypeGuardUsedInAnyGuardBelow(group, currentValues, castGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1354 castGuards.add(castGuard);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1357 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1358 CodeTree[] checkAndCast = createTypeCheckAndCast(group.getTypeGuards(), castGuards, currentValues, execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1359 CodeTree check = checkAndCast[0];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1360 CodeTree cast = checkAndCast[1];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1361
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1362 List<GuardExpression> elseGuardExpressions = group.findElseConnectableGuards();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1363 List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1364 guardExpressions.removeAll(elseGuardExpressions);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1365 CodeTree methodGuards = createMethodGuardCheck(guardExpressions, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1366
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1367 if (!group.getAssumptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1368 if (execution.isFastPath() && !forType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1369 cast = appendAssumptionFastPath(cast, group.getAssumptions(), forType, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1370 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1371 methodGuards = appendAssumptionSlowPath(methodGuards, group.getAssumptions());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1372 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1373 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1374
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1375 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1376 if (!check.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1377 builder.startIf();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1378 builder.tree(check).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1379 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1380 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1381 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1382 if (!cast.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1383 builder.tree(cast);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1384 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1385 boolean elseIf = !elseGuardExpressions.isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1386 if (!methodGuards.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1387 builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1388 builder.tree(methodGuards).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1389 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1390 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1391 } else if (elseIf) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1392 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1393 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1394 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1395
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1396 boolean reachable = isReachableGroup(group, ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1397 if (reachable) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1398 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1399 builder.tree(createGuardAndCast(child, forType, currentValues.copy(), execution));
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 SpecializationData specialization = group.getSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1402 if (specialization != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1403 builder.tree(execution.createExecute(specialization, currentValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1404 }
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 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1407
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1408 return builder.build();
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 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
1412 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
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 builder.tree(methodGuards);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1415 String connect = methodGuards.isEmpty() ? "" : " && ";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1416 for (String assumption : assumptions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1417 builder.string(connect);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1418 builder.startCall(accessParent(assumptionName(assumption)), "isValid").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1419 connect = " && ";
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1422 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1423 }
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 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
1426 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1427 builder.tree(casts);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1428 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1429 for (String assumption : assumptions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1430 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
1431 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1432 builder.end().startCatchBlock(getType(InvalidAssumptionException.class), "ae");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1433 builder.startReturn().tree(createCallNext(forType, currentValues)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1434 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1435 return builder.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1438 private static boolean isReachableGroup(SpecializationGroup group, int ifCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1439 if (ifCount != 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1440 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1441 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1442 SpecializationGroup previous = group.getPreviousGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1443 if (previous == null || previous.findElseConnectableGuards().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1444 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1445 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1446
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1447 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1448 * 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
1449 * 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
1450 */
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1451 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
1452 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1453 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1454 }
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 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1457 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1458
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1459 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
1460 NodeExecutionData execution = node.getChildExecutions().get(typeGuard.getSignatureIndex());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1461
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1462 for (GuardExpression guard : group.getGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1463 List<Parameter> guardParameters = guard.getResolvedGuard().findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1464 TypeData sourceType = currentValues.getValue(typeGuard.getSignatureIndex()).getType();
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 for (Parameter guardParameter : guardParameters) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1467 if (sourceType.needsCastTo(guardParameter.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1468 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1469 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1470 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1471 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1472
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1473 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1474 if (isTypeGuardUsedInAnyGuardBelow(child, currentValues, typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1475 return true;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1479 return false;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1482 private CodeExecutableElement createExecuteChildMethod(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1483 LocalContext locals = LocalContext.load(this, 0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1484
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1485 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
1486 if (hasUnexpectedResult(execution, targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1487 method.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1488 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1489
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1490 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1491 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1492 method.addParameter(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1493 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1494
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1495 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
1496 NodeExecutionData executeWith = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1497 LocalVariable var = locals.createValue(executeWith, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1498 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1499 locals.setValue(executeWith, var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1500 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1501
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1502 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
1503 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
1504 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1505 builder.statement(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1506 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1507 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1508 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1509 return method;
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 private CodeVariableElement createImplicitProfileParameter(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1513 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1514 switch (options.implicitCastOptimization()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1515 case NONE:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1516 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1517 case DUPLICATE_TAIL:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1518 return new CodeVariableElement(getType(Class.class), implicitClassFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1519 case MERGE_CASTS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1520 return new CodeVariableElement(ImplicitCastNodeFactory.type(targetType), implicitNodeFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1521 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1522 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1523 return null;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1526 private boolean isExecuteChildShared(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1527 if (targetType.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1528 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1529 } else if (targetType.isGeneric()) {
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1530 return resolvePolymorphicExecutables(execution).size() >= 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1531 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1532 if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1533 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1534 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1535 if (!targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1536 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1537 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1538
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1539 int uses = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1540 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1541 List<Parameter> parameters = specialization.findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1542 for (Parameter parameter : parameters) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1543 if (targetType.equals(parameter.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1544 uses++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1545 }
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 (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
1549 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
1550 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1551 return false;
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1555
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1556 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
1557 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1558 boolean hasUnexpected = hasUnexpectedResult(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1559
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1560 CodeTree executeChild;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1561 if (isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1562 executeChild = createCallSharedExecuteChild(execution, targetValue, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1563 } 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
1564 executeChild = createExecuteChild(execution, targetValue, currentValues, false);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1565 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1566
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1567 builder.tree(createTryExecuteChild(targetValue, executeChild, shortCircuit == null, hasUnexpected));
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1568
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1569 if (shortCircuit != null) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1570 currentValues.setShortCircuitValue(execution, shortCircuit.accessWith(null));
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1571 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1572
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1573 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1574 if (hasUnexpected) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1575 builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1576 LocalContext slowPathValues = currentValues.copy();
18761
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 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
1579 boolean found = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1580 for (NodeExecutionData otherExecution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1581 if (found) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1582 LocalVariable childEvaluatedValue = slowPathValues.createValue(otherExecution, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1583 LocalVariable genericShortCircuit = resolveShortCircuit(null, otherExecution, slowPathValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1584 builder.tree(createAssignExecuteChild(otherExecution, genericType, childEvaluatedValue, genericShortCircuit, slowPathValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1585 slowPathValues.setValue(otherExecution, childEvaluatedValue);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1586 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1587 // skip forward already evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1588 found = execution == otherExecution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1589 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1590 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1591 builder.startReturn().tree(createCallNext(returnType, slowPathValues)).end();
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1594
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1595 return createShortCircuit(targetValue, shortCircuit, builder.build());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1598 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
1599 if (shortCircuitValue == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1600 return tryExecute;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1603 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1604
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1605 builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1606 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
1607
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1608 builder.startIf().string(shortCircuitValue.getName()).end().startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1609 builder.tree(tryExecute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1610 builder.end();
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 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1613 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1614
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1615 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
1616 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1617 boolean hasDeclaration = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1618 if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1619 builder.tree(value.createDeclaration(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1620 hasDeclaration = true;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1623 if (hasTry) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1624 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1625 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1626 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1627 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1628
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1629 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1630 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1631 if (hasDeclaration || !needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1632 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1633 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1634 builder.type(value.getTypeMirror()).string(" ").tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1635 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1636 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1637 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1638 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1639 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1640
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1641 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1642
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1643 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1644 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1645
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1646 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
1647 if (!isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1648 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
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 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1652 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
1653 builder.startCall(executeChildMethodName(execution, targetValue.getType()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1654 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1655
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1656 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1657 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1658 builder.string(implicitProfile.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1659 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1660 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
1661 builder.tree(currentValues.getValue(i).createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1662 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1663 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1664 return builder.build();
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
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
1667 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
1668 final CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1669
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
1670 CodeTree assignment = createAssignmentStart(target, shared);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1671
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
1672 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
1673 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
1674 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
1675 } 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
1676 ExecutableTypeData executableType = executableTypes.iterator().next();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1677 if (target.getType().isGeneric() && executableType.getEvaluatedCount() == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1678 return createPolymorphicExecuteChild(execution, target, currentValues, shared);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1679 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1680 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
1681 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
1682 }
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
1683 } 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
1684 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
1685 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
1686 } 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
1687 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
1688 } 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
1689 // 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
1690 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
1691 } 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
1692 throw new AssertionError();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1693 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1694 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1695 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1696 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1697
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
1698 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
1699 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
1700 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
1701 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
1702 }
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
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1704 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
1705 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
1706 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
1707 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
1708 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1709
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1710 List<ExecutableTypeData> specializedExecutables = resolvePolymorphicExecutables(execution);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1711 Collections.sort(specializedExecutables, new Comparator<ExecutableTypeData>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1712 public int compare(ExecutableTypeData o1, ExecutableTypeData o2) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1713 return o1.getType().compareTo(o2.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1714 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1715 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1716
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
1717 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
1718 CodeTree executeGeneric = createSingleExecute(execution, target, currentValues, genericExecutableType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1719
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
1720 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1721 if (specializedExecutables.isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1722 builder.tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1723 builder.tree(executeGeneric);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1724 } 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
1725 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
1726 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
1727 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
1728
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 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
1730
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
1731 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
1732 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
1733 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
1734 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
1735 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
1736 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
1737 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
1738 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
1739 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
1740 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
1741 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
1742 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
1743 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
1744 }
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
1745
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
1746 // 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
1747 polyChainBuilder.startElseIf().string(profileField).string(" == null").end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1748 polyChainBuilder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1749 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
1750 polyChainBuilder.declaration(genericExecutableType.getType().getPrimitiveType(), valueFieldName, executeGeneric);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1751
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1752 hasSpecializedTypes = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1753 for (ExecutableTypeData executableType : specializedExecutables) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1754 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
1755 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
1756 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1757 polyChainBuilder.startBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1758 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
1759 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1760 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1762 polyChainBuilder.startElseBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1763 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
1764 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
1765 polyChainBuilder.startReturn().string(valueFieldName).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1766 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1767
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
1768 // else -> execute generic
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1769 polyChainBuilder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1770 polyChainBuilder.startStatement().tree(assignment).tree(executeGeneric).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1771 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1772
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
1773 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
1774 if (encounteredUnexpectedResult) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1775 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
1776 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1777 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1778 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
1779 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
1780 builder.startReturn().string("ex.getResult()").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1781 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
1782 } 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
1783 builder.tree(executePolymorphic);
18761
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1786 return builder.build();
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
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1789 private List<ExecutableTypeData> resolvePolymorphicExecutables(NodeExecutionData execution) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1790 if (singleSpecializable) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1791 return Collections.emptyList();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1792 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1793 Set<TypeData> specializedTypes = new HashSet<>();
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1794 for (TypeData type : node.findSpecializedTypes(execution)) {
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1795 specializedTypes.addAll(type.getImplicitSourceTypes());
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1796 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1797 return resolveSpecializedExecutables(execution, specializedTypes, options.polymorphicTypeBoxingElimination());
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1798 }
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1799
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
1800 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
1801 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1802 if (shared) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1803 builder.string("return ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1804 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1805 builder.string(target.getName()).string(" = ");
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 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1808 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1809
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1810 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
1811 CodeTreeBuilder builder = parent.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1812 List<TypeData> sourceTypes = target.getType().getImplicitSourceTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1813 String implicitClassFieldName = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1814 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
1815 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
1816
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1817 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1818 for (ExecutableTypeData executableType : executableTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1819 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1820 builder.string(implicitClassFieldName).string(" == ").typeLiteral(executableType.getType().getBoxedType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1821 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1822 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1823 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1824
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
1825 CodeTree execute = callTemplateMethod(accessParent(nodeFieldName), executableType, currentValues);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1826 ImplicitCastData cast = typeSystem.lookupCast(executableType.getType(), target.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1827 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
1828 execute = callTemplateMethod(null, cast, execute);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1829 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1830 builder.tree(execute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1831 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1832 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1833 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1834
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1835 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1836 builder.startElseBlock();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1839 LocalVariable genericValue = target.makeGeneric().nextName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1840 LocalVariable genericShortCircuit = resolveShortCircuit(null, execution, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1841
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1842 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
1843 if (executableTypes.size() == sourceTypes.size()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1844 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
1845 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1846 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1847 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
1848 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1849 }
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 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1852 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1853 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1854 return builder.build();
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
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1857 private CodeTree createFastPathTryCatchRewriteException(SpecializationData specialization, TypeData forType, LocalContext currentValues, CodeTree execution) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1858 if (specialization.getExceptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1859 return execution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1860 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1861 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1862 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1863 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1864 TypeMirror[] exceptionTypes = new TypeMirror[specialization.getExceptions().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1865 for (int i = 0; i < exceptionTypes.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1866 exceptionTypes[i] = specialization.getExceptions().get(i).getJavaClass();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1867 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1868 builder.end().startCatchBlock(exceptionTypes, "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1869 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
1870 builder.startReturn();
18785
93016f2f3f16 Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 18780
diff changeset
1871 builder.tree(createCallRemove("threw rewrite exception", forType, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1872 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1873 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1874 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1875 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1876
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1877 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
1878 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1879 String and = "";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1880 for (GuardExpression guard : guardExpressions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1881 builder.string(and);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1882 if (guard.isNegated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1883 builder.string("!");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1884 }
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
1885 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
1886 and = " && ";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1887 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1888 return builder.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1891 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
1892 CodeTreeBuilder checksBuilder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1893 CodeTreeBuilder castsBuilder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1894 for (TypeGuard typeGuard : typeGuards) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1895 int signatureIndex = typeGuard.getSignatureIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1896 LocalVariable value = currentValues.getValue(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1897 TypeData targetType = typeGuard.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1898 if (!value.getType().needsCastTo(targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1899 continue;
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 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1902 if (!checksBuilder.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1903 checksBuilder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1904 }
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 CodeTreeBuilder checkBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1907 CodeTreeBuilder castBuilder = checksBuilder.create();
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 LocalVariable shortCircuit = currentValues.getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1910 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1911 checkBuilder.string("(");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1912 CodeTreeBuilder referenceBuilder = checkBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1913 if (!shortCircuit.getType().isPrimitive()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1914 referenceBuilder.string("(boolean) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1915 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1916 referenceBuilder.tree(shortCircuit.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1917 checkBuilder.string("!").tree(referenceBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1918 checkBuilder.string(" || ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1919 castBuilder.tree(referenceBuilder.build()).string(" ? ");
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1922 List<ImplicitCastData> sourceTypes = typeSystem.lookupByTargetType(targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1923 CodeTree valueReference = value.createReference();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1924 if (sourceTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1925 checkBuilder.tree(TypeSystemCodeGenerator.check(targetType, value.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1926 castBuilder.tree(TypeSystemCodeGenerator.cast(targetType, valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1927 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1928 ImplicitCastOptimization opt = options.implicitCastOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1929 if (specializationExecution.isFastPath() && !opt.isNone()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1930 if (opt.isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1931 String typeHintField = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1932 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1933 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1934 } else if (opt.isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1935 checkBuilder.tree(ImplicitCastNodeFactory.check(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1936 castBuilder.tree(ImplicitCastNodeFactory.cast(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1937 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1938 throw new AssertionError("implicit cast opt");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1939 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1940 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1941 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1942 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1943 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1944 }
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 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1947 checkBuilder.string(")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1948 castBuilder.string(" : ").defaultValue(targetType.getPrimitiveType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1949 }
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 if (castGuards == null || castGuards.contains(typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1952 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
1953 currentValues.setValue(execution, castVariable);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1954 castsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1957 checksBuilder.tree(checkBuilder.build());
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 return new CodeTree[]{checksBuilder.build(), castsBuilder.build()};
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1960 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1961
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1962 public static final class LocalContext {
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 private final NodeGenFactory factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1965 private final Map<String, LocalVariable> values = new HashMap<>();
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 private LocalContext(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1968 this.factory = factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1969 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1970
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1971 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
1972 CodeExecutableElement method = new CodeExecutableElement(modifiers, returnType, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1973 addParametersTo(method, optionalArguments);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1974 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1975 }
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 public static LocalContext load(NodeGenFactory factory, int signatureSize) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1978 LocalContext context = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1979 context.loadValues(signatureSize);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1980 return context;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1983 public static LocalContext load(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1984 return load(factory, factory.node.getSignatureSize());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1987 public LocalContext copy() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1988 LocalContext copy = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1989 copy.values.putAll(values);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1990 return copy;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1991 }
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 private static String fieldValueName(NodeFieldData field) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1994 return field.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1995 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1996
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1997 @SuppressWarnings("static-method")
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1998 public LocalVariable createValue(NodeExecutionData execution, TypeData type) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1999 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
2000 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2001
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2002 public LocalVariable createShortCircuitValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2003 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
2004 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2005
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2006 private static String valueName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2007 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2008 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2009
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2010 private static String shortCircuitName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2011 return "has" + ElementUtils.firstLetterUpperCase(valueName(execution));
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2014 public LocalVariable get(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2015 return values.get(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2016 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2017
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2018 public LocalVariable get(Parameter parameter, int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2019 LocalVariable var = get(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2020 if (var == null && parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2021 // lookup by signature index for executeWith
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2022 NodeExecutionData execution = factory.node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2023 var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2024 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2025 return var;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2026 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2027
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2028 public LocalVariable getValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2029 return get(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2030 }
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 public LocalVariable getValue(int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2033 return getValue(factory.node.getChildExecutions().get(signatureIndex));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2034 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2035
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2036 public void removeValue(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2037 values.remove(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2038 }
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 public void setValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2041 values.put(valueName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2042 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2043
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2044 public void setShortCircuitValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2045 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2046 return;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2047 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2048 values.put(shortCircuitName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2049 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2050
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2051 private boolean needsVarargs(boolean requireLoaded) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2052 int size = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2053 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2054 if (requireLoaded && getValue(execution) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2055 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2056 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2057 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2058 size += 2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2059 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2060 size++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2061 }
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 return size > 4;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2064 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2065
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2066 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
2067 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
2068
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2069 for (NodeFieldData field : factory.node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2070 String fieldName = fieldValueName(field);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2071 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
2072 }
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 boolean varargs = needsVarargs(false);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2075 for (int i = 0; i < evaluatedArguments; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2076 NodeExecutionData execution = factory.node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2077 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2078 LocalVariable shortCircuit = createShortCircuitValue(execution).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2079 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2080 shortCircuit = shortCircuit.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2081 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2082 values.put(shortCircuit.getName(), shortCircuit);
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 LocalVariable value = createValue(execution, factory.genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2085 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2086 value = value.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2087 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2088 values.put(value.getName(), value);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2089 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2090 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2091
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2092 private static CodeTree createReadVarargs(int i) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2093 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
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 public void addReferencesTo(CodeTreeBuilder builder, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2097 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2098 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2099 if (local == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2100 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2101 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2102 builder.tree(local.createReference());
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2105
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2106 List<NodeExecutionData> executions = factory.node.getChildExecutions();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2107 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2108 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2109 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2110 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2111 builder.tree(shortCircuitVar.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2112 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2113 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2114 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2115 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2116 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2117 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
2118 // 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
2119 builder.string("(Object) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2120 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2121 builder.tree(var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2122 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2123 }
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 }
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 public void addParametersTo(CodeExecutableElement method, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2128 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2129 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2130 if (local != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2131 method.addParameter(local.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2132 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2133 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2134 if (needsVarargs(true)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2135 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
2136 method.setVarArgs(true);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2137 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2138 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2139 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2140 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2141 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2142 method.addParameter(shortCircuitVar.createParameter());
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2145
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2146 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2147 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2148 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2149 }
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2153
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2154 private LocalVariable getShortCircuit(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2155 return values.get(shortCircuitName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2156 }
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
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2160 public static final class LocalVariable {
18761
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 private final TypeData type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2163 private final TypeMirror typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2164 private final CodeTree accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2165 private final String name;
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 static LocalVariable fromParameter(Parameter parameter) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2168 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2169 String name = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2170 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2171 name = parameter.getLocalName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2172 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2173 name = createName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2174 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2175 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
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 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
2179 Objects.requireNonNull(typeMirror);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2180 this.typeMirror = typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2181 this.accessorTree = accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2182 this.type = type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2183 this.name = name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2184 }
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 public TypeData getType() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2187 return type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2188 }
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 public String getShortCircuitName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2191 return "has" + ElementUtils.firstLetterUpperCase(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2192 }
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 public String getName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2195 return name;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2198 private static String createNextName(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2199 return name + "_";
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2202 private static String createName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2203 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2204 return "<error>";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2205 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2206 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2207 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2208
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2209 public TypeMirror getTypeMirror() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2210 return typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2211 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2212
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2213 public CodeVariableElement createParameter() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2214 return new CodeVariableElement(getTypeMirror(), getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2215 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2216
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2217 public CodeTree createDeclaration(CodeTree init) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2218 return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2219 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2220
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2221 public CodeTree createReference() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2222 if (accessorTree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2223 return accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2224 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2225 return CodeTreeBuilder.singleString(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2226 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2227 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2228
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2229 public LocalVariable newType(TypeData newType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2230 return new LocalVariable(newType, newType.getPrimitiveType(), name, accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2231 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2232
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2233 public LocalVariable accessWith(CodeTree tree) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2234 return new LocalVariable(type, typeMirror, name, tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2235 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2236
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2237 public LocalVariable nextName() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2238 return new LocalVariable(type, typeMirror, createNextName(name), accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2239 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2240
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2241 public LocalVariable makeGeneric() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2242 return newType(type.getTypeSystem().getGenericTypeData());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2243 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2244
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2245 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2246
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2247 private interface SpecializationExecution {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2248
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2249 boolean isFastPath();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2250
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2251 CodeTree createExecute(SpecializationData specialization, LocalContext currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2252
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2253 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2254
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2255 }