annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 19293:21b9b9941775

Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
author Christian Humer <christian.humer@gmail.com>
date Wed, 11 Feb 2015 12:13:44 +0100
parents f4792a544170
children b31b2f289e7d
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.CompilerDirectives.CompilationFinal;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
37 import com.oracle.truffle.api.dsl.*;
18761
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;
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
44 import com.oracle.truffle.api.nodes.Node.Children;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 import com.oracle.truffle.dsl.processor.*;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
46 import com.oracle.truffle.dsl.processor.expression.*;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
47 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 import com.oracle.truffle.dsl.processor.java.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 import com.oracle.truffle.dsl.processor.java.model.*;
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
50 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 import com.oracle.truffle.dsl.processor.model.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 import com.oracle.truffle.dsl.processor.parser.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 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
54
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 public class NodeGenFactory {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
57 private static final String FRAME_VALUE = TemplateMethod.FRAME_NAME;
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
58 private static final String NAME_SUFFIX = "_";
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
59 private static final String NODE_SUFFIX = "NodeGen";
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
60
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 private final ProcessorContext context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 private final NodeData node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 private final TypeSystemData typeSystem;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 private final TypeData genericType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 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
66 private final boolean singleSpecializable;
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
67 private final int varArgsThreshold;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 public NodeGenFactory(ProcessorContext context, NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 this.context = context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 this.node = node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 this.typeSystem = node.getTypeSystem();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 this.genericType = typeSystem.getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 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
75 this.singleSpecializable = isSingleSpecializableImpl();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
76 this.varArgsThreshold = calculateVarArgsThreshold();
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
77 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
78
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
79 private int calculateVarArgsThreshold() {
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
80 TypeMirror specialization = context.getType(SpecializationNode.class);
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
81 TypeElement specializationType = fromTypeMirror(specialization);
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
82
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
83 int maxParameters = 0;
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
84 for (ExecutableElement element : ElementFilter.methodsIn(specializationType.getEnclosedElements())) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
85 if (element.getSimpleName().contentEquals("acceptAndExecute")) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
86 maxParameters = Math.max(maxParameters, element.getParameters().size());
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
87 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
88 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
89 return maxParameters;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 public static String nodeTypeName(NodeData node) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
93 return resolveNodeId(node) + NODE_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
96 private static String assumptionName(AssumptionExpression assumption) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
97 return assumption.getId() + NAME_SUFFIX;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
98 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
99
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 private static String resolveNodeId(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 String nodeid = node.getNodeId();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 nodeid = nodeid.substring(0, nodeid.length() - 4);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 return nodeid;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 public static TypeMirror nodeType(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 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
110 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 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
113 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
114 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
115 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
116 } 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
117 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
118 }
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
119 return id + "Node_";
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121
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
122 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
123 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
124 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 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
127 return execution.getName() + "Type" + NAME_SUFFIX;
18761
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 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
131 return execution.getName() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 }
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 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
135 return "specialization" + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138 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
139 return "exclude" + specialization.getId() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 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
143 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
144 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
146 private CodeTree accessParent(String name) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
147 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
148 if (name == null) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
149 return CodeTreeBuilder.singleString("this");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
150 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
151 return CodeTreeBuilder.singleString(name);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
152 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 } else {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
154 if (name == null) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
155 return CodeTreeBuilder.singleString("root");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
156 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
157 return CodeTreeBuilder.createBuilder().string("root.").string(name).build();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
158 }
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 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
163 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
164 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
165
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 clazz.addOptional(createAccessChildMethod(child));
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 (NodeFieldData field : node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171 if (!field.isGenerated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175 clazz.add(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
176 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
177 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), field.getGetter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 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
180 clazz.add(method);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18805
diff changeset
184 for (ExecutableElement superConstructor : GeneratorUtils.findUserConstructors(node.getTemplateType().asType())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 clazz.add(createNodeConstructor(clazz, superConstructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
186 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
187
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
188 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
189 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
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 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
193 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
194 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
195 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
196 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
197
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200 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
201 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
202 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
204 Collection<TypeData> specializedTypes = node.findSpecializedReturnTypes();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
205 List<ExecutableTypeData> implementedExecutables = new ArrayList<>();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
206 for (ExecutableTypeData execType : node.getExecutableTypes()) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
207 if (shouldImplementExecutableType(specializedTypes, execType)) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
208 implementedExecutables.add(execType);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
209 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
210 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
211 for (ExecutableTypeData execType : implementedExecutables) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
212 clazz.add(createExecutableTypeOverride(implementedExecutables, execType));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
213 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214 clazz.add(createGetCostMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
216 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
217 if (node.needsRewrites(context)) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
218 clazz.add(createUnsupportedMethod());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
219 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
220 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
221 clazz.getImplements().add(getType(SpecializedNode.class));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
222 clazz.add(createMethodGetSpecializationNode());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
223 clazz.add(createDeepCopyMethod());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
224 SpecializationData specializationStart = createSpecializations(clazz);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
225 clazz.add(createNodeField(PRIVATE, specializationType(null), specializationStartFieldName(), Child.class));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
226
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
227 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
228 CodeTreeBuilder builder = ((CodeExecutableElement) constructor).appendBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
229 builder.startStatement();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
230 builder.string("this.").string(specializationStartFieldName());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
231 builder.string(" = ").tree(createCallCreateMethod(specializationStart, "this", null));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
232 builder.end();
18761
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
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
236 return clazz;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
237 }
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
238
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
239 private Element createUnsupportedMethod() {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
240 LocalContext locals = LocalContext.load(this);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
241 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED), getType(UnsupportedSpecializationException.class), "unsupported");
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
243 CodeTreeBuilder builder = method.createBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
244 builder.startReturn();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
245 builder.startNew(getType(UnsupportedSpecializationException.class));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
246 builder.string("this");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
247 builder.tree(createGetSuppliedChildren());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
248 locals.addReferencesTo(builder);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
249 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
250 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
251 return method;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
252 }
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 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
255 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
256 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
257
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
258 List<CodeVariableElement> childParameters = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
260 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 constructor.getParameters().addAll(superConstructor.getParameters().size(), childParameters);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264 CodeTreeBuilder builder = constructor.appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265 List<String> childValues = new ArrayList<>(node.getChildren().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
267 String name = child.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
268 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
269 CreateCastData createCast = node.findCast(child.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270 if (createCast != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 CodeTree nameTree = CodeTreeBuilder.singleString(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 CodeTreeBuilder callBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 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
274 callBuilder.tree(callTemplateMethod(null, createCast, nameTree));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 callBuilder.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 name += "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277 builder.declaration(child.getNodeType(), name, callBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280 childValues.add(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
281 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
282
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
283 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
284 CreateCastData createCast = node.findCast(execution.getChild().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
286 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 builder.string("this.").string(nodeFieldName(execution)).string(" = ");
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 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
290 CodeTreeBuilder accessorBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 accessorBuilder.string(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
292
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
293 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
294 accessorBuilder.string("[").string(String.valueOf(execution.getIndex())).string("]");
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297 CodeTree accessor = accessorBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
298
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299 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
300 accessor = callTemplateMethod(null, createCast, accessor);
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
303 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
304 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
305 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
306 nullCheck.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
307 nullCheck.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
308 accessor = nullCheck.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311 builder.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 builder.end();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 return constructor;
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
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
319 private static boolean mayBeExcluded(SpecializationData specialization) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 return !specialization.getExceptions().isEmpty() || !specialization.getExcludedBy().isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 private SpecializationData createSpecializations(CodeTypeElement clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
326 CodeTypeElement baseSpecialization = clazz.add(createBaseSpecialization());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
327 TypeMirror baseSpecializationType = baseSpecialization.asType();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
329 Map<SpecializationData, CodeTypeElement> generated = new LinkedHashMap<>();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
331 List<SpecializationData> generateSpecializations = new ArrayList<>();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
332 generateSpecializations.add(node.getUninitializedSpecialization());
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
333 if (needsPolymorphic()) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
334 generateSpecializations.add(node.getPolymorphicSpecialization());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
335 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
336 generateSpecializations.addAll(reachableSpecializations);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
338 for (SpecializationData specialization : generateSpecializations) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
339 generated.put(specialization, clazz.add(createSpecialization(specialization, baseSpecializationType)));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
340 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
341
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
342 baseSpecialization.addOptional(createCreateNext(generated));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
343 baseSpecialization.addOptional(createCreateFallback(generated));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
344 baseSpecialization.addOptional(createCreatePolymorphic(generated));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
345
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
346 return node.getUninitializedSpecialization();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
347 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
348
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
349 private boolean needsPolymorphic() {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
350 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
351 if (reachableSpecializations.size() != 1) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
352 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
353 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
354
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
355 SpecializationData specialization = reachableSpecializations.get(0);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
356 for (Parameter parameter : specialization.getSignatureParameters()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
357 TypeData type = parameter.getTypeSystemType();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
358 if (type != null && type.hasImplicitSourceTypes()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
359 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
360 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
361 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
362 if (specialization.hasMultipleInstances()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
363 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
364 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
365 return false;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
366
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
367 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
368
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
369 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
370
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
371 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
372 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
373
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
374 clazz.addOptional(createSpecializationConstructor(clazz, null, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
375 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
376
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377 clazz.addOptional(createUnsupported());
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
378 clazz.add(createGetSuppliedChildrenMethod());
18761
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 int signatureSize = node.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381 Set<Integer> evaluatedCount = getEvaluatedCounts();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382 for (int evaluated : evaluatedCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383 if (signatureSize != evaluated || signatureSize == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384 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
385 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
386 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 Collection<TypeData> specializedTypes = node.findSpecializedTypes(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 specializedTypes.add(genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
391 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 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
393 clazz.add(createExecuteChildMethod(execution, specializedType));
18761
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 private CodeTypeElement createSpecialization(SpecializationData specialization, TypeMirror baseType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 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
403
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, specialization, null));
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 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407 TypeData targetType = p.getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 implicitProfile.getModifiers().add(PRIVATE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 implicitProfile.getModifiers().add(FINAL);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
414 clazz.add(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
415 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
418
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420 clazz.add(createFallbackGuardMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
422
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
423 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 clazz.addOptional(createMergeMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425 clazz.addOptional(createIsSameMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
426
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
427 TypeData returnType = specialization.getReturnType().getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
428 int signatureSize = specialization.getSignatureSize();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430 clazz.add(createFastPathExecuteMethod(specialization, null, signatureSize));
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 if (isTypeBoxingEliminated(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 clazz.add(createFastPathExecuteMethod(specialization, returnType, 0));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435 if (signatureSize > 0 && !returnType.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436 clazz.add(createFastPathWrapExecuteMethod(genericType, returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 ExecutableTypeData voidExecutableType = node.findExecutableType(typeSystem.getVoidType(), 0);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440 if (voidExecutableType != null && isTypeBoxingOptimized(options.voidBoxingOptimization(), returnType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 clazz.add(createFastPathWrapVoidMethod(returnType));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
447
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 private Element createDeepCopyMethod() {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
449 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
450 return null;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
451 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
452 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
453 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
454 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455 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
456 return executable;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459 private Element createGetCostMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
460 TypeMirror returnType = getType(NodeCost.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462 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
463 CodeTreeBuilder builder = executable.createBuilder();
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
464 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
465 builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end().end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
466 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
467 builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
468 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
470 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
471
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472 private CodeExecutableElement createIsSameMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
473 if (!specialization.isSpecialized() || !options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
474 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
475 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
476
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
477 List<CodeVariableElement> profiles = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
478 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
479 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 continue;
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 CodeVariableElement var = createImplicitProfileParameter(execution, parameter.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 profiles.add(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 }
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 (profiles.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 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
494 method.addParameter(new CodeVariableElement(getType(SpecializationNode.class), "other"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 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
496 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 builder.string("super.isSame(other)");
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 for (CodeVariableElement profile : profiles) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 builder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503 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
504 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
509
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
510 private Element createMergeMethod(SpecializationData specialization) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
511 boolean cacheBoundGuard = specialization.hasMultipleInstances();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
512 if (specialization.getExcludedBy().isEmpty() && !specialization.isPolymorphic() && !cacheBoundGuard) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
514 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515 TypeMirror specializationNodeType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), specializationNodeType, "merge");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517 executable.addParameter(new CodeVariableElement(specializationNodeType, "newNode"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518 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
519 CodeTreeBuilder builder = executable.createBuilder();
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 if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 builder.statement("return polymorphicMerge(newNode)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
523 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
524 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525 for (SpecializationData containedSpecialization : specialization.getExcludedBy()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527 builder.string("newNode.getClass() == ").typeLiteral(specializationType(containedSpecialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
528 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
529 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530 builder.statement("removeSame(\"Contained by " + containedSpecialization.createReferenceName() + "\")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
533 if (cacheBoundGuard) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
534 builder.statement("return super.mergeNoSame(newNode)");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
535 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
536 builder.statement("return super.merge(newNode)");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
537 }
18761
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 Element createFastPathWrapVoidMethod(TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
544 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
545 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
546 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
547 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
548 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
549 builder.startCall(TypeSystemNodeFactory.voidBoxingExecuteName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 builder.end();
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 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555 }
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 private Element createFastPathWrapExecuteMethod(TypeData override, TypeData wrap) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558 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
559 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
560 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
561 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
562 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
563 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
565 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
566 builder.startCall(TypeSystemNodeFactory.executeName(wrap));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
567 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
568 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
569 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
570 if (wrap != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
571 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
572 builder.statement("return ex.getResult()");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
573 builder.end();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
576 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
577 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
578
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
579 private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
580 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
581 if (fallback == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
582 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
583 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
584 CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
585 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
586 return null;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
589 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
590 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
591 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
592 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
593 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
595
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
596 private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
597 SpecializationData polymorphic = node.getPolymorphicSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
598 CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
599 if (generatedPolymorphic == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
600 return null;
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 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
603 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
604 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
605 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
606 return method;
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 private CodeExecutableElement createCreateNext(final Map<SpecializationData, CodeTypeElement> specializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
610 final LocalContext locals = LocalContext.load(this);
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 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
613 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
614
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
615 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
616 SpecializationGroup group = createSpecializationGroups();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
617 CodeTree execution = createGuardAndCast(group, genericType, locals, new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
618 public CodeTree createExecute(SpecializationData specialization, LocalContext values) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
619 CodeTypeElement generatedType = specializationClasses.get(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621 throw new AssertionError("No generated type for " + specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
622 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
623 return createSlowPathExecute(specialization, values);
18761
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 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
627 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
629 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
630
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
631 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
632
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
633 if (hasFallthrough(group, genericType, locals, false, null)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
634 builder.returnNull();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
635 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
636 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
637 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
638
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
639 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
640 boolean frameUsed = node.isFrameUsedByAnyGuard();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
641 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
642
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
643 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
644 locals.removeValue(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
645 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
646
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
647 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
648 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
649 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
650 }
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 CodeTreeBuilder builder = boundaryMethod.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
653 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
654 builder.startCall("createNext");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
655 locals.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
656 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
657 builder.string(" == null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
658 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
659 return boundaryMethod;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
660 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
661
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
662 private ExecutableElement createAccessChildMethod(NodeChildData child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
663 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
664 ExecutableElement getter = (ExecutableElement) child.getAccessElement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
665 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), getter);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
666 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
667
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
668 List<NodeExecutionData> executions = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
669 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
670 if (execution.getChild() == child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
671 executions.add(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
672 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
673 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
674
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
675 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
676 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
677 builder.startReturn().startNewArray((ArrayType) child.getOriginalType(), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
678 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
679 builder.string(nodeFieldName(execution));
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 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
682 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
683 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
684 builder.startReturn().string("this.").string(nodeFieldName(execution)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
685 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
686 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
687 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
688 return method;
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 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
691 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
692
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
693 private boolean isTypeBoxingEliminated(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
694 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
695 return false;
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 TypeBoxingOptimization optimization = options.monomorphicTypeBoxingOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
699 if (isTypeBoxingOptimized(optimization, specialization.getReturnType().getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
700 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703 if (isTypeBoxingOptimized(optimization, p.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711 private Set<Integer> getEvaluatedCounts() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
712 Set<Integer> evaluatedCount = new TreeSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 Collection<TypeData> returnSpecializedTypes = node.findSpecializedReturnTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 for (ExecutableTypeData execType : node.getExecutableTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
715 if (shouldImplementExecutableType(returnSpecializedTypes, execType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
716 evaluatedCount.add(execType.getEvaluatedCount());
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
719 return evaluatedCount;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
721
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
722 private Element createUnsupported() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
726 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
728
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
729 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
730 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
731
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
732 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 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
734 builder.tree(callTemplateMethod(accessParent(null), fallback, locals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
735 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
736
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
737 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
738 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
739
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
740 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
741 List<SpecializationData> reachableSpecializations = getReachableSpecializations();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
742 if (reachableSpecializations.size() != 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
743 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
744 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
745
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
746 SpecializationData specialization = reachableSpecializations.get(0);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
747
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
748 for (Parameter parameter : specialization.getSignatureParameters()) {
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
749 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
750 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
751 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
752 }
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
753 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
754
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
755 if (!specialization.getAssumptionExpressions().isEmpty()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
756 return false;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
757 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
758
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
759 if (specialization.getCaches().size() > 0) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
760 // TODO chumer: caches do not yet support single specialization.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
761 // it could be worthwhile to explore if this is possible
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
762 return false;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
763 }
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
764 return true;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
765 }
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 private List<SpecializationData> getReachableSpecializations() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768 List<SpecializationData> specializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
769 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770 if (specialization.isReachable() && //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 (specialization.isSpecialized() //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
772 || (specialization.isFallback() && optimizeFallback(specialization)))) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 specializations.add(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
776 return specializations;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777 }
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 private boolean optimizeFallback(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 switch (options.optimizeFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781 case NEVER:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783 case DECLARED:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 return specialization.getMethod() != null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 case ALWAYS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
786 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 default:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 }
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
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
792 private CodeExecutableElement createExecutableTypeOverride(List<ExecutableTypeData> implementedExecutables, ExecutableTypeData execType) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
793 final String varArgsName = "args";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 final TypeData returnType = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 final TypeData executedType = execType.getEvaluatedCount() > 0 ? null : returnType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 CodeExecutableElement method = cloneExecutableTypeOverride(execType, varArgsName);
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
798 LocalContext locals = LocalContext.load(this, execType.getSignatureSize(), Integer.MAX_VALUE);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
800 // rename varargs parameter
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 for (Parameter parameter : execType.getSignatureParameters()) {
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
803 LocalVariable var = locals.get(parameter, signatureIndex);
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
804 if (var != null) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
805 if (parameter.isTypeVarArgs()) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
806 var = var.accessWith(CodeTreeBuilder.singleString(varArgsName + "[" + parameter.getTypeVarArgsIndex() + "]"));
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
807 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
808 if (!parameter.getTypeSystemType().isGeneric()) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
809 var = var.newType(parameter.getTypeSystemType());
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
810 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
811 locals.setValue(node.getChildExecutions().get(signatureIndex), var);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 }
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
813
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 signatureIndex++;
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
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
817 Parameter frame = execType.getFrame();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
818 CodeTreeBuilder builder = method.createBuilder();
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
819 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
820 LocalVariable frameVar = null;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
821 if (frame != null) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
822 frameVar = locals.get(FRAME_VALUE).newType(frame.getType());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
823 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
824 method.getThrownTypes().clear();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
825 locals.set(FRAME_VALUE, frameVar);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
827 SpecializationData specialization = getReachableSpecializations().iterator().next();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
828 ExecutableTypeData wrappedExecutableType = findWrappedExecutable(specialization, implementedExecutables, execType);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
829 if (wrappedExecutableType != null) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
830 builder.startReturn().tree(callTemplateMethod(null, wrappedExecutableType, locals)).end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
831 } else {
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
832 builder.tree(createFastPath(builder, specialization, execType.getType(), locals));
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
833 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
834 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
835 // create acceptAndExecute
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
836 CodeTreeBuilder executeBuilder = builder.create();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
837 executeBuilder.startCall(specializationStartFieldName(), TypeSystemNodeFactory.executeName(executedType));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
838 if (frame == null) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
839 executeBuilder.nullLiteral();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
840 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
841 executeBuilder.string(frame.getLocalName());
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
842 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
843 locals.addReferencesTo(executeBuilder);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
844 executeBuilder.end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
846 CodeTreeBuilder contentBuilder = builder.create();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
847 contentBuilder.startReturn();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
848 contentBuilder.tree(TypeSystemCodeGenerator.expect(executedType, returnType, executeBuilder.build()));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
849 contentBuilder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
850 // try catch assert if unexpected value is not expected
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
851 CodeTree content = contentBuilder.build();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
852 if (!execType.hasUnexpectedValue(context) && !returnType.isGeneric() && !returnType.isVoid()) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
853 content = wrapTryCatchUnexpected(content);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
854 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
855 builder.tree(content);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 return method;
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
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
861 private CodeTree wrapTryCatchUnexpected(CodeTree content) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
862 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
863 builder.startTryBlock();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
864 builder.tree(content);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
865 builder.end().startCatchBlock(getType(UnexpectedResultException.class), "ex");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
866 builder.startThrow().startNew(getType(AssertionError.class)).end().end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
867 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
868 return builder.build();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
869 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
870
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
871 private static ExecutableTypeData findWrappedExecutable(SpecializationData specialization, List<ExecutableTypeData> implementedExecutables, ExecutableTypeData executedType) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
872 if (specialization.getReturnType().getTypeSystemType() == executedType.getType()) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
873 return null;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
874 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
875 for (ExecutableTypeData otherType : implementedExecutables) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
876 if (otherType != executedType && //
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
877 otherType.getType() == specialization.getReturnType().getTypeSystemType() && //
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
878 otherType.getEvaluatedCount() == executedType.getEvaluatedCount()) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
879 return otherType;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
880 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
881 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
882 return null;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
883 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
884
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
885 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
886 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), execType.getMethod());
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 method.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891 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
892 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
893 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
894
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
895 // align argument names
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
896 int index = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
897 for (Parameter parameter : execType.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898 CodeVariableElement var = (CodeVariableElement) method.getParameters().get(index);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 if (parameter.isTypeVarArgs()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
900 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
901 var.setName(varArgsName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
902 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
903 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
904 var.setName(LocalVariable.fromParameter(parameter).createParameter().getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
905 var.getAnnotationMirrors().clear();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
906 index++;
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 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
909 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
910
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
911 private boolean shouldImplementExecutableType(Collection<TypeData> specializedTypes, ExecutableTypeData execType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
912 TypeData type = execType.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 Set<Modifier> modifiers = execType.getMethod().getModifiers();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 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
915 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 } else if (execType.isAbstract()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
918 } else if (type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
920 } else if (type.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 for (TypeData specializedType : specializedTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
922 if (isTypeBoxingOptimized(options.voidBoxingOptimization(), specializedType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
924 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
925 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
926 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
927 } else if (!specializedTypes.contains(type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
928 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 } else if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
930 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
932 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
933 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
934
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
935 private Element createMethodGetSpecializationNode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 TypeMirror returntype = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
937 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returntype, "getSpecializationNode");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
938 method.createBuilder().startReturn().string(specializationStartFieldName()).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
939 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
940 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
941
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
942 private TypeMirror getType(Class<?> clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943 return context.getType(clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946 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
947 CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
948 childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
949 setVisibility(childField.getModifiers(), visibility);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
950 return childField;
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
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
953 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
954 if (optimization == TypeBoxingOptimization.NONE) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
955 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
956 } 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
957 return Collections.emptyList();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
959
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 List<ExecutableTypeData> executables = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
961 for (TypeData type : types) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
962 if (!isTypeBoxingOptimized(optimization, type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
963 continue;
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 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
966 if (foundType != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 executables.add(foundType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
969 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
970 return executables;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
971 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
972
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
973 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
974 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
975 if (method.getMethod().getModifiers().contains(STATIC)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
976 builder.startStaticCall(method.getMethod().getEnclosingElement().asType(), method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
977 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
978 builder.startCall(receiver, method.getMethodName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 int index = -1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 for (Parameter parameter : method.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
982 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
983 if (index < boundValues.length) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
984 CodeTree tree = boundValues[index];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
985 if (tree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 builder.tree(tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
987 continue;
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 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
990
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
991 builder.defaultValue(parameter.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
993 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
994 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
995 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996
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
997 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
998 CodeTree[] bindings = new CodeTree[method.getParameters().size()];
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 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 for (int i = 0; i < bindings.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1002 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
1003
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004 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
1005 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
1006 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
1007 }
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
1008
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1009 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
1010 CodeTree valueReference = var.createReference();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1011 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
1012 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
1013 } 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
1014 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
1015 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1016 bindings[i] = valueReference;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1017 }
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
1018
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019 if (parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 signatureIndex++;
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 }
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
1023 return callTemplateMethod(receiver, method, bindings);
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1026 private SpecializationGroup createSpecializationGroups() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1027 return SpecializationGroup.create(getReachableSpecializations());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1028 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1029
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1030 private CodeTree createSlowPathExecute(SpecializationData specialization, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1031 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1032 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1033 return builder.returnNull().build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1034 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1035
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
1036 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1037 builder.tree(createTransferToInterpreterAndInvalidate());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1038 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1039
19293
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1040 // caches unbound to guards are invoked after all guards
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1041 for (CacheExpression cache : specialization.getCaches()) {
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1042 if (!specialization.isCacheBoundByGuard(cache)) {
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1043 initializeCache(builder, specialization, cache, currentValues);
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1044 }
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1045 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1046 boolean hasAssumptions = !specialization.getAssumptionExpressions().isEmpty();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1047 if (hasAssumptions) {
19293
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1048
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1049 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1050 CodeTree assumptions = DSLExpressionGenerator.write(assumption.getExpression(), accessParent(null),
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1051 castBoundTypes(bindExpressionValues(assumption.getExpression(), specialization, currentValues)));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1052 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1053 // needs specialization index for assumption to make unique
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1054 String varName = name + specialization.getIndex();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1055 TypeMirror type = assumption.getExpression().getResolvedType();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1056 builder.declaration(type, varName, assumptions);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1057 currentValues.set(name, new LocalVariable(null, type, varName, null));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1058 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1059
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1060 builder.startIf();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1061 String sep = "";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1062 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1063 LocalVariable assumptionVar = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1064 if (assumptionVar == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1065 throw new AssertionError("assumption var not resolved");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1066 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1067 builder.string(sep);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1068 builder.startCall("isValid").tree(assumptionVar.createReference()).end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1069 sep = " && ";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1070 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1071 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1072 builder.startBlock();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1073 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1074
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1075 for (SpecializationData otherSpeciailzation : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1076 if (otherSpeciailzation == specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1077 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1078 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1079 if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1080 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1081 builder.tree(accessParent(excludedFieldName(otherSpeciailzation)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1082 builder.string(" = true");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1083 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1084 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1085 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1086
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1087 CodeTree create = createCallCreateMethod(specialization, null, currentValues);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1088
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1089 if (specialization.hasMultipleInstances()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1090 builder.declaration(getType(SpecializationNode.class), "s", create);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1091 DSLExpression limitExpression = specialization.getLimitExpression();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1092 CodeTree limitExpressionTree;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1093 if (limitExpression == null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1094 limitExpressionTree = CodeTreeBuilder.singleString("3");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1095 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1096 limitExpressionTree = DSLExpressionGenerator.write(limitExpression, accessParent(null), //
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1097 castBoundTypes(bindExpressionValues(limitExpression, specialization, currentValues)));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1098 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1099
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1100 builder.startIf().string("countSame(s) < ").tree(limitExpressionTree).end().startBlock();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1101 builder.statement("return s");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1102 builder.end();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1103 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1104 builder.startReturn().tree(create).end();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1105 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1106
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1107 if (hasAssumptions) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1108 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1109 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1110
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1111 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1112 CodeTreeBuilder checkHasSeenBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1113 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
1114 checkHasSeenBuilder.tree(builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 checkHasSeenBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1116 return checkHasSeenBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1118 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1120
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1121 private boolean hasFallthrough(SpecializationGroup group, TypeData forType, LocalContext currentValues, boolean fastPath, List<GuardExpression> ignoreGuards) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1122 for (TypeGuard guard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 if (currentValues.getValue(guard.getSignatureIndex()) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1124 // not evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1126 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1127 LocalVariable value = currentValues.getValue(guard.getSignatureIndex());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1128 if (value.getType().needsCastTo(guard.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1131 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1132
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1133 List<GuardExpression> guards = new ArrayList<>(group.getGuards());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1134 List<GuardExpression> elseConnectable = group.findElseConnectableGuards();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1135 guards.removeAll(elseConnectable);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1136 if (ignoreGuards != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1137 guards.removeAll(ignoreGuards);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1138 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1139 SpecializationData specialization = group.getSpecialization();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1140 if (specialization != null && fastPath) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1141 for (ListIterator<GuardExpression> iterator = guards.listIterator(); iterator.hasNext();) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1142 GuardExpression guard = iterator.next();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1143 if (!specialization.isDynamicParameterBound(guard.getExpression())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1144 iterator.remove();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1145 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1146 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1147 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1148
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1149 if (!guards.isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1150 return true;
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
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1153 if (!fastPath && specialization != null && !specialization.getAssumptionExpressions().isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1155 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1156
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1157 if (!fastPath && specialization != null && mayBeExcluded(specialization)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1158 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1159 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1160
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1161 if (!elseConnectable.isEmpty()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1162 SpecializationGroup previous = group.getPrevious();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1163 if (previous != null && hasFallthrough(previous, forType, currentValues, fastPath, previous.getGuards())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1164 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1165 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1166 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1167
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1168 List<SpecializationGroup> groupChildren = group.getChildren();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1169 if (!groupChildren.isEmpty()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1170 return hasFallthrough(groupChildren.get(groupChildren.size() - 1), forType, currentValues, fastPath, ignoreGuards);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1171 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1172
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1173 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1174 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1175
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1176 private Element createGetSuppliedChildrenMethod() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1177 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
1178
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1179 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
1180 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
1181
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1182 CodeTreeBuilder builder = method.createBuilder();
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1183 builder.startReturn().tree(createGetSuppliedChildren()).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1184
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1185 return method;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1186 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1187
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1188 private CodeTree createGetSuppliedChildren() {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1189 ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1190 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1191 builder.startNewArray(nodeArray, null);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1192 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
1193 NodeExecutionData execution = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1194 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1195 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1196 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1197 builder.tree(accessParent(nodeFieldName(execution)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1198 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1199 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1200 return builder.build();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1201 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1202
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1203 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1204
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1205 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
1206 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1207
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1208 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
1209 if (useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1210 builder.startStaticCall(specializationType(specialization), "create");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1211 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 builder.startNew(specializationType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1213 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1214 if (rootName != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1215 builder.string(rootName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1216 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1217 builder.string("root");
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 if (currentValues != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1220 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1221 CodeVariableElement var = createImplicitProfileParameter(p.getSpecification().getExecution(), p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1222 if (var != null) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1223 // we need the original name here
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1224 builder.tree(LocalVariable.fromParameter(p).createReference());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1225 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1226 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1227 for (CacheExpression cache : specialization.getCaches()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1228 LocalVariable variable = currentValues.get(cache.getParameter().getLocalName());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1229 if (variable == null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1230 throw new AssertionError("Could not bind cached value " + cache.getParameter().getLocalName() + ": " + currentValues);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1231 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1232 builder.tree(variable.createReference());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1233 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1234 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1235 LocalVariable variable = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1236 if (variable == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1237 throw new AssertionError("Could not bind assumption value " + assumption.getId() + ": " + currentValues);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1238 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1239 builder.tree(variable.createReference());
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1240 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1243
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1245 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 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
1248 if (!useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1251
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1252 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
1253 executable.setReturnType(specializationType(null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1254 executable.setSimpleName(CodeNames.of("create"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1255 executable.getModifiers().add(STATIC);
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 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
1258 builder.startReturn().startNew(specializationType(specialization));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1259 for (VariableElement parameter : executable.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1260 builder.string(parameter.getSimpleName().toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1261 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1262 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1263 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1264 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1265
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
1266 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
1267 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
1268 }
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
1269
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1270 private static String implicitClassFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1271 return execution.getName() + "ImplicitType";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1273
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1274 private static String implicitNodeFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1275 return execution.getName() + "Cast";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1277
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1278 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
1279 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
1280
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281 constructor.addParameter(new CodeVariableElement(nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282 CodeTreeBuilder builder = constructor.createBuilder();
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 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1285 if (constantIndex == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1286 builder.statement("super(index)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1287 constructor.addParameter(new CodeVariableElement(getType(int.class), "index"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1288 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1289 builder.startStatement().startSuperCall().string(constantIndex).end().end();
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 builder.statement("this.root = root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1292 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 int index = resolveSpecializationIndex(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294 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
1295
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1296 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 NodeExecutionData execution = p.getSpecification().getExecution();
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 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getTypeSystemType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301 LocalVariable var = LocalVariable.fromParameter(p).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1302
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1303 String implicitFieldName = implicitProfile.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1304 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1305 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1306 CodeTree implicitType = TypeSystemCodeGenerator.implicitType(p.getTypeSystemType(), var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1307 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
1308 } else if (options.implicitCastOptimization().isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1309 // use node that supports polymorphism
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1310 constructor.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1311 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
1312 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1313 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1314 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1315 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1316 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1317 for (CacheExpression cache : specialization.getCaches()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1318 String name = cache.getParameter().getLocalName();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1319 TypeMirror type = cache.getParameter().getType();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1320
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1321 if (ElementUtils.isAssignable(type, new ArrayCodeTypeMirror(getType(Node.class)))) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1322 CodeVariableElement var = clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), type, name));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1323 var.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(Children.class)));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1324 } else if (ElementUtils.isAssignable(type, getType(Node.class))) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1325 CodeVariableElement var = clazz.add(new CodeVariableElement(modifiers(PRIVATE), type, name));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1326 var.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(Child.class)));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1327 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1328 clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), type, name));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1329 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1330 constructor.addParameter(new CodeVariableElement(type, name));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1331 builder.startStatement().string("this.").string(name).string(" = ").string(name).end();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1332 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1333
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1334 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1335 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1336 TypeMirror type = assumption.getExpression().getResolvedType();
19293
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1337 CodeVariableElement field = clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), type, name));
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1338 field.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class)));
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1339 constructor.addParameter(new CodeVariableElement(type, name));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1340 builder.startStatement().string("this.").string(name).string(" = ").string(name).end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1341 }
18761
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 if (constructor.getParameters().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1345 // do not generate default constructor
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1346 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1347 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1348 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1349 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1350
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1351 // 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
1352 private static int resolveSpecializationIndex(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1354 return Integer.MAX_VALUE - 1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1355 } else if (specialization.isUninitialized()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1356 return Integer.MAX_VALUE;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1357 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1358 return 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1359 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1360 return specialization.getIndex();
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1363
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1364 private static CodeTree createThrowUnsupported(LocalContext currentValues) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1365 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1366 builder.startThrow().startCall("unsupported");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1367 currentValues.addReferencesTo(builder);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1368 builder.end().end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1369 return builder.build();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1370 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1371
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1372 private CodeTree createCallNext(TypeData forType, LocalContext currentValues) {
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
1373 if (singleSpecializable) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1374 return createThrowUnsupported(currentValues);
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
1375 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1376 CodeTreeBuilder callBuilder = CodeTreeBuilder.createBuilder();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1377 callBuilder.startCall("next", TypeSystemNodeFactory.executeName(null));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1378 currentValues.addReferencesTo(callBuilder, FRAME_VALUE);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1379 callBuilder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1380 return CodeTreeBuilder.createBuilder().startReturn().tree(TypeSystemCodeGenerator.expect(genericType, forType, callBuilder.build())).end().build();
18761
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
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
1383 private CodeTree createCallRemove(String reason, TypeData forType, LocalContext currentValues) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1384 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1385 return createThrowUnsupported(currentValues);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1386 }
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
1387 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1388 builder.startCall("remove");
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1389 builder.doubleQuote(reason);
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
1390 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
1391 builder.end();
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1392 CodeTree call = builder.build();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1393
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1394 builder = builder.create();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1395 builder.startReturn();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1396 builder.tree(TypeSystemCodeGenerator.expect(genericType, forType, call));
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1397 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1398 return builder.build();
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
1399 }
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
1400
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1401 private static CodeTree createCallDelegate(String methodName, String reason, TypeData forType, LocalContext currentValues) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1402 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1403 builder.startCall(methodName);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1404 if (reason != null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1405 builder.doubleQuote(reason);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1406 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1407 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1408 builder.end();
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 TypeData executedType = forType.getTypeSystem().getGenericTypeData();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1411 return TypeSystemCodeGenerator.expect(executedType, forType, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1412 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1413
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
1414 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
1415 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
1416 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
1417 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
1418 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
1419 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
1420 }
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
1421 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
1422 }
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
1423
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
1424 private ExecutableTypeData resolveExecutableType(NodeChildData child, TypeData type) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1425 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
1426 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
1427 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
1428 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
1429 }
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
1430 return executableType;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1431 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1432
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1433 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
1434 for (ExecutableTypeData executableType : findSpecializedExecutableTypes(execution, type)) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1435 if (executableType != null && (executableType.hasUnexpectedValue(context) || executableType.getType().needsCastTo(type))) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1436 return true;
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1439 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1440 }
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 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
1443 TypeData type = forType == null ? genericType : forType;
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
1444 LocalContext currentLocals = LocalContext.load(this, evaluatedArguments, varArgsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1445
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1446 if (specialization != null) {
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1447 currentLocals.loadFastPathState(specialization);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1448 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1449
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1450 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
1451 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
1452
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1453 if (!type.isGeneric()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1454 executable.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1455 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1456
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1457 CodeTreeBuilder builder = executable.createBuilder();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1458 builder.tree(createFastPath(builder, specialization, type, currentLocals));
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1459
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1460 return executable;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1461 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1462
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1463 private CodeTree createFastPath(CodeTreeBuilder parent, SpecializationData specialization, TypeData type, LocalContext currentLocals) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1464 final CodeTreeBuilder builder = parent.create();
18761
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 (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1467 LocalVariable var = currentLocals.getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1468 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1469 TypeData targetType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1470 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1471 targetType = genericType;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1472 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1473 targetType = specialization.findParameterOrDie(execution).getTypeSystemType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1474 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1475 LocalVariable shortCircuit = resolveShortCircuit(specialization, execution, currentLocals);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1476 LocalVariable value = currentLocals.createValue(execution, targetType).nextName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1477 builder.tree(createAssignExecuteChild(execution, type, value, shortCircuit, currentLocals));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1478 currentLocals.setValue(execution, value);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1479 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1480 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1481
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1482 LocalContext originalValues = currentLocals.copy();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1483 if (specialization == null) {
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1484 builder.startReturn().tree(createCallDelegate("acceptAndExecute", null, type, currentLocals)).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1485 } else if (specialization.isPolymorphic()) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1486 builder.tree(createCallNext(type, currentLocals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1487 } else if (specialization.isUninitialized()) {
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1488 builder.startReturn().tree(createCallDelegate("uninitialized", null, type, currentLocals)).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1489 } else {
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1490 final TypeData finalType = type;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1491 SpecializationGroup group = SpecializationGroup.create(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1492 SpecializationExecution executionFactory = new SpecializationExecution() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1493 public CodeTree createExecute(SpecializationData s, LocalContext values) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1494 return createFastPathExecute(builder, finalType, s, values);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1495 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1496
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1497 public boolean isFastPath() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1498 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1499 }
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 builder.tree(createGuardAndCast(group, type, currentLocals, executionFactory));
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1502 if (hasFallthrough(group, type, originalValues, true, null) || group.getSpecialization().isFallback()) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1503 builder.tree(createCallNext(type, originalValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1504 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1505 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1506 return builder.build();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1507 }
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 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
1510 LocalVariable shortCircuit = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1511 SpecializationData resolvedSpecialization = specialization;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1512 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1513 resolvedSpecialization = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1514 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1515
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1516 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1517 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
1518 CodeTree access = callTemplateMethod(accessParent(null), shortCircuitData, currentLocals);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1519 shortCircuit = currentLocals.createShortCircuitValue(execution).accessWith(access);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1520 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1521 return shortCircuit;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1524 private int calculateShortCircuitIndex(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1525 int shortCircuitIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1526 for (NodeExecutionData otherExectuion : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1527 if (otherExectuion.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1528 if (otherExectuion == execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1529 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1530 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1531 shortCircuitIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1532 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1533 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1534 return shortCircuitIndex;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1535 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1536
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1537 private CodeTree createFastPathExecute(CodeTreeBuilder parent, final TypeData forType, SpecializationData specialization, LocalContext currentValues) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1538 CodeTreeBuilder builder = parent.create();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1539 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1540 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1541 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
1542 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1543 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1544 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1545 currentValues.addReferencesTo(builder);
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 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1548 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1549 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1550 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1551 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1552 CodeTreeBuilder execute = builder.create();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1553
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1554 if (!specialization.getAssumptionExpressions().isEmpty()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1555 builder.startTryBlock();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1556 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1557 LocalVariable assumptionVar = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1558 if (assumptionVar == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1559 throw new AssertionError("Could not resolve assumption var " + currentValues);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1560 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1561 builder.startStatement().startCall("check").tree(assumptionVar.createReference()).end().end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1562 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1563 builder.end().startCatchBlock(getType(InvalidAssumptionException.class), "ae");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1564 builder.startReturn();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1565 List<String> assumptionIds = new ArrayList<>();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1566 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1567 assumptionIds.add(assumption.getId());
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1568 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1569 builder.tree(createCallDelegate("removeThis", String.format("Assumption %s invalidated", assumptionIds), forType, currentValues));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1570 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1571 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1572 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1573
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1574 execute.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1575 if (specialization.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1576 execute.startCall("unsupported");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1577 currentValues.addReferencesTo(execute, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1578 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1579 } 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
1580 execute.tree(callTemplateMethod(accessParent(null), specialization, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1581 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1582 execute.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1583 builder.tree(createFastPathTryCatchRewriteException(specialization, forType, currentValues, execute.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1584 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1585 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1586 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1587
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1588 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
1589 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
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 Set<TypeGuard> castGuards;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1592 if (execution.isFastPath()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1593 castGuards = null; // cast all
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1594 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1595 castGuards = new HashSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1596 for (TypeGuard castGuard : group.getTypeGuards()) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1597 if (isTypeGuardUsedInAnyGuardOrCacheBelow(group, currentValues, castGuard)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1598 castGuards.add(castGuard);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1599 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1600 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1601 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1602
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1603 SpecializationData specialization = group.getSpecialization();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1604 CodeTree[] checkAndCast = createTypeCheckAndLocals(specialization, group.getTypeGuards(), castGuards, currentValues, execution);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1605
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1606 CodeTree check = checkAndCast[0];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1607 CodeTree cast = checkAndCast[1];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1608
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1609 List<GuardExpression> elseGuardExpressions = group.findElseConnectableGuards();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1610 List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1611 guardExpressions.removeAll(elseGuardExpressions);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1612 CodeTree[] methodGuardAndAssertions = createMethodGuardCheck(guardExpressions, specialization, currentValues, execution.isFastPath());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1613 CodeTree methodGuards = methodGuardAndAssertions[0];
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1614 CodeTree guardAssertions = methodGuardAndAssertions[1];
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1615
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1616 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1617 if (!check.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1618 builder.startIf();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1619 builder.tree(check).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1620 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1621 ifCount++;
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 (!cast.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1624 builder.tree(cast);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1625 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1626 if (!guardAssertions.isEmpty()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1627 builder.tree(guardAssertions);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1628 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1629 boolean elseIf = !elseGuardExpressions.isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1630 if (!methodGuards.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1631 builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1632 builder.tree(methodGuards).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1633 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1634 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1635 } else if (elseIf) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1636 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1637 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1638 }
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 boolean reachable = isReachableGroup(group, ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1641 if (reachable) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1642 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1643 builder.tree(createGuardAndCast(child, forType, currentValues.copy(), execution));
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 if (specialization != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1646 builder.tree(execution.createExecute(specialization, currentValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1647 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1648 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1649 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1650
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1651 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1652 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1653
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1654 private static boolean isReachableGroup(SpecializationGroup group, int ifCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1655 if (ifCount != 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1656 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1657 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1658 SpecializationGroup previous = group.getPreviousGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1659 if (previous == null || previous.findElseConnectableGuards().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1660 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1661 }
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 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1664 * 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
1665 * 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
1666 */
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1667 if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() &&
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1668 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1669 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1670 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1671
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1672 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1673 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1674
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1675 private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1676 String localName = currentValues.getValue(typeGuard.getSignatureIndex()).getName();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1677
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1678 SpecializationData specialization = group.getSpecialization();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1679 for (GuardExpression guard : group.getGuards()) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1680 if (isVariableBoundIn(specialization, guard.getExpression(), localName, currentValues)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1681 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1682 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1683 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1684 if (specialization != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1685 for (CacheExpression cache : specialization.getCaches()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1686 if (isVariableBoundIn(specialization, cache.getExpression(), localName, currentValues)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1687 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1688 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1689 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1690 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1691
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1692 for (SpecializationGroup child : group.getChildren()) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1693 if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1694 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1695 }
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1698 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1699 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1700
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1701 private static boolean isVariableBoundIn(SpecializationData specialization, DSLExpression expression, String localName, LocalContext currentValues) throws AssertionError {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1702 Map<Variable, LocalVariable> boundValues = bindExpressionValues(expression, specialization, currentValues);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1703 for (Variable var : expression.findBoundVariables()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1704 LocalVariable target = boundValues.get(var);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1705 if (target != null && localName.equals(target.getName())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1706 return true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1707 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1708 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1709 return false;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1710 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1711
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1712 private CodeExecutableElement createExecuteChildMethod(NodeExecutionData execution, TypeData targetType) {
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
1713 LocalContext locals = LocalContext.load(this, 0, varArgsThreshold);
18761
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 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
1716 if (hasUnexpectedResult(execution, targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1717 method.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1718 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1719
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1720 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1721 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1722 method.addParameter(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1723 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1724
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1725 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
1726 NodeExecutionData executeWith = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1727 LocalVariable var = locals.createValue(executeWith, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1728 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1729 locals.setValue(executeWith, var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1730 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1731
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1732 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
1733 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
1734 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1735 builder.statement(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1736 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1737 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1738 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1739 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1740 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1741
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1742 private CodeVariableElement createImplicitProfileParameter(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1743 if (targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1744 switch (options.implicitCastOptimization()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1745 case NONE:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1746 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1747 case DUPLICATE_TAIL:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1748 return new CodeVariableElement(getType(Class.class), implicitClassFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1749 case MERGE_CASTS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1750 return new CodeVariableElement(ImplicitCastNodeFactory.type(targetType), implicitNodeFieldName(execution));
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1753 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1754 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1755
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1756 private boolean isExecuteChildShared(NodeExecutionData execution, TypeData targetType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1757 if (targetType.isVoid()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1758 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1759 } 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
1760 return resolvePolymorphicExecutables(execution).size() >= 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1761 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1762 if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1763 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1764 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1765 if (!targetType.hasImplicitSourceTypes()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1766 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1767 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1768
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1769 int uses = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1770 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1771 List<Parameter> parameters = specialization.findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1772 for (Parameter parameter : parameters) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1773 if (targetType.equals(parameter.getTypeSystemType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1774 uses++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1775 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1776 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1777 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1778 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
1779 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
1780 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1781 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1782 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1783 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1784 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1785
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1786 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
1787 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1788 boolean hasUnexpected = hasUnexpectedResult(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1789
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1790 CodeTree executeChild;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1791 if (isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1792 executeChild = createCallSharedExecuteChild(execution, targetValue, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1793 } 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
1794 executeChild = createExecuteChild(execution, targetValue, currentValues, false);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1795 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1796
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1797 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
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 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
1800 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
1801 }
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
1802
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1803 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1804 if (hasUnexpected) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1805 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
1806 LocalContext slowPathValues = currentValues.copy();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1807
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1808 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
1809 boolean found = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1810 for (NodeExecutionData otherExecution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1811 if (found) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1812 LocalVariable childEvaluatedValue = slowPathValues.createValue(otherExecution, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1813 LocalVariable genericShortCircuit = resolveShortCircuit(null, otherExecution, slowPathValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1814 builder.tree(createAssignExecuteChild(otherExecution, genericType, childEvaluatedValue, genericShortCircuit, slowPathValues));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1815 slowPathValues.setValue(otherExecution, childEvaluatedValue);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1816 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1817 // skip forward already evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1818 found = execution == otherExecution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1819 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1820 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1821 builder.tree(createCallNext(returnType, slowPathValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1822 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1823 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1824
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1825 return createShortCircuit(targetValue, shortCircuit, builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1826 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1827
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1828 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
1829 if (shortCircuitValue == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1830 return tryExecute;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1831 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1832
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1833 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
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 builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1836 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
1837
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1838 builder.startIf().string(shortCircuitValue.getName()).end().startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1839 builder.tree(tryExecute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1840 builder.end();
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 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1843 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1844
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1845 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
1846 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1847 boolean hasDeclaration = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1848 if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1849 builder.tree(value.createDeclaration(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1850 hasDeclaration = true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1851 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1852
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1853 if (hasTry) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1854 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1855 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1856 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1857 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1858
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1859 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1860 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1861 if (hasDeclaration || !needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1862 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1863 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1864 builder.type(value.getTypeMirror()).string(" ").tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1865 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1866 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1867 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1868 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1869 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1870
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1871 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1872
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1873 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1874 }
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 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
1877 if (!isExecuteChildShared(execution, targetValue.getType())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1878 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
1879 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1880
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1881 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1882 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
1883 builder.startCall(executeChildMethodName(execution, targetValue.getType()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1884 builder.string(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1885
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1886 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetValue.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1887 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1888 builder.string(implicitProfile.getName());
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 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
1891 builder.tree(currentValues.getValue(i).createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1892 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1893 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1894 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1895 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1896
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
1897 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
1898 final CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1899
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
1900 CodeTree assignment = createAssignmentStart(target, shared);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1901
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
1902 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
1903 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
1904 throw new AssertionError(); // cannot execute child
18797
3db8ec140f3f Truffle-DSL: fix implicit cast optimization bug.
Christian Humer <christian.humer@gmail.com>
parents: 18788
diff changeset
1905 } else if (executableTypes.size() == 1 && !target.getType().hasImplicitSourceTypes()) {
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
1906 ExecutableTypeData executableType = executableTypes.iterator().next();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1907 if (target.getType().isGeneric() && executableType.getEvaluatedCount() == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1908 return createPolymorphicExecuteChild(execution, target, currentValues, shared);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1909 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1910 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
1911 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
1912 }
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
1913 } 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
1914 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
1915 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
1916 } 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
1917 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
1918 } 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
1919 // 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
1920 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
1921 } 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
1922 throw new AssertionError();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1923 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1924 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1925 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1926 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1927
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1928 private CodeTree createSingleExecute(NodeExecutionData execution, LocalVariable target, LocalContext currentValues, ExecutableTypeData executableType) {
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
1929 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
1930 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
1931 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
1932 }
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
1933
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1934 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
1935 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
1936 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
1937 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
1938 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1939
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
1940 List<ExecutableTypeData> specializedExecutables = resolvePolymorphicExecutables(execution);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1941 Collections.sort(specializedExecutables, new Comparator<ExecutableTypeData>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1942 public int compare(ExecutableTypeData o1, ExecutableTypeData o2) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1943 return o1.getType().compareTo(o2.getType());
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
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
1947 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
1948 CodeTree executeGeneric = createSingleExecute(execution, target, currentValues, genericExecutableType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1949
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
1950 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
1951 if (specializedExecutables.isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1952 builder.tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1953 builder.tree(executeGeneric);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1954 } 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
1955 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
1956 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
1957 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
1958
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
1959 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
1960
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
1961 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
1962 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
1963 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
1964 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
1965 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
1966 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
1967 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
1968 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
1969 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
1970 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
1971 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
1972 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
1973 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
1974 }
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
1975
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
1976 // 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
1977 polyChainBuilder.startElseIf().string(profileField).string(" == null").end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1978 polyChainBuilder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1979 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
1980 polyChainBuilder.declaration(genericExecutableType.getType().getPrimitiveType(), valueFieldName, executeGeneric);
18761
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 hasSpecializedTypes = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1983 for (ExecutableTypeData executableType : specializedExecutables) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1984 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
1985 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
1986 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1987 polyChainBuilder.startBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1988 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
1989 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1990 }
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 polyChainBuilder.startElseBlock();
18777
76cbf5f33f82 Truffle-DSL: fixed bug for polymorphic execute optimization.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
1993 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
1994 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
1995 polyChainBuilder.startReturn().string(valueFieldName).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1996 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1997
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
1998 // else -> execute generic
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1999 polyChainBuilder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2000 polyChainBuilder.startStatement().tree(assignment).tree(executeGeneric).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2001 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2002
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
2003 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
2004 if (encounteredUnexpectedResult) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2005 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
2006 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2007 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2008 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
2009 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
2010 builder.startReturn().string("ex.getResult()").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2011 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
2012 } 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
2013 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2014 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2015 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2016 return builder.build();
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
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
2019 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
2020 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
2021 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
2022 }
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
2023 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
2024 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
2025 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
2026 }
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
2027 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
2028 }
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
2029
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
2030 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
2031 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2032 if (shared) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2033 builder.string("return ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2034 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2035 builder.string(target.getName()).string(" = ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2036 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2037 return builder.build();
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 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
2041 CodeTreeBuilder builder = parent.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2042 List<TypeData> sourceTypes = target.getType().getImplicitSourceTypes();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2043 String implicitClassFieldName = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2044 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
2045 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
2046
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2047 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2048 for (ExecutableTypeData executableType : executableTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2049 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2050 builder.string(implicitClassFieldName).string(" == ").typeLiteral(executableType.getType().getBoxedType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2051 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2052 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2053 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2054
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
2055 CodeTree execute = callTemplateMethod(accessParent(nodeFieldName), executableType, currentValues);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2056 ImplicitCastData cast = typeSystem.lookupCast(executableType.getType(), target.getType());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2057 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
2058 execute = callTemplateMethod(null, cast, execute);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2059 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2060 builder.tree(execute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2061 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2062 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2063 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2064
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2065 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2066 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2067 }
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 LocalVariable genericValue = target.makeGeneric().nextName();
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2070 builder.tree(createAssignExecuteChild(execution, genericValue.getType(), genericValue, null, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2071 if (executableTypes.size() == sourceTypes.size()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2072 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
2073 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2074 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2075 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
2076 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2077 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2078
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2079 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2080 builder.end();
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 return builder.build();
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
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
2085 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
2086 if (specialization.getExceptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2087 return execution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2088 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2089 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2090 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2091 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2092 TypeMirror[] exceptionTypes = new TypeMirror[specialization.getExceptions().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2093 for (int i = 0; i < exceptionTypes.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2094 exceptionTypes[i] = specialization.getExceptions().get(i).getJavaClass();
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 builder.end().startCatchBlock(exceptionTypes, "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2097 builder.startStatement().tree(accessParent(excludedFieldName(specialization))).string(" = true").end();
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
2098 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
2099 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2100 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2101 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2102
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2103 private CodeTree[] createMethodGuardCheck(List<GuardExpression> guardExpressions, SpecializationData specialization, LocalContext currentValues, boolean fastPath) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2104 CodeTreeBuilder expressionBuilder = CodeTreeBuilder.createBuilder();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2105 CodeTreeBuilder assertionBuilder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2106 String and = "";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2107 for (GuardExpression guard : guardExpressions) {
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2108 DSLExpression expression = guard.getExpression();
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2109
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2110 Map<Variable, CodeTree> resolvedBindings = castBoundTypes(bindExpressionValues(expression, specialization, currentValues));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2111 CodeTree expressionCode = DSLExpressionGenerator.write(expression, accessParent(null), resolvedBindings);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2112
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2113 if (!specialization.isDynamicParameterBound(expression) && fastPath) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2114 /*
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2115 * Guards where no dynamic parameters are bound can just be executed on the fast
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2116 * path.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2117 */
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2118 assertionBuilder.startAssert().tree(expressionCode).end();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2119 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2120 expressionBuilder.string(and);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2121 expressionBuilder.tree(expressionCode);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2122 and = " && ";
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2123 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2124 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2125 return new CodeTree[]{expressionBuilder.build(), assertionBuilder.build()};
18761
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
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2128 private static Map<Variable, CodeTree> castBoundTypes(Map<Variable, LocalVariable> bindings) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2129 Map<Variable, CodeTree> resolvedBindings = new HashMap<>();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2130 for (Variable variable : bindings.keySet()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2131 LocalVariable localVariable = bindings.get(variable);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2132 CodeTree resolved = localVariable.createReference();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2133 if (!ElementUtils.typeEquals(variable.getResolvedType(), localVariable.getTypeMirror())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2134 resolved = CodeTreeBuilder.createBuilder().cast(variable.getResolvedType(), resolved).build();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2135 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2136 resolvedBindings.put(variable, resolved);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2137 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2138 return resolvedBindings;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2139 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2140
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2141 private static Map<Variable, LocalVariable> bindExpressionValues(DSLExpression expression, SpecializationData specialization, LocalContext currentValues) throws AssertionError {
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2142 Map<Variable, LocalVariable> bindings = new HashMap<>();
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2143
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2144 Set<Variable> boundVariables = expression.findBoundVariables();
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2145 if (specialization == null && !boundVariables.isEmpty()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2146 throw new AssertionError("Cannot bind guard variable in non-specialization group. yet.");
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2147 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2148
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2149 // resolve bindings for local context
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2150 for (Variable variable : boundVariables) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2151 Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2152 if (resolvedParameter != null) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2153 LocalVariable localVariable;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2154 if (resolvedParameter.getSpecification().isSignature()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2155 NodeExecutionData execution = resolvedParameter.getSpecification().getExecution();
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2156 localVariable = currentValues.getValue(execution);
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2157 } else {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2158 localVariable = currentValues.get(resolvedParameter.getLocalName());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2159 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2160 if (localVariable != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2161 bindings.put(variable, localVariable);
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2162 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2163 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2164 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2165 return bindings;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2166 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2167
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2168 private CodeTree[] createTypeCheckAndLocals(SpecializationData specialization, List<TypeGuard> typeGuards, Set<TypeGuard> castGuards, LocalContext currentValues,
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2169 SpecializationExecution specializationExecution) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2170 CodeTreeBuilder checksBuilder = CodeTreeBuilder.createBuilder();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2171 CodeTreeBuilder localsBuilder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2172 for (TypeGuard typeGuard : typeGuards) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2173 int signatureIndex = typeGuard.getSignatureIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2174 LocalVariable value = currentValues.getValue(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2175 TypeData targetType = typeGuard.getType();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2176 if (!value.getType().needsCastTo(targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2177 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2178 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2179 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2180 if (!checksBuilder.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2181 checksBuilder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2182 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2183
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2184 CodeTreeBuilder checkBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2185 CodeTreeBuilder castBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2186
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2187 LocalVariable shortCircuit = currentValues.getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2188 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2189 checkBuilder.string("(");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2190 CodeTreeBuilder referenceBuilder = checkBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2191 if (!shortCircuit.getType().isPrimitive()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2192 referenceBuilder.string("(boolean) ");
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 referenceBuilder.tree(shortCircuit.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2195 checkBuilder.string("!").tree(referenceBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2196 checkBuilder.string(" || ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2197 castBuilder.tree(referenceBuilder.build()).string(" ? ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2198 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2199
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2200 List<ImplicitCastData> sourceTypes = typeSystem.lookupByTargetType(targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2201 CodeTree valueReference = value.createReference();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2202 if (sourceTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2203 checkBuilder.tree(TypeSystemCodeGenerator.check(targetType, value.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2204 castBuilder.tree(TypeSystemCodeGenerator.cast(targetType, valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2205 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2206 ImplicitCastOptimization opt = options.implicitCastOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2207 if (specializationExecution.isFastPath() && !opt.isNone()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2208 if (opt.isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2209 String typeHintField = implicitClassFieldName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2210 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2211 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, typeHintField));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2212 } else if (opt.isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2213 checkBuilder.tree(ImplicitCastNodeFactory.check(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2214 castBuilder.tree(ImplicitCastNodeFactory.cast(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2215 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2216 throw new AssertionError("implicit cast opt");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2217 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2218 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2219 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2220 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(targetType, valueReference, null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2221 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2222 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2223
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2224 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2225 checkBuilder.string(")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2226 castBuilder.string(" : ").defaultValue(targetType.getPrimitiveType());
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 if (castGuards == null || castGuards.contains(typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2230 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
2231 currentValues.setValue(execution, castVariable);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2232 localsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2233 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2234
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2235 checksBuilder.tree(checkBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2236 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2237
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2238 if (specialization != null && !specializationExecution.isFastPath()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2239 for (CacheExpression cache : specialization.getCaches()) {
19293
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2240 if (specialization.isCacheBoundByGuard(cache)) {
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2241 initializeCache(localsBuilder, specialization, cache, currentValues);
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2242 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2243 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2244 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2245
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2246 return new CodeTree[]{checksBuilder.build(), localsBuilder.build()};
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2247 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2248
19293
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2249 private void initializeCache(CodeTreeBuilder builder, SpecializationData specialization, CacheExpression cache, LocalContext currentValues) {
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2250 CodeTree initializer = DSLExpressionGenerator.write(cache.getExpression(), accessParent(null), castBoundTypes(bindExpressionValues(cache.getExpression(), specialization, currentValues)));
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2251 String name = cache.getParameter().getLocalName();
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2252 // multiple specializations might use the same name
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2253 String varName = name + specialization.getIndex();
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2254 TypeMirror type = cache.getParameter().getType();
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2255 builder.declaration(type, varName, initializer);
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2256 currentValues.set(name, new LocalVariable(null, type, varName, null));
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2257 }
21b9b9941775 Truffle-DSL: initialize caches late if possible; fix assumption arrays need a @CompilationFinal to be checked.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
2258
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2259 public static final class LocalContext {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2260
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2261 private final NodeGenFactory factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2262 private final Map<String, LocalVariable> values = new HashMap<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2263
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2264 private LocalContext(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2265 this.factory = factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2266 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2267
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2268 public void loadFastPathState(SpecializationData specialization) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2269 for (CacheExpression cache : specialization.getCaches()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2270 Parameter cacheParameter = cache.getParameter();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2271 String name = cacheParameter.getVariableElement().getSimpleName().toString();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2272 set(cacheParameter.getLocalName(), new LocalVariable(cacheParameter.getTypeSystemType(), cacheParameter.getType(), name, CodeTreeBuilder.singleString("this." + name)));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2273 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2274
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2275 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2276 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2277 TypeMirror type = assumption.getExpression().getResolvedType();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2278 set(name, new LocalVariable(null, type, name, CodeTreeBuilder.singleString("this." + name)));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2279 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2280 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2281
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2282 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
2283 CodeExecutableElement method = new CodeExecutableElement(modifiers, returnType, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2284 addParametersTo(method, optionalArguments);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2285 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2286 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2287
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2288 public static LocalContext load(NodeGenFactory factory, int signatureSize, int varargsThreshold) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2289 LocalContext context = new LocalContext(factory);
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2290 context.loadValues(signatureSize, varargsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2291 return context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2292 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2293
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2294 public static LocalContext load(NodeGenFactory factory) {
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2295 return load(factory, factory.node.getSignatureSize(), factory.varArgsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2296 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2297
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2298 public LocalContext copy() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2299 LocalContext copy = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2300 copy.values.putAll(values);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2301 return copy;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2302 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2303
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2304 private static String fieldValueName(NodeFieldData field) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2305 return field.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2306 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2307
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2308 @SuppressWarnings("static-method")
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2309 public LocalVariable createValue(NodeExecutionData execution, TypeData type) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2310 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
2311 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2312
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2313 public LocalVariable createShortCircuitValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2314 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
2315 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2316
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2317 private static String valueName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2318 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2319 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2320
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2321 private static String shortCircuitName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2322 return "has" + ElementUtils.firstLetterUpperCase(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2323 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2324
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2325 public void set(String id, LocalVariable var) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2326 values.put(id, var);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2327 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2328
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2329 public LocalVariable get(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2330 return values.get(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2331 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2332
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2333 public LocalVariable get(Parameter parameter, int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2334 LocalVariable var = get(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2335 if (var == null && parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2336 // lookup by signature index for executeWith
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2337 List<NodeExecutionData> childExecutions = factory.node.getChildExecutions();
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2338 if (signatureIndex < childExecutions.size() && signatureIndex >= 0) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2339 NodeExecutionData execution = childExecutions.get(signatureIndex);
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2340 var = getValue(execution);
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2341 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2342 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2343 return var;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2344 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2345
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2346 public LocalVariable getValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2347 return get(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2348 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2349
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2350 public LocalVariable getValue(int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2351 return getValue(factory.node.getChildExecutions().get(signatureIndex));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2352 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2353
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2354 public void removeValue(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2355 values.remove(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2356 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2357
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2358 public void setValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2359 values.put(valueName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2360 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2361
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2362 public void setShortCircuitValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2363 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2364 return;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2365 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2366 values.put(shortCircuitName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2367 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2368
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2369 private boolean needsVarargs(boolean requireLoaded, int varArgsThreshold) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2370 int size = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2371 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2372 if (requireLoaded && getValue(execution) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2373 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2374 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2375 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2376 size += 2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2377 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2378 size++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2379 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2380 }
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2381 return size >= varArgsThreshold;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2382 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2383
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2384 private void loadValues(int evaluatedArguments, int varargsThreshold) {
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
2385 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
2386
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2387 for (NodeFieldData field : factory.node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2388 String fieldName = fieldValueName(field);
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2389 values.put(fieldName, new LocalVariable(null, field.getType(), fieldName, factory.accessParent(field.getName())));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2390 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2391
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2392 boolean varargs = needsVarargs(false, varargsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2393 for (int i = 0; i < evaluatedArguments; i++) {
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2394 List<NodeExecutionData> childExecutions = factory.node.getChildExecutions();
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2395 if (i >= childExecutions.size()) {
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2396 break;
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2397 }
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2398 NodeExecutionData execution = childExecutions.get(i);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2399 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2400 LocalVariable shortCircuit = createShortCircuitValue(execution).makeGeneric();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2401 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2402 shortCircuit = shortCircuit.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2403 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2404 values.put(shortCircuit.getName(), shortCircuit);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2405 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2406 LocalVariable value = createValue(execution, factory.genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2407 if (varargs) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2408 value = value.accessWith(createReadVarargs(i));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2409 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2410 values.put(value.getName(), value);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2411 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2412 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2413
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2414 private static CodeTree createReadVarargs(int i) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2415 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
2416 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2417
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2418 public void addReferencesTo(CodeTreeBuilder builder, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2419 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2420 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2421 if (local == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2422 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2423 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2424 builder.tree(local.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2425 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2426 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2427
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2428 List<NodeExecutionData> executions = factory.node.getChildExecutions();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2429 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2430 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2431 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2432 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2433 builder.tree(shortCircuitVar.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2434 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2435 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2436 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2437 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2438 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2439 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
2440 // 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
2441 builder.string("(Object) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2442 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2443 builder.tree(var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2444 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2445 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2446 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2447 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2448
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2449 public void addParametersTo(CodeExecutableElement method, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2450 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2451 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2452 if (local != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2453 method.addParameter(local.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2454 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2455 }
18805
121748e43a01 Truffle-DSL: fix execute methods with evaluated arguments were not handled correctly with varargs arguments.
Christian Humer <christian.humer@gmail.com>
parents: 18797
diff changeset
2456 if (needsVarargs(true, factory.varArgsThreshold)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2457 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
2458 method.setVarArgs(true);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2459 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2460 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2461 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2462 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2463 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2464 method.addParameter(shortCircuitVar.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2465 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2466 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2467
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2468 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2469 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2470 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2471 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2472 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2473 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2474 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2475
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2476 private LocalVariable getShortCircuit(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2477 return values.get(shortCircuitName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2478 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2479
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2480 @Override
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2481 public String toString() {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2482 return "LocalContext [values=" + values + "]";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2483 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2484
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2485 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2486
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2487 public static final class LocalVariable {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2488
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2489 private final TypeData type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2490 private final TypeMirror typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2491 private final CodeTree accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2492 private final String name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2493
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2494 public static LocalVariable fromParameter(Parameter parameter) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2495 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2496 String name = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2497 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2498 name = parameter.getLocalName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2499 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2500 name = createName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2501 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2502 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
2503 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2504
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2505 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
2506 Objects.requireNonNull(typeMirror);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2507 this.typeMirror = typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2508 this.accessorTree = accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2509 this.type = type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2510 this.name = name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2511 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2512
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2513 public TypeData getType() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2514 return type;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2515 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2516
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2517 public String getShortCircuitName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2518 return "has" + ElementUtils.firstLetterUpperCase(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2519 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2520
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2521 public String getName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2522 return name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2523 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2524
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2525 private static String createNextName(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2526 return name + "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2527 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2528
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2529 private static String createName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2530 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2531 return "<error>";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2532 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2533 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2534 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2535
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2536 public TypeMirror getTypeMirror() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2537 return typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2538 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2539
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2540 public CodeVariableElement createParameter() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2541 return new CodeVariableElement(getTypeMirror(), getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2542 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2543
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2544 public CodeTree createDeclaration(CodeTree init) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2545 return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2546 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2547
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2548 public CodeTree createReference() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2549 if (accessorTree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2550 return accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2551 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2552 return CodeTreeBuilder.singleString(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2553 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2554 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2555
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2556 public LocalVariable newType(TypeData newType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2557 return new LocalVariable(newType, newType.getPrimitiveType(), name, accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2558 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2559
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2560 public LocalVariable newType(TypeMirror newType) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2561 return new LocalVariable(type, newType, name, accessorTree);
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2562 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2563
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2564 public LocalVariable accessWith(CodeTree tree) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2565 return new LocalVariable(type, typeMirror, name, tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2566 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2567
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2568 public LocalVariable nextName() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2569 return new LocalVariable(type, typeMirror, createNextName(name), accessorTree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2570 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2571
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2572 public LocalVariable makeGeneric() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2573 return newType(type.getTypeSystem().getGenericTypeData());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2574 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2575
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2576 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2577
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2578 private interface SpecializationExecution {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2579
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2580 boolean isFastPath();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2581
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2582 CodeTree createExecute(SpecializationData specialization, LocalContext currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2583
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2584 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2585
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2586 }