annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 22508:a619835e6709

SpecializationNode refactoring: update root field through generated setter
author Andreas Woess <andreas.woess@oracle.com>
date Thu, 17 Dec 2015 16:16:10 +0100
parents dc83cc1f94f2
children 60c68f691534
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
22508
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
25 import static com.oracle.truffle.dsl.processor.generator.GeneratorUtils.createClass;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
26 import static com.oracle.truffle.dsl.processor.generator.GeneratorUtils.createTransferToInterpreterAndInvalidate;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
27 import static com.oracle.truffle.dsl.processor.generator.GeneratorUtils.isTypeBoxingOptimized;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
28 import static com.oracle.truffle.dsl.processor.java.ElementUtils.compareType;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
29 import static com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
30 import static com.oracle.truffle.dsl.processor.java.ElementUtils.getTypeId;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
31 import static com.oracle.truffle.dsl.processor.java.ElementUtils.isObject;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
32 import static com.oracle.truffle.dsl.processor.java.ElementUtils.isSubtypeBoxed;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
33 import static com.oracle.truffle.dsl.processor.java.ElementUtils.isVoid;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
34 import static com.oracle.truffle.dsl.processor.java.ElementUtils.modifiers;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
35 import static com.oracle.truffle.dsl.processor.java.ElementUtils.needsCastTo;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
36 import static com.oracle.truffle.dsl.processor.java.ElementUtils.setVisibility;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
37 import static com.oracle.truffle.dsl.processor.java.ElementUtils.typeEquals;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
38 import static javax.lang.model.element.Modifier.ABSTRACT;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
39 import static javax.lang.model.element.Modifier.FINAL;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
40 import static javax.lang.model.element.Modifier.PRIVATE;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
41 import static javax.lang.model.element.Modifier.PROTECTED;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
42 import static javax.lang.model.element.Modifier.PUBLIC;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
43 import static javax.lang.model.element.Modifier.STATIC;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
44
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
45 import java.util.ArrayList;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
46 import java.util.Arrays;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
47 import java.util.Collection;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
48 import java.util.Collections;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
49 import java.util.Comparator;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
50 import java.util.HashMap;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
51 import java.util.HashSet;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
52 import java.util.LinkedHashMap;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
53 import java.util.List;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
54 import java.util.ListIterator;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
55 import java.util.Map;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
56 import java.util.Objects;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
57 import java.util.Set;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
58
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
59 import javax.lang.model.element.Element;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
60 import javax.lang.model.element.ExecutableElement;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
61 import javax.lang.model.element.Modifier;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
62 import javax.lang.model.element.TypeElement;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
63 import javax.lang.model.element.VariableElement;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
64 import javax.lang.model.type.ArrayType;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
65 import javax.lang.model.type.DeclaredType;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
66 import javax.lang.model.type.TypeMirror;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
67 import javax.lang.model.util.ElementFilter;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
68
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
69 import com.oracle.truffle.api.CompilerDirectives;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
72 import com.oracle.truffle.api.dsl.Cached;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
73 import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
74 import com.oracle.truffle.api.dsl.internal.DSLOptions;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 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
76 import com.oracle.truffle.api.dsl.internal.DSLOptions.TypeBoxingOptimization;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
77 import com.oracle.truffle.api.dsl.internal.SpecializationNode;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
78 import com.oracle.truffle.api.dsl.internal.SpecializedNode;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
79 import com.oracle.truffle.api.dsl.internal.SuppressFBWarnings;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
80 import com.oracle.truffle.api.frame.Frame;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
81 import com.oracle.truffle.api.nodes.InvalidAssumptionException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
82 import com.oracle.truffle.api.nodes.Node;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 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
84 import com.oracle.truffle.api.nodes.Node.Children;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
85 import com.oracle.truffle.api.nodes.NodeCost;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
86 import com.oracle.truffle.api.nodes.UnexpectedResultException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
87 import com.oracle.truffle.dsl.processor.ProcessorContext;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
88 import com.oracle.truffle.dsl.processor.expression.DSLExpression;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
89 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
90 import com.oracle.truffle.dsl.processor.java.ElementUtils;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
91 import com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
92 import com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
93 import com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
94 import com.oracle.truffle.dsl.processor.java.model.CodeNames;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
95 import com.oracle.truffle.dsl.processor.java.model.CodeTree;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
96 import com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
97 import com.oracle.truffle.dsl.processor.java.model.CodeTypeElement;
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
98 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
99 import com.oracle.truffle.dsl.processor.java.model.CodeVariableElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
100 import com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
101 import com.oracle.truffle.dsl.processor.model.AssumptionExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
102 import com.oracle.truffle.dsl.processor.model.CacheExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
103 import com.oracle.truffle.dsl.processor.model.CreateCastData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
104 import com.oracle.truffle.dsl.processor.model.ExecutableTypeData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
105 import com.oracle.truffle.dsl.processor.model.GuardExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
106 import com.oracle.truffle.dsl.processor.model.ImplicitCastData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
107 import com.oracle.truffle.dsl.processor.model.NodeChildData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
108 import com.oracle.truffle.dsl.processor.model.NodeData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
109 import com.oracle.truffle.dsl.processor.model.NodeExecutionData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
110 import com.oracle.truffle.dsl.processor.model.NodeFieldData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
111 import com.oracle.truffle.dsl.processor.model.Parameter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
112 import com.oracle.truffle.dsl.processor.model.ShortCircuitData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
113 import com.oracle.truffle.dsl.processor.model.SpecializationData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
114 import com.oracle.truffle.dsl.processor.model.TemplateMethod;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
115 import com.oracle.truffle.dsl.processor.model.TypeSystemData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22003
diff changeset
116 import com.oracle.truffle.dsl.processor.parser.SpecializationGroup;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 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
118
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 public class NodeGenFactory {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
121 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
122 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
123 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
124
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 private final ProcessorContext context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 private final NodeData node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127 private final TypeSystemData typeSystem;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
128 private final TypeMirror genericType;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 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
130 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
131 private final int varArgsThreshold;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
132 private final Set<TypeMirror> expectedTypes = new HashSet<>();
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
133 private final Set<NodeExecutionData> usedExecuteChildMethods = new HashSet<>();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
134 private boolean nextUsed;
21877
23f0f181bc05 Truffle-DSL: fix unsupported method for single specializable nodes was generated too often.
Christian Humer <christian.humer@gmail.com>
parents: 21077
diff changeset
135 private boolean singleSpecializableUnsupportedUsed;
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
136
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
137 private List<ExecutableTypeData> usedTypes;
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
138 private List<SpecializationData> reachableSpecializations;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 public NodeGenFactory(ProcessorContext context, NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 this.context = context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 this.node = node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 this.typeSystem = node.getTypeSystem();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
144 this.genericType = context.getType(Object.class);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 this.options = typeSystem.getOptions();
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
146 this.varArgsThreshold = calculateVarArgsThreshold();
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
147 this.reachableSpecializations = calculateReachableSpecializations();
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
148 this.singleSpecializable = isSingleSpecializableImpl();
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
149 this.usedTypes = filterBaseExecutableTypes(node.getExecutableTypes(), reachableSpecializations);
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
150 }
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
151
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
152 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
153 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
154 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
155
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
156 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
157 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
158 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
159 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
160 }
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
161 }
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
162 return maxParameters;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 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
166 return resolveNodeId(node) + NODE_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
169 private static String assumptionName(AssumptionExpression assumption) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
170 return assumption.getId() + NAME_SUFFIX;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
171 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
172
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173 private static String resolveNodeId(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174 String nodeid = node.getNodeId();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
176 nodeid = nodeid.substring(0, nodeid.length() - 4);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
177 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 return nodeid;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 public static TypeMirror nodeType(NodeData node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182 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
183 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 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
186 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
187 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
188 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
189 } 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
190 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
191 }
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
192 return id + "Node_";
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
194
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
195 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
196 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
197 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 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
200 return execution.getName() + "Type" + NAME_SUFFIX;
18761
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 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
204 return execution.getName() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
207 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
208 return "specialization" + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
210
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211 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
212 return "exclude" + specialization.getId() + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
215 private static String executeChildMethodName(NodeExecutionData execution, TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
216 return "execute" + ElementUtils.firstLetterUpperCase(execution.getName()) + (ElementUtils.isObject(type) ? "" : getTypeId(type)) + NAME_SUFFIX;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
218
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
219 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
220 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
221 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
222 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
223 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
224 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
225 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
226 } else {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
227 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
228 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
229 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
230 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
231 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
232 }
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 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
236 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
237 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
238
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
239 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240 clazz.addOptional(createAccessChildMethod(child));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
243 for (NodeFieldData field : node.getFields()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
244 if (!field.isGenerated()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
245 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
246 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
247
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
248 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
249 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
250 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), field.getGetter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
251 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
252 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
253 clazz.add(method);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
254 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
255 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
256
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18805
diff changeset
257 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
258 clazz.add(createNodeConstructor(clazz, superConstructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
260
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261 for (NodeExecutionData execution : node.getChildExecutions()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
262 if (execution.getChild() != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
263 clazz.add(createNodeField(PRIVATE, execution.getNodeType(), nodeFieldName(execution), Child.class));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
264 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
267 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
268 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
269 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
270 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
274 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 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
276 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279 clazz.add(createGetCostMethod());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280
19348
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
281 avoidFindbugsProblems(clazz);
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
282
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
283 if (singleSpecializable) {
20999
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
284 SpecializationData specialization = reachableSpecializations.iterator().next();
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
285
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
286 for (ExecutableTypeData execType : usedTypes) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
287 if (execType.getMethod() == null) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
288 boolean foundDelegate = false;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
289 for (ExecutableTypeData type : usedTypes) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
290 if (type == execType) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
291 continue;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
292 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
293 if (findFastPathDelegate(specialization.getReturnType().getType(), type, usedTypes) == execType) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
294 foundDelegate = true;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
295 break;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
296 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
297 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
298 // just exclude synthetic execute methods that were not delegated to
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
299 if (!foundDelegate) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
300 continue;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
301 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
302 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
303
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
304 clazz.add(createExecutableTypeOverride(usedTypes, execType));
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
305 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
306
21877
23f0f181bc05 Truffle-DSL: fix unsupported method for single specializable nodes was generated too often.
Christian Humer <christian.humer@gmail.com>
parents: 21077
diff changeset
307 if (singleSpecializableUnsupportedUsed) {
21879
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
308 addUnsupportedMethod(clazz);
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
309 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
310 } else {
20999
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
311
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
312 for (ExecutableTypeData execType : usedTypes) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
313 if (execType.getMethod() == null) {
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
314 continue;
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
315 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
316 clazz.add(createExecutableTypeOverride(usedTypes, execType));
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
317 }
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
318
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
319 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
320 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
321 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
322 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
323 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
324
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
325 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
326 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
327 builder.startStatement();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
328 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
329 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
330 builder.end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333
20999
ef2825da2e43 Truffle-DSL: fixed generation of unused synthetic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
334 for (TypeMirror type : ElementUtils.uniqueSortedTypes(expectedTypes, false)) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
335 if (!typeSystem.hasType(type)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
336 clazz.addOptional(TypeSystemCodeGenerator.createExpectMethod(PRIVATE, typeSystem, context.getType(Object.class), type));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
337 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
338 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
339
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
340 return clazz;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
341 }
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
342
19348
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
343 private void avoidFindbugsProblems(CodeTypeElement clazz) {
21978
844d6d053d1b added local SuppressFBWarnings annotation
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
344 TypeElement type = context.getEnvironment().getElementUtils().getTypeElement(SuppressFBWarnings.class.getName());
19348
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
345 boolean foundComparison = false;
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
346 outer: for (SpecializationData specialization : node.getSpecializations()) {
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
347 for (GuardExpression guard : specialization.getGuards()) {
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
348 if (guard.getExpression().containsComparisons()) {
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
349 foundComparison = true;
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
350 break outer;
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
351 }
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
352 }
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
353 }
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
354
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
355 if (foundComparison) {
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
356 CodeAnnotationMirror annotation = new CodeAnnotationMirror((DeclaredType) type.asType());
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
357 annotation.setElementValue(annotation.findExecutableElement("value"), new CodeAnnotationValue("SA_LOCAL_SELF_COMPARISON"));
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
358 clazz.addAnnotationMirror(annotation);
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
359 }
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
360 }
ef292a5bb79d Truffle-DSL: fix findbugs comparison warnings.
Christian Humer <christian.humer@gmail.com>
parents: 19303
diff changeset
361
21879
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
362 private void addUnsupportedMethod(CodeTypeElement clazz) {
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
363 CodeVariableElement seenUnsupportedField = new CodeVariableElement(modifiers(PRIVATE), getType(boolean.class), "seenUnsupported0");
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
364 seenUnsupportedField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class)));
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
365 clazz.add(seenUnsupportedField);
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
366 LocalContext locals = LocalContext.load(this);
21879
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
367 CodeExecutableElement method = locals.createMethod(modifiers(PRIVATE), getType(UnsupportedSpecializationException.class), "unsupported", varArgsThreshold);
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
368 CodeTreeBuilder builder = method.createBuilder();
21879
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
369 builder.startIf().string("!").string(seenUnsupportedField.getName()).end().startBlock();
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
370 builder.startStatement().startStaticCall(getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end();
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
371 builder.startStatement().string(seenUnsupportedField.getName()).string(" = true").end();
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
372 builder.end();
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
373
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
374 builder.startReturn();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
375 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
376 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
377 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
378 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
379 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
380 builder.end();
21879
90fd69243227 Truffle-DSL: speculate using a compilation final boolean that the unsupported branch is not taken for single specializable nodes.
Christian Humer <christian.humer@gmail.com>
parents: 21877
diff changeset
381 clazz.add(method);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384 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
385 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
386 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
387
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 List<CodeVariableElement> childParameters = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
391 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 constructor.getParameters().addAll(superConstructor.getParameters().size(), childParameters);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
394 CodeTreeBuilder builder = constructor.appendBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
395 List<String> childValues = new ArrayList<>(node.getChildren().size());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 for (NodeChildData child : node.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397 String name = child.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 CreateCastData createCast = node.findCast(child.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400 if (createCast != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 CodeTree nameTree = CodeTreeBuilder.singleString(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 CodeTreeBuilder callBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 callBuilder.string(name).string(" != null ? ");
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
404 callBuilder.tree(callMethod(null, createCast.getMethod(), nameTree));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405 callBuilder.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 name += "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407 builder.declaration(child.getNodeType(), name, callBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410 childValues.add(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 for (NodeExecutionData execution : node.getChildExecutions()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
414 if (execution.getChild() == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
415 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
416 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417 CreateCastData createCast = node.findCast(execution.getChild().getName());
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 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420 builder.string("this.").string(nodeFieldName(execution)).string(" = ");
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 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
423 CodeTreeBuilder accessorBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 accessorBuilder.string(name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
426 if (execution.isIndexed()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
427 accessorBuilder.string("[").string(String.valueOf(execution.getChildIndex())).string("]");
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
428 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430 CodeTree accessor = accessorBuilder.build();
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 (createCast != null && execution.getChild().getCardinality().isOne()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
433 accessor = callMethod(null, createCast.getMethod(), accessor);
18761
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436 if (execution.isIndexed()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 CodeTreeBuilder nullCheck = builder.create();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
438 nullCheck.string(name).string(" != null && ").string(String.valueOf(execution.getChildIndex())).string(" < ").string(name).string(".length").string(" ? ");
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 nullCheck.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440 nullCheck.string(" : null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 accessor = nullCheck.build();
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 builder.tree(accessor);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446 builder.end();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
449 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
451
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
452 private static boolean mayBeExcluded(SpecializationData specialization) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453 return !specialization.getExceptions().isEmpty() || !specialization.getExcludedBy().isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
456 private SpecializationData createSpecializations(CodeTypeElement clazz) {
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
457 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
458 TypeMirror baseSpecializationType = baseSpecialization.asType();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
460 Map<SpecializationData, CodeTypeElement> generated = new LinkedHashMap<>();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
462 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
463 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
464 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
465 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
466 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
467 generateSpecializations.addAll(reachableSpecializations);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
468
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
469 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
470 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
471 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472
20951
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
473 baseSpecialization.addOptional(createCreateNext(generated));
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
474 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
475 baseSpecialization.addOptional(createCreatePolymorphic(generated));
20951
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
476 baseSpecialization.addOptional(createGetNext(baseSpecialization));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
477
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
478 for (NodeExecutionData execution : node.getChildExecutions()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
479 Collection<TypeMirror> specializedTypes = node.findSpecializedTypes(execution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
480 specializedTypes.add(genericType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
481 for (TypeMirror specializedType : specializedTypes) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
482 if (isExecuteChildShared(execution, specializedType)) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
483 baseSpecialization.addOptional(createExecuteChildMethod(execution, specializedType));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
484 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
485 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
486 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
487
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
488 return node.getUninitializedSpecialization();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
491 private boolean needsPolymorphic() {
21065
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
492 int signatureSize = node.getSignatureSize();
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
493 boolean allEvaluated = true;
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
494 for (ExecutableTypeData type : usedTypes) {
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
495 if (type.getEvaluatedCount() != signatureSize) {
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
496 allEvaluated = false;
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
497 }
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
498 }
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
499 if (allEvaluated) {
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
500 return false;
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
501 }
986f1c0d6f55 Truffle-DSL: do not generate polymorphic nodes for nodes with all parameters evaluated in all execute methods.
Christian Humer <christian.humer@oracle.com>
parents: 20999
diff changeset
502
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
503 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
504 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
505 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
506
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
507 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
508 for (Parameter parameter : specialization.getSignatureParameters()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
509 TypeMirror type = parameter.getType();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
510 if (type != null && typeSystem.hasImplicitSourceTypes(type)) {
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 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
512 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
513 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
514 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
515 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
516 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
517 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
518
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
519 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
520
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
523 private CodeTypeElement createBaseSpecialization() {
20949
9a83732f97eb Truffle-DSL: ensure proper wildcards for generics are filled in; remove unused type system node code generator.
Christian Humer <christian.humer@gmail.com>
parents: 20948
diff changeset
524 CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, ABSTRACT, STATIC), specializationTypeName(null), typeSystem.getContext().getType(SpecializationNode.class));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 clazz.addOptional(createSpecializationConstructor(clazz, null, null));
22508
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
527 CodeVariableElement rootField = new CodeVariableElement(modifiers(PROTECTED), nodeType(node), "root");
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
528 rootField.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class)));
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
529 clazz.add(rootField);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531 clazz.addOptional(createUnsupported());
22508
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
532 clazz.add(createSetRootMethod());
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
533 clazz.add(createGetSuppliedChildrenMethod());
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
534 clazz.add(createAcceptAndExecute());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
535
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
536 for (ExecutableTypeData type : usedTypes) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
537 clazz.add(createFastPathExecuteMethod(null, type, usedTypes));
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 clazz;
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
22508
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
543 private Element createSetRootMethod() {
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
544 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), context.getType(void.class), "setRoot", new CodeVariableElement(getType(Node.class), "root"));
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
545 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
546
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
547 CodeTreeBuilder builder = method.createBuilder();
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
548 builder.startStatement().string("this.root = ").cast(ElementUtils.fillInGenericWildcards(nodeType(node))).string("root").end();
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
549
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
550 return method;
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
551 }
a619835e6709 SpecializationNode refactoring: update root field through generated setter
Andreas Woess <andreas.woess@oracle.com>
parents: 22157
diff changeset
552
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
553 private Element createAcceptAndExecute() {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
554 ExecutableTypeData executableElement = createSpecializationNodeSignature(node.getSignatureSize());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
555 LocalContext currentLocals = LocalContext.load(this, executableElement, varArgsThreshold);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
556 CodeExecutableElement executable = createExecuteMethod(null, executableElement, currentLocals, false, varArgsThreshold);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
557
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
558 executable.getModifiers().add(FINAL);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
559 CodeTreeBuilder builder = executable.createBuilder();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
560
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
561 CodeTree receiver = CodeTreeBuilder.singleString("this");
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
562
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
563 builder.tree(createCallDelegateExecute(builder, receiver, currentLocals, executableElement, node.getGenericExecutableType(null)));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
564
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
565 return executable;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
566 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
567
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
568 private ExecutableTypeData createSpecializationNodeSignature(int argumentCount) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
569 TypeMirror[] parameters = new TypeMirror[argumentCount];
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
570 Arrays.fill(parameters, genericType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
571 return new ExecutableTypeData(node, genericType, "acceptAndExecute", context.getType(Frame.class), Arrays.asList(parameters));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
572 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
573
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
574 private boolean shouldImplementExecutableType(SpecializationData specialization, ExecutableTypeData executableType) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
575 // always implement the root execute method. they are declared abstract in the base node.
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
576 if (executableType.getDelegatedTo() == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
577 return true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
578 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
579
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
580 // specializations with more parameters are just ignored
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
581 if (executableType.getEvaluatedCount() > node.getExecutionCount()) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
582 return false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
583 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
584
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
585 if (!isSubtypeBoxed(context, specialization.getReturnType().getType(), executableType.getReturnType())) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
586 return false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
587 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
588
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
589 // the evaluated signature might be compatible to the specialization
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
590 boolean specializationCompatible = true;
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
591 List<TypeMirror> signatureParameters = executableType.getSignatureParameters();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
592 for (int i = 0; i < signatureParameters.size(); i++) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
593 TypeMirror evaluatedType = signatureParameters.get(i);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
594 TypeMirror specializedType = specialization.findParameterOrDie(node.getChildExecutions().get(i)).getType();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
595
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
596 if (!isSubtypeBoxed(context, evaluatedType, specializedType) && !isSubtypeBoxed(context, specializedType, evaluatedType)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
597 specializationCompatible = false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
598 break;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
599 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
600 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
601 if (!specializationCompatible) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
602 return false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
603 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
604
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
605 // possibly trigger void optimization for a specialization if it is enabled
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
606 if (isVoid(executableType.getReturnType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
607 if (isTypeBoxingOptimized(options.voidBoxingOptimization(), specialization.getReturnType().getType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
608 return true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
609 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
610 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
611
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
612 // trigger type boxing elimination for unevaluated arguments
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
613 for (int i = executableType.getEvaluatedCount(); i < node.getExecutionCount(); i++) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
614 NodeExecutionData execution = node.getChildExecutions().get(i);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
615 TypeMirror specializedType = specialization.findParameterOrDie(execution).getType();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
616 if (isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), specializedType)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
617 // it does not make sense to do type boxing elimination for children with
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
618 // no type specialized execute method
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
619 if (execution.getChild() != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
620 ExecutableTypeData executedType = execution.getChild().findExecutableType(specializedType);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
621 if (executedType != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
622 return true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
623 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
624 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
625 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
626 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
627
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
628 // trigger type boxing elimination for return types
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
629 if (typeEquals(executableType.getReturnType(), specialization.getReturnType().getType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
630 if (isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), executableType.getReturnType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
631 return true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
632 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
633 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
634
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
635 // trigger generation for evaluated assignable type matches other than generic
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
636 for (int i = 0; i < signatureParameters.size(); i++) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
637 TypeMirror evaluatedType = signatureParameters.get(i);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
638 NodeExecutionData execution = node.getChildExecutions().get(i);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
639 TypeMirror specializedType = specialization.findParameterOrDie(execution).getType();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
640
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
641 if (isSubtypeBoxed(context, evaluatedType, specializedType) && !isObject(specializedType)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
642 return true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
643 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
644 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
645
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
646 return false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
647 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
648
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
649 private List<ExecutableTypeData> filterBaseExecutableTypes(List<ExecutableTypeData> executableTypes, List<SpecializationData> specializations) {
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
650 Set<TypeMirror> returnTypes = new HashSet<>();
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
651 for (SpecializationData specialization : node.getSpecializations()) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
652 returnTypes.add(specialization.getReturnType().getType());
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
653 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
654
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
655 List<ExecutableTypeData> prefilteredTypes = new ArrayList<>();
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
656 for (ExecutableTypeData type : executableTypes) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
657 if (type.getDelegatedTo() == null || shouldAlwaysImplementExecutableType(type)) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
658 prefilteredTypes.add(type);
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
659 } else {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
660 boolean foundSubtype = false;
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
661 for (TypeMirror returnType : returnTypes) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
662 if (isSubtypeBoxed(context, returnType, type.getReturnType())) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
663 foundSubtype = true;
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
664 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
665 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
666 if (foundSubtype) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
667 prefilteredTypes.add(type);
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
668 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
669 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
670 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
671
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
672 Set<ExecutableTypeData> types = new HashSet<>();
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
673 type: for (ExecutableTypeData type : prefilteredTypes) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
674 for (SpecializationData specialization : specializations) {
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
675 if (shouldImplementExecutableType(specialization, type) || shouldAlwaysImplementExecutableType(type)) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
676 types.add(type);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
677 continue type;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
678 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
679 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
680 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
681 Set<ExecutableTypeData> delegatesToAdd = new HashSet<>();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
682 do {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
683 delegatesToAdd.clear();
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
684 for (ExecutableTypeData type : types) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
685 ExecutableTypeData delegate = type.getDelegatedTo();
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
686 if (delegate != null && !types.contains(delegate)) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
687 delegatesToAdd.add(delegate);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
688 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
689 }
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
690 types.addAll(delegatesToAdd);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
691 } while (!delegatesToAdd.isEmpty());
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
692 List<ExecutableTypeData> newUsedTypes = new ArrayList<>(types);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
693 Collections.sort(newUsedTypes);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
694 return newUsedTypes;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
695 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
696
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
697 private boolean shouldAlwaysImplementExecutableType(ExecutableTypeData type) {
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
698 return type.isAbstract() || !(type.hasUnexpectedValue(context) && type.getMethod() != null);
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
699 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
700
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 private CodeTypeElement createSpecialization(SpecializationData specialization, TypeMirror baseType) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702 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
703
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 CodeExecutableElement constructor = clazz.addOptional(createSpecializationConstructor(clazz, specialization, null));
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 for (Parameter p : specialization.getSignatureParameters()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
707 TypeMirror targetType = p.getType();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
708 if (typeSystem.hasImplicitSourceTypes(targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709 NodeExecutionData execution = p.getSpecification().getExecution();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
710 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
712 implicitProfile.getModifiers().add(PRIVATE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 implicitProfile.getModifiers().add(FINAL);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 clazz.add(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
715 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
716 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
717 }
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 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720 clazz.add(createFallbackGuardMethod());
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 clazz.addOptional(createSpecializationCreateMethod(specialization, constructor));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 clazz.addOptional(createMergeMethod(specialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725 clazz.addOptional(createIsSameMethod(specialization));
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
726 clazz.addOptional(createIsIdenticalMethod(specialization));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
728 // get types that should get implemented
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
729 List<ExecutableTypeData> types = new ArrayList<>();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
730 for (ExecutableTypeData type : node.getExecutableTypes()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
731 if (shouldImplementExecutableType(specialization, type)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
732 types.add(type);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
734 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
735 for (ExecutableTypeData type : types) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
736 clazz.add(createFastPathExecuteMethod(specialization, type, types));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
737 }
18761
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 return clazz;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
740 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
741
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
742 public static List<Parameter> getDynamicParameters(TemplateMethod method) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
743 List<Parameter> parameters = new ArrayList<>();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
744 for (Parameter param : method.getReturnTypeAndParameters()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
745 if (param.getSpecification().isLocal()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
746 // ignore parameters passed by locals
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
747 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
748 } else if (param.getVariableElement() != null && param.getVariableElement().getAnnotation(Cached.class) != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
749 // ignore cached parameters
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
750 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
751 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
752 parameters.add(param);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
753 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
754 return parameters;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
755 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
756
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
757 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
758 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
759 return null;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
760 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 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
762 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
763 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
764 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
765 return executable;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768 private Element createGetCostMethod() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
769 TypeMirror returnType = getType(NodeCost.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 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
772 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
773 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
774 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
775 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
776 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
777 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
778 return executable;
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
779
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
782 private Element createIsIdenticalMethod(SpecializationData specialization) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
783 boolean cacheBoundGuard = specialization.hasMultipleInstances();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
784 if (!cacheBoundGuard) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
785 return null;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
786 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
787
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
788 LocalContext currentLocals = LocalContext.load(this, createSpecializationNodeSignature(node.getSignatureSize()), varArgsThreshold);
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
789 currentLocals.loadFastPathState(specialization);
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
790
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
791 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(boolean.class), "isIdentical");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
792 method.addParameter(new CodeVariableElement(getType(SpecializationNode.class), "other"));
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
793 currentLocals.addParametersTo(method, varArgsThreshold, FRAME_VALUE);
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
794 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
795 final CodeTreeBuilder builder = method.createBuilder();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
796
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
797 SpecializationGroup group = SpecializationGroup.create(specialization);
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
798 SpecializationBody executionFactory = new SpecializationBody(true, false) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
799 @Override
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
800 public CodeTree createBody(SpecializationData s, LocalContext values) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
801 return builder.create().returnTrue().build();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
802 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
803 };
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
804
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
805 builder.tree(createGuardAndCast(group, genericType, currentLocals, executionFactory));
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
806 builder.returnFalse();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
807 return method;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
808 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
809
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 private CodeExecutableElement createIsSameMethod(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 if (!specialization.isSpecialized() || !options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815 List<CodeVariableElement> profiles = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 for (Parameter parameter : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
818 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
820 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
821 CodeVariableElement var = createImplicitProfileParameter(execution, parameter.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
822 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
823 profiles.add(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
824 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
825 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 if (profiles.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
831 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
832 method.addParameter(new CodeVariableElement(getType(SpecializationNode.class), "other"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 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
834 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837 builder.string("super.isSame(other)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
838
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839 for (CodeVariableElement profile : profiles) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 builder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 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
842 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 private Element createMergeMethod(SpecializationData specialization) {
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
849 if (specialization.getExcludedBy().isEmpty() && !specialization.isPolymorphic()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 TypeMirror specializationNodeType = getType(SpecializationNode.class);
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
853 LocalContext currentLocals = LocalContext.load(this, createSpecializationNodeSignature(node.getSignatureSize()), varArgsThreshold);
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
854
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), specializationNodeType, "merge");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 executable.addParameter(new CodeVariableElement(specializationNodeType, "newNode"));
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
857 currentLocals.addParametersTo(executable, varArgsThreshold, FRAME_VALUE);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 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
859 CodeTreeBuilder builder = executable.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 if (specialization.isPolymorphic()) {
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
862 builder.startReturn();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
863 builder.startCall("polymorphicMerge");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
864 builder.string("newNode");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
865 builder.startCall("super", "merge");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
866 builder.string("newNode");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
867 currentLocals.addReferencesTo(builder, FRAME_VALUE);
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
868 builder.end();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
869 builder.end();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
870 builder.end();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
871
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
872 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874 for (SpecializationData containedSpecialization : specialization.getExcludedBy()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875 elseIf = builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
876 builder.string("newNode.getClass() == ").typeLiteral(specializationType(containedSpecialization));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
879 builder.statement("removeSame(\"Contained by " + containedSpecialization.createReferenceName() + "\")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
881 }
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
882 builder.startReturn();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
883 builder.startCall("super", "merge");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
884 builder.string("newNode");
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
885 currentLocals.addReferencesTo(builder, FRAME_VALUE);
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
886 builder.end();
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
887 builder.end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
888 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
892
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
893 private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
894 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
895 if (fallback == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
896 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
897 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898 CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
900 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
901 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
902
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
903 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
904 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
905 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
906 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
907 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
908 }
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 private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
911 SpecializationData polymorphic = node.getPolymorphicSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
912 CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 if (generatedPolymorphic == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
915 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 TypeMirror returnType = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917 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
918 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
919 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
920 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
922
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 private CodeExecutableElement createCreateNext(final Map<SpecializationData, CodeTypeElement> specializationClasses) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
924 final LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
925
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
926 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), getType(SpecializationNode.class), "createNext", varArgsThreshold, FRAME_VALUE);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
927 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
928
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
930 SpecializationGroup group = createSpecializationGroups();
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
931 CodeTree execution = createGuardAndCast(group, genericType, locals, new SpecializationBody(false, false) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
932 @Override
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
933 public CodeTree createBody(SpecializationData specialization, LocalContext values) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
934 CodeTypeElement generatedType = specializationClasses.get(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
935 if (generatedType == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 throw new AssertionError("No generated type for " + specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
937 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
938 return createSlowPathExecute(specialization, values);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
939 }
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 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
944 if (hasFallthrough(group, genericType, locals, false, null)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945 builder.returnNull();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
947 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
948 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
949
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
950 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
951 boolean frameUsed = node.isFrameUsedByAnyGuard();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
952 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
955 locals.removeValue(FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
956 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
958 CodeExecutableElement boundaryMethod = locals.createMethod(modifiers(PRIVATE), getType(boolean.class), "guardFallback", varArgsThreshold, FRAME_VALUE);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
959 if (!frameUsed) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 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
961 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
962
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
963 CodeTreeBuilder builder = boundaryMethod.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
964 builder.startReturn();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
965 builder.startCall("createNext");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
966 locals.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968 builder.string(" == null");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
969 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
970 return boundaryMethod;
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
973 private ExecutableElement createAccessChildMethod(NodeChildData child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 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
975 ExecutableElement getter = (ExecutableElement) child.getAccessElement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
976 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), getter);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
977 method.getModifiers().remove(Modifier.ABSTRACT);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
978
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979 List<NodeExecutionData> executions = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 for (NodeExecutionData execution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 if (execution.getChild() == child) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
982 executions.add(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
983 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
984 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
985
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
987 if (child.getCardinality().isMany()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
988 builder.startReturn().startNewArray((ArrayType) child.getOriginalType(), null);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
989 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
990 builder.string(nodeFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
991 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
993 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
994 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
995 builder.startReturn().string("this.").string(nodeFieldName(execution)).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
997 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
998 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
999 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1000 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1002 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004 private Element createUnsupported() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1005 SpecializationData fallback = node.getGenericSpecialization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006 if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1007 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1008 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1009 LocalContext locals = LocalContext.load(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1010
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1011 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), genericType, "unsupported", varArgsThreshold, FRAME_VALUE);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1012 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
1013
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1014 CodeTreeBuilder builder = method.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1015 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
1016 builder.tree(callTemplateMethod(accessParent(null), fallback, locals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1017 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1018
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1021
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
1022 private boolean isSingleSpecializableImpl() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1023 if (reachableSpecializations.size() != 1) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1024 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1025 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1026
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1027 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
1028
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1029 for (Parameter parameter : specialization.getSignatureParameters()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1030 TypeMirror type = parameter.getType();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1031 if (type != null && typeSystem.hasImplicitSourceTypes(type)) {
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
1032 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
1033 }
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
1034 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1035
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1036 if (!specialization.getAssumptionExpressions().isEmpty()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1037 return false;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1038 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1039
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1040 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
1041 // 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
1042 // 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
1043 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
1044 }
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
1045 return true;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1046 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1047
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1048 private List<SpecializationData> calculateReachableSpecializations() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1049 List<SpecializationData> specializations = new ArrayList<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1050 for (SpecializationData specialization : node.getSpecializations()) {
22003
5bc7f7b867ab Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21978
diff changeset
1051 if (specialization.isReachable() && //
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1052 (specialization.isSpecialized() //
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1053 || (specialization.isFallback() && optimizeFallback(specialization)))) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1054 specializations.add(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1055 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1056 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1057 return specializations;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1058 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1059
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1060 private boolean optimizeFallback(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1061 switch (options.optimizeFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1062 case NEVER:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1063 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1064 case DECLARED:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1065 return specialization.getMethod() != null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1066 case ALWAYS:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1067 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1068 default:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1069 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1070 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1071 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1072
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1073 private CodeExecutableElement createExecutableTypeOverride(List<ExecutableTypeData> usedExecutables, ExecutableTypeData execType) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1074 LocalContext locals = LocalContext.load(this, execType, Integer.MAX_VALUE);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1075 CodeExecutableElement method = createExecuteMethod(null, execType, locals, true, Integer.MAX_VALUE);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1076
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1077 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
1078 if (singleSpecializable) {
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1079 SpecializationData specialization = reachableSpecializations.iterator().next();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1080 builder.tree(createFastPath(builder, specialization, execType, usedExecutables, locals));
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1081 } else {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1082 // create acceptAndExecute
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1083 ExecutableTypeData delegate = execType;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1084 CodeTree receiver = CodeTreeBuilder.singleString(specializationStartFieldName());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1085 builder.tree(createCallDelegateExecute(builder, receiver, locals, execType, delegate));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1086 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1087 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1088 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1089
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1090 private Element createMethodGetSpecializationNode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1091 TypeMirror returntype = getType(SpecializationNode.class);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1092 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returntype, "getSpecializationNode");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1093 method.createBuilder().startReturn().string(specializationStartFieldName()).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1094 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1095 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1096
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1097 private TypeMirror getType(Class<?> clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1098 return context.getType(clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1099 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1100
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1101 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
1102 CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1103 childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1104 setVisibility(childField.getModifiers(), visibility);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1105 return childField;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1106 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1107
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1108 private static List<ExecutableTypeData> resolveSpecializedExecutables(NodeExecutionData execution, Collection<TypeMirror> types, TypeBoxingOptimization optimization) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1109 if (optimization == TypeBoxingOptimization.NONE) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1110 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
1111 } 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
1112 return Collections.emptyList();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1113 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1114
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 List<ExecutableTypeData> executables = new ArrayList<>();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1116 for (TypeMirror type : types) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 if (!isTypeBoxingOptimized(optimization, type)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1118 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1120 if (execution.getChild() == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1121 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1122 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 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
1124 if (foundType != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 executables.add(foundType);
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1128 return executables;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1131 private static CodeTree callMethod(CodeTree receiver, ExecutableElement method, CodeTree... boundValues) {
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
1132 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1133 if (method.getModifiers().contains(STATIC)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1134 builder.startStaticCall(method.getEnclosingElement().asType(), method.getSimpleName().toString());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1135 } else {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1136 builder.startCall(receiver, method.getSimpleName().toString());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1137 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1138 int index = -1;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1139 for (VariableElement parameter : method.getParameters()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1140 index++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1141 if (index < boundValues.length) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1142 CodeTree tree = boundValues[index];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1143 if (tree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1144 builder.tree(tree);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1145 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1146 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1147 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1148
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1149 builder.defaultValue(parameter.asType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1150 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1151 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1152 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1153 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1155 private CodeTree[] bindExecuteMethodParameters(NodeExecutionData execution, ExecutableTypeData method, LocalContext currentValues) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1156 List<NodeExecutionData> executeWith = execution != null ? execution.getChild().getExecuteWith() : null;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1157
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1158 List<CodeTree> values = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1159 if (method.getFrameParameter() != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1160 LocalVariable frameLocal = currentValues.get(FRAME_VALUE);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1161 if (frameLocal == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1162 values.add(CodeTreeBuilder.singleString("null"));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1163 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1164 values.add(createTypeSafeReference(frameLocal, method.getFrameParameter()));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1165 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1166 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1167
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1168 int evaluatedIndex = 0;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1169 for (int executionIndex = 0; executionIndex < node.getExecutionCount(); executionIndex++) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1170 NodeExecutionData parameterExecution;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1171 if (executeWith != null && executionIndex < executeWith.size()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1172 parameterExecution = executeWith.get(executionIndex);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1173 } else {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1174 parameterExecution = node.getChildExecutions().get(executionIndex);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1175 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1176 if (parameterExecution.isShortCircuit()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1177 if (evaluatedIndex < method.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1178 TypeMirror targetType = method.getEvaluatedParameters().get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1179 LocalVariable shortCircuit = currentValues.getShortCircuit(parameterExecution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1180 if (shortCircuit != null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1181 values.add(createTypeSafeReference(shortCircuit, targetType));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1182 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1183 values.add(CodeTreeBuilder.createBuilder().defaultValue(targetType).build());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1184 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1185 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1186 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1187 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1188 if (evaluatedIndex < method.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1189 TypeMirror targetType = method.getEvaluatedParameters().get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1190 LocalVariable value = currentValues.getValue(parameterExecution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1191 if (value != null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1192 values.add(createTypeSafeReference(value, targetType));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1193 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1194 values.add(CodeTreeBuilder.createBuilder().defaultValue(targetType).build());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1195 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1196 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1197 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1198 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1199 return values.toArray(new CodeTree[values.size()]);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1200 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1201
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1202 private CodeTree callExecuteMethod(NodeExecutionData execution, ExecutableTypeData method, LocalContext currentValues) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1203 CodeTree receiver = execution != null ? accessParent(nodeFieldName(execution)) : null;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1204 return callMethod(receiver, method.getMethod(), bindExecuteMethodParameters(execution, method, currentValues));
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1205 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1206
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1207 private 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
1208 CodeTree[] bindings = new CodeTree[method.getParameters().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1209
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1210 int signatureIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1211 for (int i = 0; i < bindings.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 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
1213
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1214 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
1215 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
1216 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
1217 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1218
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1219 if (var != null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1220 bindings[i] = createTypeSafeReference(var, parameter.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1221 }
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
1222
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1223 if (parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1224 signatureIndex++;
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 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1227 return callMethod(receiver, method.getMethod(), bindings);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1228 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1229
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1230 private CodeTree createTypeSafeReference(LocalVariable var, TypeMirror targetType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1231 CodeTree valueReference = var.createReference();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1232 TypeMirror sourceType = var.getTypeMirror();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1233 if (targetType == null || sourceType == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1234 return valueReference;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1235 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1236 if (needsCastTo(sourceType, targetType)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1237 valueReference = TypeSystemCodeGenerator.cast(typeSystem, targetType, valueReference);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1238 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1239 return valueReference;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1240 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 private SpecializationGroup createSpecializationGroups() {
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1243 return SpecializationGroup.create(reachableSpecializations);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244 }
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 private CodeTree createSlowPathExecute(SpecializationData specialization, LocalContext currentValues) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1248 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249 return builder.returnNull().build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1251
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
1252 if (node.isFrameUsedByAnyGuard()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1253 builder.tree(createTransferToInterpreterAndInvalidate());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1254 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1255
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
1256 // 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
1257 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
1258 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
1259 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
1260 }
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
1261 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1262 boolean hasAssumptions = !specialization.getAssumptionExpressions().isEmpty();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1263 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
1264
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1265 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1266 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
1267 castBoundTypes(bindExpressionValues(assumption.getExpression(), specialization, currentValues)));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1268 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1269 // 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
1270 String varName = name + specialization.getIndex();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1271 TypeMirror type = assumption.getExpression().getResolvedType();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1272 builder.declaration(type, varName, assumptions);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1273 currentValues.set(name, new LocalVariable(type, varName, null, null));
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1274 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1275
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1276 builder.startIf();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1277 String sep = "";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1278 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1279 LocalVariable assumptionVar = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1280 if (assumptionVar == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1281 throw new AssertionError("assumption var not resolved");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1282 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1283 builder.string(sep);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1284 builder.startCall("isValid").tree(assumptionVar.createReference()).end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1285 sep = " && ";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1286 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1287 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1288 builder.startBlock();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1289 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1290
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1291 for (SpecializationData otherSpeciailzation : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1292 if (otherSpeciailzation == specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1295 if (otherSpeciailzation.getExcludedBy().contains(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1296 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 builder.tree(accessParent(excludedFieldName(otherSpeciailzation)));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1298 builder.string(" = true");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1299 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1302
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1303 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
1304
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1305 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
1306 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
1307 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
1308 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
1309 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
1310 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
1311 } else {
22003
5bc7f7b867ab Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21978
diff changeset
1312 limitExpressionTree = DSLExpressionGenerator.write(limitExpression, accessParent(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
1313 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
1314 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1315
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1316 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
1317 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
1318 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
1319 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1320 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
1321 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1322
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1323 if (hasAssumptions) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1324 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1325 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1326
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1327 if (mayBeExcluded(specialization)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1328 CodeTreeBuilder checkHasSeenBuilder = builder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1329 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
1330 checkHasSeenBuilder.tree(builder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1331 checkHasSeenBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1332 return checkHasSeenBuilder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1333 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1334 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1335 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1336
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1337 private boolean hasFallthrough(SpecializationGroup group, TypeMirror 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
1338 for (TypeGuard guard : group.getTypeGuards()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1339 if (currentValues.getValue(guard.getSignatureIndex()) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1340 // not evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1341 return true;
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 LocalVariable value = currentValues.getValue(guard.getSignatureIndex());
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1344 if (needsCastTo(value.getTypeMirror(), guard.getType())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1345 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1346 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1347 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1348
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1349 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
1350 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
1351 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
1352 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
1353 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
1354 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1355 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
1356 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
1357 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
1358 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
1359 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
1360 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
1361 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1362 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1363 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1364
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1365 if (!guards.isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1366 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1367 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1368
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1369 if (!fastPath && specialization != null && !specialization.getAssumptionExpressions().isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1370 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1371 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1372
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1373 if (!fastPath && specialization != null && mayBeExcluded(specialization)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1374 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1375 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1376
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1377 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
1378 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
1379 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
1380 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
1381 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1382 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1383
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1384 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
1385 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
1386 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
1387 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1388
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1389 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1390 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1391
20951
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
1392 private Element createGetNext(CodeTypeElement type) {
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
1393 if (!nextUsed) {
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
1394 return null;
a77b760a0307 Truffle-DSL: fixed on-demand generation of getNext.
Christian Humer <christian.humer@gmail.com>
parents: 20949
diff changeset
1395 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1396 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), type.asType(), "getNext");
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1397 CodeTreeBuilder builder = method.createBuilder();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1398 builder.startReturn().cast(type.asType(), CodeTreeBuilder.singleString("this.next")).end();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1399 return method;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1400 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1401
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1402 private Element createGetSuppliedChildrenMethod() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1403 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
1404
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1405 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
1406 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
1407
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1408 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
1409 builder.startReturn().tree(createGetSuppliedChildren()).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1410
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1411 return method;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1412 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1413
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1414 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
1415 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
1416 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
1417 builder.startNewArray(nodeArray, null);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1418 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
1419 NodeExecutionData execution = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1420 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1421 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1422 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1423 if (execution.getChild() == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1424 builder.nullLiteral();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1425 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1426 builder.tree(accessParent(nodeFieldName(execution)));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1427 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1428 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1429 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1430 return builder.build();
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 // create specialization
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1434
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1435 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
1436 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
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 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
1439 if (useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1440 builder.startStaticCall(specializationType(specialization), "create");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1441 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1442 builder.startNew(specializationType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1443 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1444 if (rootName != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1445 builder.string(rootName);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1446 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1447 builder.string("root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1448 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1449 if (currentValues != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1450 for (Parameter p : specialization.getSignatureParameters()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1451 CodeVariableElement var = createImplicitProfileParameter(p.getSpecification().getExecution(), p.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1452 if (var != null) {
19704
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
1453 LocalVariable variable = currentValues.get(p.getLocalName());
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
1454 if (variable == null) {
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
1455 throw new AssertionError("Could not bind cached value " + p.getLocalName() + ": " + currentValues);
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
1456 }
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
1457 builder.tree(variable.original().createReference());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1458 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1459 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1460 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
1461 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
1462 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
1463 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
1464 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1465 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
1466 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1467 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1468 LocalVariable variable = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1469 if (variable == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1470 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
1471 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1472 builder.tree(variable.createReference());
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1473 }
18761
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 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1476
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1477 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1478 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1479
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1480 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
1481 if (!useLazyClassLoading()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1482 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1483 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1484
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1485 CodeExecutableElement 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
1486 executable.setReturnType(specializationType(null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1487 executable.setSimpleName(CodeNames.of("create"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1488 executable.getModifiers().add(STATIC);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1489
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1490 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
1491 builder.startReturn().startNew(specializationType(specialization));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1492 for (VariableElement parameter : executable.getParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1493 builder.string(parameter.getSimpleName().toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1494 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1495 builder.end().end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1496 return executable;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1497 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1498
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
1499 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
1500 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
1501 }
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
1502
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1503 private static String implicitClassFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1504 return execution.getName() + "ImplicitType";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1505 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1506
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1507 private static String implicitNodeFieldName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1508 return execution.getName() + "Cast";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1509 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1510
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1511 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
1512 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
1513
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1514 constructor.addParameter(new CodeVariableElement(nodeType(node), "root"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1515 CodeTreeBuilder builder = constructor.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1516
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1517 if (specialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1518 if (constantIndex == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1519 builder.statement("super(index)");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1520 constructor.addParameter(new CodeVariableElement(getType(int.class), "index"));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1521 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1522 builder.startStatement().startSuperCall().string(constantIndex).end().end();
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 builder.statement("this.root = root");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1525 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1526 int index = resolveSpecializationIndex(specialization);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1527 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
1528
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1529 for (Parameter p : specialization.getSignatureParameters()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1530 NodeExecutionData execution = p.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1531
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1532 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, p.getType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1533 if (implicitProfile != null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1534 LocalVariable var = LocalVariable.fromParameter(p).makeGeneric(context);
18761
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 String implicitFieldName = implicitProfile.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1537 if (options.implicitCastOptimization().isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1538 constructor.addParameter(var.createParameter());
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1539 CodeTree implicitType = TypeSystemCodeGenerator.implicitType(typeSystem, p.getType(), var.createReference());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1540 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
1541 } else if (options.implicitCastOptimization().isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1542 // use node that supports polymorphism
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1543 constructor.addParameter(var.createParameter());
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1544 builder.startStatement().string("this.").string(implicitFieldName).string(" = ").tree(ImplicitCastNodeFactory.create(typeSystem, p.getType(), var.createReference())).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1545 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1546 throw new AssertionError();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1547 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1548 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1549 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1550 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
1551 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
1552 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
1553
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1554 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
1555 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
1556 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
1557 } 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
1558 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
1559 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
1560 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1561 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
1562 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1563 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
1564 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
1565 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1566
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1567 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1568 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1569 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
1570 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
1571 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
1572 constructor.addParameter(new CodeVariableElement(type, name));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1573 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
1574 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1575 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1576
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1577 if (constructor.getParameters().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1578 // do not generate default constructor
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1579 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1580 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1581 return constructor;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1582 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1583
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1584 // 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
1585 private static int resolveSpecializationIndex(SpecializationData specialization) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1586 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1587 return Integer.MAX_VALUE - 1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1588 } else if (specialization.isUninitialized()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1589 return Integer.MAX_VALUE;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1590 } else if (specialization.isPolymorphic()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1591 return 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1592 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1593 return specialization.getIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1594 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1595 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1596
21877
23f0f181bc05 Truffle-DSL: fix unsupported method for single specializable nodes was generated too often.
Christian Humer <christian.humer@gmail.com>
parents: 21077
diff changeset
1597 private CodeTree createThrowUnsupported(LocalContext currentValues) {
23f0f181bc05 Truffle-DSL: fix unsupported method for single specializable nodes was generated too often.
Christian Humer <christian.humer@gmail.com>
parents: 21077
diff changeset
1598 singleSpecializableUnsupportedUsed = true;
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1599 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
1600 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
1601 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
1602 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
1603 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
1604 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1605
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1606 private CodeTree createCallNext(CodeTreeBuilder parent, ExecutableTypeData currentType, ExecutableTypeData callType, 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
1607 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
1608 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
1609 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1610 CodeTreeBuilder callBuilder = parent.create();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1611 callBuilder.tree(createCallDelegateExecute(callBuilder, CodeTreeBuilder.singleString("getNext()"), currentValues, currentType, callType));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1612 nextUsed = true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1613 return callBuilder.build();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1614 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1615
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1616 private CodeTree createCallRemove(String reason, ExecutableTypeData 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
1617 if (singleSpecializable) {
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1618 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
1619 }
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
1620 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
1621 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
1622 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
1623 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
1624 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
1625 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
1626
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1627 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
1628 builder.startReturn();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1629 builder.tree(expectOrCast(genericType, forType, call));
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1630 builder.end();
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1631 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
1632 }
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
1633
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1634 private CodeTree createCallDelegate(String methodName, String reason, ExecutableTypeData forType, LocalContext currentValues) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1635 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1636 builder.startCall(methodName);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1637 if (reason != null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1638 builder.doubleQuote(reason);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1639 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1640 currentValues.addReferencesTo(builder, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1641 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1642
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1643 CodeTree expectOrCast = expectOrCast(genericType, forType, builder.build());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1644 return expectOrCast;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1645 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1646
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1647 private CodeTree expectOrCast(TypeMirror sourceType, ExecutableTypeData targetType, CodeTree content) {
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1648 if (needsUnexpectedResultException(targetType)) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1649 return expect(sourceType, targetType.getReturnType(), content);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1650 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1651 return cast(sourceType, targetType.getReturnType(), content);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1652 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1653 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1654
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1655 private CodeTree cast(TypeMirror sourceType, TypeMirror targetType, CodeTree content) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1656 if (ElementUtils.needsCastTo(sourceType, targetType) && !isVoid(sourceType)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1657 return TypeSystemCodeGenerator.cast(typeSystem, targetType, content);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1658 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1659 return content;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1660 }
18761
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
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1663 private CodeTree expect(TypeMirror sourceType, TypeMirror forType, CodeTree tree) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1664 if (sourceType == null || ElementUtils.needsCastTo(sourceType, forType)) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1665 expectedTypes.add(forType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1666 return TypeSystemCodeGenerator.expect(typeSystem, forType, tree);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1667 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1668 return tree;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1669 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1670
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1671 private Set<ExecutableTypeData> findSpecializedExecutableTypes(NodeExecutionData execution, TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1672 if (execution.getChild() == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1673 return Collections.emptySet();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1674 }
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
1675 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
1676 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
1677 executedTypes.add(executableType);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1678 if (typeSystem.hasImplicitSourceTypes(type)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1679 executedTypes.addAll(resolveSpecializedExecutables(execution, typeSystem.lookupSourceTypes(type), options.implicitTypeBoxingOptimization()));
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
1680 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1681 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
1682 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1683
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1684 private ExecutableTypeData resolveExecutableType(NodeChildData child, TypeMirror type) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1685 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
1686 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
1687 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
1688 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
1689 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
1690 return executableType;
18761
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
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1693 private boolean hasChildUnexpectedResult(NodeExecutionData execution, TypeMirror 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
1694 for (ExecutableTypeData executableType : findSpecializedExecutableTypes(execution, type)) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1695 if (executableType != null && (executableType.hasUnexpectedValue(context) || needsCastTo(executableType.getReturnType(), type))) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1696 return true;
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1699 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1700 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1701
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1702 private Element createFastPathExecuteMethod(SpecializationData specialization, ExecutableTypeData executedType, List<ExecutableTypeData> allTypes) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1703 LocalContext currentLocals = LocalContext.load(this, executedType, Integer.MAX_VALUE);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1704 CodeExecutableElement executable = createExecuteMethod(specialization, executedType, currentLocals, false, Integer.MAX_VALUE);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1705 CodeTreeBuilder builder = executable.createBuilder();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1706 if (specialization == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1707 if (executedType.getDelegatedTo() == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1708 executable.getModifiers().add(ABSTRACT);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1709 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1710 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1711 executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class)));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1712 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1713 builder.tree(createFastPath(builder, specialization, executedType, allTypes, currentLocals));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1714
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1715 return executable;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1716 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1717
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1718 private static final String VARARGS_NAME = "args";
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1719
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1720 private CodeExecutableElement createExecuteMethod(SpecializationData specialization, ExecutableTypeData executedType, LocalContext currentLocals, boolean originalOverride, int varArgs) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1721 TypeMirror returnType = executedType.getReturnType();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1722
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1723 if (specialization != null) {
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1724 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
1725 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
1726
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1727 String methodName;
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1728 if (originalOverride && executedType.getMethod() != null) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1729 methodName = executedType.getMethod().getSimpleName().toString();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1730 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1731 methodName = executedType.getUniqueName();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1732 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1733
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1734 CodeExecutableElement executable;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1735 if (originalOverride && executedType.getMethod() != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1736 executable = CodeExecutableElement.clone(context.getEnvironment(), executedType.getMethod());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1737 executable.getAnnotationMirrors().clear();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1738 executable.getModifiers().remove(ABSTRACT);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1739 for (VariableElement var : executable.getParameters()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1740 ((CodeVariableElement) var).getAnnotationMirrors().clear();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1741 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1742 if (executedType.getFrameParameter() != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1743 ((CodeVariableElement) executable.getParameters().get(0)).setName(FRAME_VALUE);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1744 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1745
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1746 if (executable.isVarArgs()) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1747 ((CodeVariableElement) executable.getParameters().get(executable.getParameters().size() - 1)).setName(VARARGS_NAME);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1748 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1749
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1750 renameOriginalParameters(executedType, executable, currentLocals);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1751 } else {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1752 executable = currentLocals.createMethod(modifiers(PUBLIC), returnType, methodName, varArgs, FRAME_VALUE);
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1753 }
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1754 executable.getThrownTypes().clear();
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1755
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1756 if (needsUnexpectedResultException(executedType)) {
20947
824ef485081f Truffle-DSL: performance optimization for types * specialization complexity in shouldOverrideExecutableType.
Christian Humer <christian.humer@gmail.com>
parents: 20945
diff changeset
1757 executable.getThrownTypes().add(context.getDeclaredType(UnexpectedResultException.class));
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1758 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1759
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1760 return executable;
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1761 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1762
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1763 private void renameOriginalParameters(ExecutableTypeData executedType, CodeExecutableElement executable, LocalContext currentLocals) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1764 // rename varargs parameter
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1765 int evaluatedIndex = 0;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1766 for (int executionIndex = 0; executionIndex < node.getExecutionCount(); executionIndex++) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1767 NodeExecutionData execution = node.getChildExecutions().get(executionIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1768 if (execution.isShortCircuit()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1769 if (evaluatedIndex < executedType.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1770 TypeMirror evaluatedType = executedType.getEvaluatedParameters().get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1771 LocalVariable shortCircuit = currentLocals.getShortCircuit(execution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1772 if (shortCircuit != null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1773 currentLocals.setShortCircuitValue(execution, renameExecutableTypeParameter(executable, executedType, evaluatedIndex, evaluatedType, shortCircuit));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1774 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1775 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1776 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1777 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1778 if (evaluatedIndex < executedType.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1779 TypeMirror evaluatedType = executedType.getEvaluatedParameters().get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1780 LocalVariable value = currentLocals.getValue(execution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1781 if (value != null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1782 currentLocals.setValue(execution, renameExecutableTypeParameter(executable, executedType, evaluatedIndex, evaluatedType, value));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1783 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1784 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1785 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1786 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1787 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1788
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1789 private static LocalVariable renameExecutableTypeParameter(CodeExecutableElement method, ExecutableTypeData executedType, int evaluatedIndex, TypeMirror targetType, LocalVariable var) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1790 int parameterIndex = executedType.getParameterIndex(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1791 int varArgsIndex = executedType.getVarArgsIndex(parameterIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1792 LocalVariable returnVar = var;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1793 if (varArgsIndex >= 0) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1794 returnVar = returnVar.accessWith(CodeTreeBuilder.singleString(VARARGS_NAME + "[" + varArgsIndex + "]"));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1795 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1796 ((CodeVariableElement) method.getParameters().get(parameterIndex)).setName(returnVar.getName());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1797 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1798 if (!isObject(targetType)) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1799 returnVar = returnVar.newType(targetType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1800 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1801 return returnVar;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1802 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1803
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1804 private boolean needsUnexpectedResultException(ExecutableTypeData executedType) {
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1805 if (!executedType.hasUnexpectedValue(context)) {
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1806 return false;
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1807 }
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1808
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1809 SpecializationData polymorphicSpecialization = node.getPolymorphicSpecialization();
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1810 if (polymorphicSpecialization != null && isSubtypeBoxed(context, polymorphicSpecialization.getReturnType().getType(), executedType.getReturnType())) {
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1811 return false;
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1812 } else {
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1813 return true;
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1814 }
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1815 }
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1816
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1817 private CodeTree createFastPath(CodeTreeBuilder parent, SpecializationData specialization, final ExecutableTypeData executableType, List<ExecutableTypeData> allTypes, 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
1818 final CodeTreeBuilder builder = parent.create();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1819 TypeMirror returnType = executableType.getReturnType();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1820
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1821 ExecutableTypeData delegate = null;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1822 if (specialization == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1823 delegate = executableType.getDelegatedTo();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1824 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1825
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1826 if (delegate == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1827 delegate = findFastPathDelegate((specialization != null ? specialization.getReturnType().getType() : genericType), executableType, allTypes);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1828 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1829
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1830 int delegateSignatureCount = delegate != null ? delegate.getSignatureParameters().size() : 0;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1831 for (NodeExecutionData execution : node.getChildExecutions()) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1832 if (specialization == null && delegate != null && execution.getIndex() >= delegateSignatureCount) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1833 // we just evaluate children for the next delegate
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1834 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1835 } else if (specialization != null && delegate != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1836 // skip if already delegated
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1837 break;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1838 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1839
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1840 LocalVariable var = currentLocals.getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1841 if (var == null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1842 TypeMirror targetType;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1843 if (specialization == null) {
20966
05a2b72c071f Truffle-DSL: fixed potential non generic executes in uninitialized nodes.
Christian Humer <christian.humer@gmail.com>
parents: 20964
diff changeset
1844 targetType = node.getGenericType(execution);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1845 } else {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
1846 targetType = specialization.findParameterOrDie(execution).getType();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1847 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1848 LocalVariable shortCircuit = resolveShortCircuit(specialization, execution, currentLocals);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1849 var = currentLocals.createValue(execution, targetType).nextName();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1850 builder.tree(createAssignExecuteChild(builder, execution, executableType, var, shortCircuit, currentLocals));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1851 currentLocals.setValue(execution, var);
18761
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1854
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1855 LocalContext originalValues = currentLocals.copy();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1856 if (delegate != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1857 builder.tree(createCallDelegateExecute(builder, null, currentLocals, executableType, delegate));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1858 } else if (specialization == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1859 // nothing to do. abstract anyway
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1860 } else if (specialization.isPolymorphic()) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1861 builder.tree(createCallNext(builder, executableType, node.getGenericExecutableType(executableType), currentLocals));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1862 } else if (specialization.isUninitialized()) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1863 builder.startReturn().tree(createCallDelegate("uninitialized", null, executableType, currentLocals)).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1864 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1865 SpecializationGroup group = SpecializationGroup.create(specialization);
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
1866 SpecializationBody executionFactory = new SpecializationBody(true, true) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
1867 @Override
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
1868 public CodeTree createBody(SpecializationData s, LocalContext values) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1869 return createFastPathExecute(builder, executableType, s, values);
18761
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 };
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1872 builder.tree(createGuardAndCast(group, returnType, currentLocals, executionFactory));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1873 if (hasFallthrough(group, returnType, originalValues, true, null) || group.getSpecialization().isFallback()) {
20964
56a30cfcefaf Truffle-DSL: fixed wrong executable delegate.
Christian Humer <christian.humer@gmail.com>
parents: 20963
diff changeset
1874 builder.tree(createCallNext(builder, executableType, node.getGenericExecutableType(executableType), originalValues));
18761
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 }
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
1877 return builder.build();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1878 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1879
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1880 private CodeTree createCallDelegateExecute(final CodeTreeBuilder parent, CodeTree receiver, LocalContext currentLocals, ExecutableTypeData source, ExecutableTypeData delegate) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1881 CodeTreeBuilder callBuilder = parent.create();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1882
20963
ec1dca6d288a Truffle-DSL: fixed single specializable node migth delegate to a synthetic executable type.
Christian Humer <christian.humer@gmail.com>
parents: 20951
diff changeset
1883 if (singleSpecializable && delegate.getMethod() != null) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1884 callBuilder.startCall(receiver, delegate.getMethod().getSimpleName().toString());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1885 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1886 callBuilder.startCall(receiver, delegate.getUniqueName());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1887 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1888 callBuilder.trees(bindExecuteMethodParameters(null, delegate, currentLocals));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1889 callBuilder.end();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1890 CodeTree call = expectOrCast(delegate.getReturnType(), source, callBuilder.build());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1891
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1892 CodeTreeBuilder returnBuilder = parent.create();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1893 if (isVoid(source.getReturnType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1894 returnBuilder.statement(call);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1895 returnBuilder.returnStatement();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1896 } else if (isVoid(delegate.getReturnType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1897 returnBuilder.statement(call);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1898 returnBuilder.returnDefault();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1899 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1900 returnBuilder.startReturn().tree(call).end();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1901 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1902
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1903 CodeTreeBuilder builder = parent.create();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1904
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
1905 if (!needsUnexpectedResultException(source) && needsUnexpectedResultException(delegate)) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1906 builder.startTryBlock();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1907 builder.tree(returnBuilder.build());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1908 builder.end().startCatchBlock(context.getType(UnexpectedResultException.class), "ex");
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1909 if (!isVoid(source.getReturnType())) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1910 builder.startReturn().tree(cast(context.getType(Object.class), source.getReturnType(), CodeTreeBuilder.singleString("ex.getResult()"))).end();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1911 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1912 builder.end();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1913 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1914 builder.tree(returnBuilder.build());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1915 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1916 return builder.build();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1917 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1918
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1919 private ExecutableTypeData findFastPathDelegate(TypeMirror targetType, ExecutableTypeData executableType, List<ExecutableTypeData> allTypes) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1920 if (typeEquals(executableType.getReturnType(), targetType)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1921 // type matches look for even better delegates
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1922 for (ExecutableTypeData type : allTypes) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1923 if (typeEquals(type.getReturnType(), targetType) && executableType.sameParameters(type)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1924 if (type != executableType) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1925 return type;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1926 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1927 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1928 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1929 return null;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1930 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1931 for (ExecutableTypeData type : allTypes) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1932 if (typeEquals(type.getReturnType(), targetType) && executableType.sameParameters(type)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1933 return type;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1934 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1935 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1936 int executableIndex = allTypes.indexOf(executableType);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1937 int compareIndex = 0;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1938 for (ExecutableTypeData type : allTypes) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1939 if (executableIndex != compareIndex && executableType.sameParameters(type)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1940 int result = ExecutableTypeData.compareType(context, type.getReturnType(), executableType.getReturnType());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1941 if (result < 0) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1942 return type;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1943 } else if (result == 0 && executableIndex < compareIndex) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1944 return type;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1945 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1946 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1947 compareIndex++;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1948 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1949 return null;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1950 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1951 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1952
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1953 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
1954 LocalVariable shortCircuit = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1955 if (execution.isShortCircuit()) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1956 shortCircuit = currentLocals.getShortCircuit(execution);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1957
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1958 if (shortCircuit == null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1959 SpecializationData resolvedSpecialization = specialization;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1960 if (specialization == null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1961 resolvedSpecialization = node.getGenericSpecialization();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1962 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1963 ShortCircuitData shortCircuitData = resolvedSpecialization.getShortCircuits().get(calculateShortCircuitIndex(execution));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1964 CodeTree access = callTemplateMethod(accessParent(null), shortCircuitData, currentLocals);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1965 shortCircuit = currentLocals.createShortCircuitValue(execution).accessWith(access);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1966 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1967 CodeTree access = shortCircuit.createReference();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1968 shortCircuit = shortCircuit.nextName().accessWith(access);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1969 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1970 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1971 return shortCircuit;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1972 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1973
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1974 private int calculateShortCircuitIndex(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1975 int shortCircuitIndex = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1976 for (NodeExecutionData otherExectuion : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1977 if (otherExectuion.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1978 if (otherExectuion == execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1979 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1980 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1981 shortCircuitIndex++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1982 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1983 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1984 return shortCircuitIndex;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1985 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1986
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1987 private CodeTree createFastPathExecute(CodeTreeBuilder parent, final ExecutableTypeData forType, SpecializationData specialization, 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
1988 CodeTreeBuilder builder = parent.create();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1989 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1990 if (specialization.isFallback()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1991 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
1992 if (node.isFrameUsedByAnyGuard()) {
20945
1ed58a90b510 Truffle-DSL: fixed isFrameUsedByAnyGuard() was incomplete
Christian Humer <christian.humer@gmail.com>
parents: 20944
diff changeset
1993 if (currentValues.get(FRAME_VALUE) != null) {
1ed58a90b510 Truffle-DSL: fixed isFrameUsedByAnyGuard() was incomplete
Christian Humer <christian.humer@gmail.com>
parents: 20944
diff changeset
1994 builder.string(FRAME_VALUE);
1ed58a90b510 Truffle-DSL: fixed isFrameUsedByAnyGuard() was incomplete
Christian Humer <christian.humer@gmail.com>
parents: 20944
diff changeset
1995 } else {
1ed58a90b510 Truffle-DSL: fixed isFrameUsedByAnyGuard() was incomplete
Christian Humer <christian.humer@gmail.com>
parents: 20944
diff changeset
1996 builder.nullLiteral();
1ed58a90b510 Truffle-DSL: fixed isFrameUsedByAnyGuard() was incomplete
Christian Humer <christian.humer@gmail.com>
parents: 20944
diff changeset
1997 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1998 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1999 currentValues.addReferencesTo(builder);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2000
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2001 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2002 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2003 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2004 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2005 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2006 CodeTreeBuilder execute = builder.create();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2007
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2008 if (!specialization.getAssumptionExpressions().isEmpty()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2009 builder.startTryBlock();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2010 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2011 LocalVariable assumptionVar = currentValues.get(assumptionName(assumption));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2012 if (assumptionVar == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2013 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
2014 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2015 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
2016 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2017 builder.end().startCatchBlock(getType(InvalidAssumptionException.class), "ae");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2018 builder.startReturn();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2019 List<String> assumptionIds = new ArrayList<>();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2020 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2021 assumptionIds.add(assumption.getId());
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2022 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2023 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
2024 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2025 builder.end();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2026 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2027
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2028 if (specialization.getMethod() == null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2029 execute.startReturn();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2030 execute.startCall("unsupported");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2031 currentValues.addReferencesTo(execute, FRAME_VALUE);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2032 execute.end();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2033 execute.end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2034 } else {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2035 boolean doReturn = !isVoid(specialization.getMethod().getReturnType());
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2036 if (doReturn) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2037 execute.startReturn();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2038 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2039 execute.startStatement();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2040 }
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
2041 execute.tree(callTemplateMethod(accessParent(null), specialization, currentValues));
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2042 execute.end();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2043 if (!doReturn) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2044 if (isVoid(forType.getReturnType())) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2045 execute.returnStatement();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2046 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2047 execute.startReturn();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2048 execute.defaultValue(forType.getReturnType());
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2049 execute.end();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2050 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2051 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2052 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2053 builder.tree(createFastPathTryCatchRewriteException(specialization, forType, currentValues, execute.build()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2054 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2055 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2056 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2057
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2058 private CodeTree createGuardAndCast(SpecializationGroup group, TypeMirror forType, LocalContext currentValues, SpecializationBody execution) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2059 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2060
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2061 Set<TypeGuard> castGuards;
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
2062 if (execution.needsCastedValues()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2063 castGuards = null; // cast all
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2064 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2065 castGuards = new HashSet<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2066 for (TypeGuard castGuard : group.getTypeGuards()) {
21077
4cba24bef2ee Truffle-DSL: fix unnecessary cast in generated isIdentical for types used just in cached expressions .
Christian Humer <christian.humer@gmail.com>
parents: 21066
diff changeset
2067 if (isTypeGuardUsedInAnyGuardOrCacheBelow(group, currentValues, castGuard, execution.isFastPath())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2068 castGuards.add(castGuard);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2069 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2070 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2071 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2072
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2073 SpecializationData specialization = group.getSpecialization();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2074 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
2075
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2076 CodeTree check = checkAndCast[0];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2077 CodeTree cast = checkAndCast[1];
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 List<GuardExpression> elseGuardExpressions = group.findElseConnectableGuards();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2080 List<GuardExpression> guardExpressions = new ArrayList<>(group.getGuards());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2081 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
2082 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
2083 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
2084 CodeTree guardAssertions = methodGuardAndAssertions[1];
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2085
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2086 int ifCount = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2087 if (!check.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2088 builder.startIf();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2089 builder.tree(check).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2090 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2091 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2092 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2093 if (!cast.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2094 builder.tree(cast);
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 boolean elseIf = !elseGuardExpressions.isEmpty();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2097 if (!methodGuards.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2098 builder.startIf(elseIf);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2099 builder.tree(methodGuards).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2100 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2101 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2102 } else if (elseIf) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2103 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2104 ifCount++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2105 }
19303
37bbcabf7744 Truffle-DSL: move constant guard assertions after dynamic guards.
Christian Humer <christian.humer@gmail.com>
parents: 19299
diff changeset
2106 if (!guardAssertions.isEmpty()) {
37bbcabf7744 Truffle-DSL: move constant guard assertions after dynamic guards.
Christian Humer <christian.humer@gmail.com>
parents: 19299
diff changeset
2107 builder.tree(guardAssertions);
37bbcabf7744 Truffle-DSL: move constant guard assertions after dynamic guards.
Christian Humer <christian.humer@gmail.com>
parents: 19299
diff changeset
2108 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2109
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2110 boolean reachable = isReachableGroup(group, ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2111 if (reachable) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2112 for (SpecializationGroup child : group.getChildren()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2113 builder.tree(createGuardAndCast(child, forType, currentValues.copy(), execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2114 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2115 if (specialization != null) {
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
2116 builder.tree(execution.createBody(specialization, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2117 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2118 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2119 builder.end(ifCount);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2120
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2121 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2122 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2123
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2124 private static boolean isReachableGroup(SpecializationGroup group, int ifCount) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2125 if (ifCount != 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2126 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2127 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2128 SpecializationGroup previous = group.getPreviousGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2129 if (previous == null || previous.findElseConnectableGuards().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2130 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2131 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2132
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2133 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2134 * 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
2135 * 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
2136 */
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2137 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
2138 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2139 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2140 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2141
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2142 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2143 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2144
21077
4cba24bef2ee Truffle-DSL: fix unnecessary cast in generated isIdentical for types used just in cached expressions .
Christian Humer <christian.humer@gmail.com>
parents: 21066
diff changeset
2145 private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard, boolean fastPath) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2146 String localName = currentValues.getValue(typeGuard.getSignatureIndex()).getName();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2147
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2148 SpecializationData specialization = group.getSpecialization();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2149 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
2150 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
2151 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
2152 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2153 }
21077
4cba24bef2ee Truffle-DSL: fix unnecessary cast in generated isIdentical for types used just in cached expressions .
Christian Humer <christian.humer@gmail.com>
parents: 21066
diff changeset
2154 if (!fastPath && specialization != 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
2155 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
2156 if (isVariableBoundIn(specialization, cache.getExpression(), localName, currentValues)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2157 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2158 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2159 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2160 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2161
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2162 for (SpecializationGroup child : group.getChildren()) {
21077
4cba24bef2ee Truffle-DSL: fix unnecessary cast in generated isIdentical for types used just in cached expressions .
Christian Humer <christian.humer@gmail.com>
parents: 21066
diff changeset
2163 if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard, fastPath)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2164 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2165 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2166 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2167
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2168 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2169 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2170
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2171 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
2172 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
2173 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
2174 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
2175 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
2176 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
2177 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2178 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2179 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
2180 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2181
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2182 private CodeExecutableElement createExecuteChildMethod(NodeExecutionData execution, TypeMirror targetType) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2183 if (!usedExecuteChildMethods.contains(execution)) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2184 return null;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2185 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2186
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2187 LocalContext locals = LocalContext.load(this, createSpecializationNodeSignature(0), Integer.MAX_VALUE);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2188
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2189 CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), targetType, executeChildMethodName(execution, targetType), Integer.MAX_VALUE, FRAME_VALUE);
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
2190 if (hasChildUnexpectedResult(execution, targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2191 method.getThrownTypes().add(getType(UnexpectedResultException.class));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2192 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2193
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2194 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2195 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2196 method.addParameter(implicitProfile);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2197 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2198
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2199 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
2200 NodeExecutionData executeWith = node.getChildExecutions().get(i);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2201 LocalVariable var = locals.createValue(executeWith, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2202 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2203 locals.setValue(executeWith, var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2204 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2205
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2206 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
2207 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
2208 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2209 builder.statement(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2210 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2211 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2212 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2213 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2214 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2215
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2216 private CodeVariableElement createImplicitProfileParameter(NodeExecutionData execution, TypeMirror targetType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2217 if (typeSystem.hasImplicitSourceTypes(targetType)) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2218 if (typeEquals(node.getGenericType(execution), targetType)) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2219 return null;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2220 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2221
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2222 switch (options.implicitCastOptimization()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2223 case NONE:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2224 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2225 case DUPLICATE_TAIL:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2226 return new CodeVariableElement(getType(Class.class), implicitClassFieldName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2227 case MERGE_CASTS:
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2228 return new CodeVariableElement(ImplicitCastNodeFactory.type(typeSystem, targetType), implicitNodeFieldName(execution));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2229 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2230 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2231 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2232 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2233
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2234 private boolean isExecuteChildShared(NodeExecutionData execution, TypeMirror targetType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2235 if (isVoid(targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2236 return false;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2237 } else if (isObject(targetType)) {
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
2238 return resolvePolymorphicExecutables(execution).size() >= 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2239 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2240 if (!isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), targetType)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2241 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2242 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2243 if (!typeSystem.hasImplicitSourceTypes(targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2244 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2245 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2246
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2247 int uses = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2248 for (SpecializationData specialization : node.getSpecializations()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2249 List<Parameter> parameters = specialization.findByExecutionData(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2250 for (Parameter parameter : parameters) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2251 if (targetType.equals(parameter.getType())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2252 uses++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2253 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2254 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2255 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2256 if (uses > 1) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2257 return resolveSpecializedExecutables(execution, typeSystem.lookupSourceTypes(targetType), options.implicitTypeBoxingOptimization()).size() > 1;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2258 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2259 return false;
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2262 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2263
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2264 private CodeTree createAssignExecuteChild(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData type, LocalVariable targetValue, LocalVariable shortCircuit,
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2265 LocalContext currentValues) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2266 CodeTreeBuilder builder = parent.create();
20948
a0d97b639d57 Truffle-DSL: do not throw UnexpectedResultException for operations that guarantee the type.
Christian Humer <christian.humer@gmail.com>
parents: 20947
diff changeset
2267 boolean hasUnexpected = hasChildUnexpectedResult(execution, targetValue.getTypeMirror());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2268
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2269 CodeTree executeChild;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2270 if (isExecuteChildShared(execution, targetValue.getTypeMirror())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2271 executeChild = createCallSharedExecuteChild(execution, targetValue, currentValues);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2272 } 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
2273 executeChild = createExecuteChild(execution, targetValue, currentValues, false);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2274 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2275
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2276 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
2277
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
2278 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
2279 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
2280 }
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
2281
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2282 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2283 if (hasUnexpected) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2284 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
2285 LocalContext slowPathValues = currentValues.copy();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2286 slowPathValues.setValue(execution, targetValue.makeGeneric(context).accessWith(CodeTreeBuilder.singleString("ex.getResult()")));
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2287
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2288 ExecutableTypeData delegateType = node.getGenericExecutableType(type);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2289 boolean found = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2290 for (NodeExecutionData otherExecution : node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2291 if (found) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2292 LocalVariable childEvaluatedValue = slowPathValues.createValue(otherExecution, genericType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2293 LocalVariable genericShortCircuit = resolveShortCircuit(null, otherExecution, slowPathValues);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2294 builder.tree(createAssignExecuteChild(builder, otherExecution, delegateType, childEvaluatedValue, genericShortCircuit, slowPathValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2295 slowPathValues.setValue(otherExecution, childEvaluatedValue);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2296 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2297 // skip forward already evaluated
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2298 found = execution == otherExecution;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2299 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2300 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2301 builder.tree(createCallNext(builder, type, delegateType, slowPathValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2302 builder.end();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2305 return createShortCircuit(targetValue, shortCircuit, builder.build());
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 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
2309 if (shortCircuitValue == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2310 return tryExecute;
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 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2314
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2315 builder.tree(shortCircuitValue.createDeclaration(shortCircuitValue.createReference()));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2316 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
2317
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2318 builder.startIf().string(shortCircuitValue.getName()).end().startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2319 builder.tree(tryExecute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2320 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2321
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2322 return builder.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2325 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
2326 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2327 boolean hasDeclaration = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2328 if ((hasTry || !executeChild.isSingleLine()) && needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2329 builder.tree(value.createDeclaration(null));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2330 hasDeclaration = true;
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 if (hasTry) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2334 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2335 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2336 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2337 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2338
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2339 if (executeChild.isSingleLine()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2340 builder.startStatement();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2341 if (hasDeclaration || !needDeclaration) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2342 builder.tree(executeChild);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2343 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2344 builder.type(value.getTypeMirror()).string(" ").tree(executeChild);
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 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2347 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2348 builder.tree(executeChild);
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2351 builder.end();
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 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2354 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2355
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2356 private CodeTree createCallSharedExecuteChild(NodeExecutionData execution, LocalVariable targetValue, LocalContext currentValues) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2357 if (!isExecuteChildShared(execution, targetValue.getTypeMirror())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2358 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
2359 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2360 usedExecuteChildMethods.add(execution);
18761
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 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2363 builder.tree(targetValue.createReference()).string(" = ");
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2364 builder.startCall(executeChildMethodName(execution, targetValue.getTypeMirror()));
20944
354b7f1b4acf Truffle-DSL: fixed frame may be null for shared polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
2365 if (currentValues.get(FRAME_VALUE) == null) {
354b7f1b4acf Truffle-DSL: fixed frame may be null for shared polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
2366 builder.nullLiteral();
354b7f1b4acf Truffle-DSL: fixed frame may be null for shared polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
2367 } else {
354b7f1b4acf Truffle-DSL: fixed frame may be null for shared polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
2368 builder.string(FRAME_VALUE);
354b7f1b4acf Truffle-DSL: fixed frame may be null for shared polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
2369 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2370
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2371 CodeVariableElement implicitProfile = createImplicitProfileParameter(execution, targetValue.getTypeMirror());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2372 if (implicitProfile != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2373 builder.string(implicitProfile.getName());
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 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
2376 builder.tree(currentValues.getValue(i).createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2377 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2378 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2379 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2380 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2381
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
2382 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
2383 final CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2384
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 CodeTree assignment = createAssignmentStart(target, shared);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2386
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2387 final Set<ExecutableTypeData> executableTypes = findSpecializedExecutableTypes(execution, target.getTypeMirror());
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
2388 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
2389 throw new AssertionError(); // cannot execute child
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2390 } else if (executableTypes.size() == 1 && !typeSystem.hasImplicitSourceTypes(target.getTypeMirror())) {
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
2391 ExecutableTypeData executableType = executableTypes.iterator().next();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2392 if (isObject(target.getTypeMirror()) && executableType.getEvaluatedCount() == 0) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2393 return createPolymorphicExecuteChild(execution, target, currentValues, shared);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2394 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2395 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
2396 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
2397 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2398 } 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
2399 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
2400 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
2401 } 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
2402 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
2403 } 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
2404 // 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
2405 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
2406 } 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
2407 throw new AssertionError();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2408 }
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 return builder.build();
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
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2413 private CodeTree createSingleExecute(NodeExecutionData execution, LocalVariable target, LocalContext currentValues, ExecutableTypeData executableType) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2414 CodeTree execute = callExecuteMethod(execution, executableType, currentValues);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2415 return expect(executableType.getReturnType(), target.getTypeMirror(), execute);
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
2416 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2417
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2418 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
2419 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
2420 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
2421 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
2422 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2423
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
2424 List<ExecutableTypeData> specializedExecutables = resolvePolymorphicExecutables(execution);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2425 Collections.sort(specializedExecutables, new Comparator<ExecutableTypeData>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2426 public int compare(ExecutableTypeData o1, ExecutableTypeData o2) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2427 return compareType(o1.getReturnType(), o2.getReturnType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2428 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2429 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2430
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
2431 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
2432 CodeTree executeGeneric = createSingleExecute(execution, target, currentValues, genericExecutableType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2433
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
2434 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
2435 if (specializedExecutables.isEmpty()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2436 builder.tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2437 builder.tree(executeGeneric);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2438 } 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
2439 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
2440 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
2441 final String valueFieldName = "_value";
21066
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2442 final String typeFieldName = "_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
2443
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2444 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
2445
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2446 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
2447 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
2448 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
2449 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
2450 polyChainBuilder.string(profileField);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2451 polyChainBuilder.string(" == ").typeLiteral(executableType.getReturnType());
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
2452 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
2453 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
2454 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
2455 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
2456 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
2457 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
2458 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
2459 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2460
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18774
diff changeset
2461 // 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
2462 polyChainBuilder.startElseIf().string(profileField).string(" == null").end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2463 polyChainBuilder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2464 polyChainBuilder.tree(createTransferToInterpreterAndInvalidate());
21066
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2465 polyChainBuilder.declaration(context.getType(Class.class), typeFieldName, polyChainBuilder.create().typeLiteral(genericType).build());
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2466 polyChainBuilder.startTryBlock();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2467 polyChainBuilder.declaration(genericExecutableType.getReturnType(), valueFieldName, executeGeneric);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2468
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2469 hasSpecializedTypes = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2470 for (ExecutableTypeData executableType : specializedExecutables) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2471 hasSpecializedTypes = polyChainBuilder.startIf(hasSpecializedTypes);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2472 polyChainBuilder.tree(TypeSystemCodeGenerator.check(typeSystem, executableType.getReturnType(), CodeTreeBuilder.singleString(valueFieldName)));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2473 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2474 polyChainBuilder.startBlock();
21066
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2475 polyChainBuilder.startStatement().string(typeFieldName).string(" = ").typeLiteral(executableType.getReturnType()).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2476 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2477 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2478 polyChainBuilder.startElseBlock();
21066
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2479 polyChainBuilder.startStatement().string(typeFieldName).string(" = ").typeLiteral(genericType).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
2480 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
2481 polyChainBuilder.startReturn().string(valueFieldName).end();
21066
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2482
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2483 polyChainBuilder.end().startFinallyBlock();
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2484 polyChainBuilder.startStatement().tree(accessParent(profileField)).string(" = ").string(typeFieldName).end();
82539241ff38 Truffle-DSL: initialize the polymorphic cached type also if the child node throws an exception.
Christian Humer <christian.humer@gmail.com>
parents: 21065
diff changeset
2485 polyChainBuilder.end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2486 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2487
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
2488 // else -> execute generic
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2489 polyChainBuilder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2490 polyChainBuilder.startStatement().tree(assignment).tree(executeGeneric).end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2491 polyChainBuilder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2492
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
2493 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
2494 if (encounteredUnexpectedResult) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2495 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
2496 builder.tree(executePolymorphic);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2497 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2498 builder.startCatchBlock(getType(UnexpectedResultException.class), "ex");
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2499 builder.startStatement().tree(accessParent(profileField)).string(" = ").typeLiteral(genericType).end();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2500 builder.startReturn().string("ex.getResult()").end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2501 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
2502 } 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
2503 builder.tree(executePolymorphic);
18761
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 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2506 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2507 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2508
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
2509 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
2510 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
2511 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
2512 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2513 Set<TypeMirror> specializedTypes = new HashSet<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2514 for (TypeMirror type : node.findSpecializedTypes(execution)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2515 specializedTypes.addAll(typeSystem.lookupSourceTypes(type));
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
2516 }
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
2517 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
2518 }
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
2519
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
2520 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
2521 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2522 if (shared) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2523 builder.string("return ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2524 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2525 builder.string(target.getName()).string(" = ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2526 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2527 return builder.build();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2530 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
2531 CodeTreeBuilder builder = parent.create();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2532 List<TypeMirror> sourceTypes = typeSystem.lookupSourceTypes(target.getTypeMirror());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2533 String implicitClassFieldName = implicitClassFieldName(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
2534 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
2535
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2536 boolean elseIf = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2537 for (ExecutableTypeData executableType : executableTypes) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2538 elseIf = builder.startIf(elseIf);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2539 builder.string(implicitClassFieldName).string(" == ").typeLiteral(executableType.getReturnType());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2540 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2541 builder.startBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2542 builder.startStatement().tree(assignment);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2543
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2544 CodeTree execute = callExecuteMethod(execution, executableType, currentValues);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2545 ImplicitCastData cast = typeSystem.lookupCast(executableType.getReturnType(), target.getTypeMirror());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2546 if (cast != null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2547 execute = callMethod(null, cast.getMethod(), execute);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2548 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2549 builder.tree(execute);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2550 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2551 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2552 }
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 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2555 builder.startElseBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2556 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2557
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2558 LocalVariable genericValue = target.makeGeneric(context).nextName();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2559 builder.tree(createAssignExecuteChild(builder, execution, node.getGenericExecutableType(null), genericValue, null, currentValues));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2560 if (executableTypes.size() == sourceTypes.size()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2561 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
2562 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2563 builder.startStatement().tree(assignment);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2564 builder.tree(TypeSystemCodeGenerator.implicitExpect(typeSystem, target.getTypeMirror(), genericValue.createReference(), implicitClassFieldName));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2565 builder.end();
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
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2568 if (!executableTypes.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2569 builder.end();
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 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2572 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2573
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
2574 private CodeTree createFastPathTryCatchRewriteException(SpecializationData specialization, ExecutableTypeData forType, LocalContext currentValues, CodeTree execution) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2575 if (specialization.getExceptions().isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2576 return execution;
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 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2579 builder.startTryBlock();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2580 builder.tree(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2581 TypeMirror[] exceptionTypes = new TypeMirror[specialization.getExceptions().size()];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2582 for (int i = 0; i < exceptionTypes.length; i++) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2583 exceptionTypes[i] = specialization.getExceptions().get(i).getJavaClass();
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 builder.end().startCatchBlock(exceptionTypes, "ex");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2586 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
2587 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
2588 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2589 return builder.build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2590 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2591
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2592 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
2593 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
2594 CodeTreeBuilder assertionBuilder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2595 String and = "";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2596 for (GuardExpression guard : guardExpressions) {
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2597 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
2598
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2599 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
2600 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
2601
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2602 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
2603 /*
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2604 * 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
2605 * path.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2606 */
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2607 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
2608 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2609 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
2610 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
2611 and = " && ";
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2612 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2613 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2614 return new CodeTree[]{expressionBuilder.build(), assertionBuilder.build()};
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2615 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2616
19299
8e4f683e16d9 Truffle-DSL: fixed warning
Christian Humer <christian.humer@gmail.com>
parents: 19294
diff changeset
2617 private static Map<Variable, CodeTree> castBoundTypes(Map<Variable, LocalVariable> bindings) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2618 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
2619 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
2620 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
2621 CodeTree resolved = localVariable.createReference();
19294
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2622 TypeMirror sourceType = localVariable.getTypeMirror();
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2623 TypeMirror targetType = variable.getResolvedTargetType();
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2624 if (targetType == null) {
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2625 targetType = variable.getResolvedType();
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2626 }
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2627 if (!ElementUtils.isAssignable(sourceType, targetType)) {
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
2628 resolved = CodeTreeBuilder.createBuilder().cast(targetType, resolved).build();
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2629 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2630 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
2631 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2632 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
2633 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2634
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2635 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
2636 Map<Variable, LocalVariable> bindings = new HashMap<>();
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2637
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2638 Set<Variable> boundVariables = expression.findBoundVariables();
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2639 if (specialization == null && !boundVariables.isEmpty()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2640 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
2641 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2642
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2643 // resolve bindings for local context
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2644 for (Variable variable : boundVariables) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2645 Parameter resolvedParameter = specialization.findByVariable(variable.getResolvedVariable());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2646 if (resolvedParameter != null) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2647 LocalVariable localVariable;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2648 if (resolvedParameter.getSpecification().isSignature()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2649 NodeExecutionData execution = resolvedParameter.getSpecification().getExecution();
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2650 localVariable = currentValues.getValue(execution);
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2651 } else {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2652 localVariable = currentValues.get(resolvedParameter.getLocalName());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2653 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2654 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
2655 bindings.put(variable, localVariable);
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2656 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2657 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2658 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2659 return bindings;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2660 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
2661
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2662 private CodeTree[] createTypeCheckAndLocals(SpecializationData specialization, List<TypeGuard> typeGuards, Set<TypeGuard> castGuards, LocalContext currentValues,
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
2663 SpecializationBody specializationExecution) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2664 CodeTreeBuilder checksBuilder = CodeTreeBuilder.createBuilder();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2665 CodeTreeBuilder localsBuilder = CodeTreeBuilder.createBuilder();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2666 for (TypeGuard typeGuard : typeGuards) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2667 int signatureIndex = typeGuard.getSignatureIndex();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2668 LocalVariable value = currentValues.getValue(signatureIndex);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2669 TypeMirror targetType = typeGuard.getType();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2670 if (!ElementUtils.needsCastTo(value.getTypeMirror(), targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2671 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2672 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2673 NodeExecutionData execution = node.getChildExecutions().get(signatureIndex);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2674 if (!checksBuilder.isEmpty()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2675 checksBuilder.string(" && ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2676 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2677
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2678 CodeTreeBuilder checkBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2679 CodeTreeBuilder castBuilder = checksBuilder.create();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2680
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2681 LocalVariable shortCircuit = currentValues.getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2682 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2683 checkBuilder.string("(");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2684 CodeTreeBuilder referenceBuilder = checkBuilder.create();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2685 if (!ElementUtils.isPrimitive(shortCircuit.getTypeMirror())) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2686 referenceBuilder.string("(boolean) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2687 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2688 referenceBuilder.tree(shortCircuit.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2689 checkBuilder.string("!").tree(referenceBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2690 checkBuilder.string(" || ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2691 castBuilder.tree(referenceBuilder.build()).string(" ? ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2692 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2693
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2694 List<ImplicitCastData> sourceTypes = typeSystem.lookupByTargetType(targetType);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2695 CodeTree valueReference = value.createReference();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2696 if (sourceTypes.isEmpty()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2697 checkBuilder.tree(TypeSystemCodeGenerator.check(typeSystem, targetType, value.createReference()));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2698 castBuilder.tree(TypeSystemCodeGenerator.cast(typeSystem, targetType, valueReference));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2699 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2700 ImplicitCastOptimization opt = options.implicitCastOptimization();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2701 if (specializationExecution.isFastPath() && !opt.isNone()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2702 if (opt.isDuplicateTail()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2703 String typeHintField = implicitClassFieldName(execution);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2704 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(typeSystem, targetType, valueReference, typeHintField));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2705 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(typeSystem, targetType, valueReference, typeHintField));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2706 } else if (opt.isMergeCasts()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2707 checkBuilder.tree(ImplicitCastNodeFactory.check(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2708 castBuilder.tree(ImplicitCastNodeFactory.cast(implicitNodeFieldName(execution), valueReference));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2709 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2710 throw new AssertionError("implicit cast opt");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2711 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2712 } else {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2713 checkBuilder.tree(TypeSystemCodeGenerator.implicitCheck(typeSystem, targetType, valueReference, null));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2714 castBuilder.tree(TypeSystemCodeGenerator.implicitCast(typeSystem, targetType, valueReference, null));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2715 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2716 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2717
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2718 if (shortCircuit != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2719 checkBuilder.string(")");
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2720 castBuilder.string(" : ").defaultValue(targetType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2721 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2722
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2723 if (castGuards == null || castGuards.contains(typeGuard)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2724 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
2725 currentValues.setValue(execution, castVariable);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2726 localsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2727 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2728
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2729 checksBuilder.tree(checkBuilder.build());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2730 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2731
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2732 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
2733 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
2734 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
2735 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
2736 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2737 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2738 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2739
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2740 return new CodeTree[]{checksBuilder.build(), localsBuilder.build()};
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2741 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2742
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
2743 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
2744 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
2745 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
2746 // 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
2747 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
2748 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
2749 builder.declaration(type, varName, initializer);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2750 currentValues.set(name, new LocalVariable(type, varName, null, null));
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
2751 }
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
2752
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2753 public static final class LocalContext {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2754
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2755 private final NodeGenFactory factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2756 private final Map<String, LocalVariable> values = new HashMap<>();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2757
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2758 private LocalContext(NodeGenFactory factory) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2759 this.factory = factory;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2760 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2761
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2762 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
2763 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
2764 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
2765 String name = cacheParameter.getVariableElement().getSimpleName().toString();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2766 set(cacheParameter.getLocalName(), new LocalVariable(cacheParameter.getType(), name, CodeTreeBuilder.singleString("this." + name), 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
2767 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2768
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2769 for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2770 String name = assumptionName(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2771 TypeMirror type = assumption.getExpression().getResolvedType();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2772 set(name, new LocalVariable(type, name, CodeTreeBuilder.singleString("this." + name), null));
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2773 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2774 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
2775
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2776 public CodeExecutableElement createMethod(Set<Modifier> modifiers, TypeMirror returnType, String name, int varArgsThreshold, String... optionalArguments) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2777 CodeExecutableElement method = new CodeExecutableElement(modifiers, returnType, name);
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2778 addParametersTo(method, varArgsThreshold, optionalArguments);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2779 return method;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2780 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2781
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2782 public static LocalContext load(NodeGenFactory factory, ExecutableTypeData type, int varargsThreshold) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2783 LocalContext context = new LocalContext(factory);
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2784 context.loadEvaluatedValues(type, varargsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2785 return context;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2786 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2787
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2788 private void loadEvaluatedValues(ExecutableTypeData executedType, int varargsThreshold) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2789 TypeMirror frame = executedType.getFrameParameter();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2790 if (frame == null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2791 removeValue(FRAME_VALUE);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2792 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2793 set(FRAME_VALUE, new LocalVariable(frame, FRAME_VALUE, null, null));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2794 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2795 for (NodeFieldData field : factory.node.getFields()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2796 String fieldName = fieldValueName(field);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2797 values.put(fieldName, new LocalVariable(field.getType(), fieldName, factory.accessParent(field.getName()), null));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2798 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2799 boolean varargs = needsVarargs(false, varargsThreshold);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2800 List<TypeMirror> evaluatedParameter = executedType.getEvaluatedParameters();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2801 int evaluatedIndex = 0;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2802 for (int executionIndex = 0; executionIndex < factory.node.getExecutionCount(); executionIndex++) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2803 NodeExecutionData execution = factory.node.getChildExecutions().get(executionIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2804 if (execution.isShortCircuit()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2805 if (evaluatedIndex < executedType.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2806 TypeMirror evaluatedType = evaluatedParameter.get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2807 LocalVariable shortCircuit = createShortCircuitValue(execution).newType(evaluatedType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2808 if (varargs) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2809 shortCircuit = shortCircuit.accessWith(createReadVarargs(evaluatedIndex));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2810 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2811 values.put(shortCircuit.getName(), shortCircuit.makeOriginal());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2812 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2813 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2814 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2815 if (evaluatedIndex < executedType.getEvaluatedCount()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2816 TypeMirror evaluatedType = evaluatedParameter.get(evaluatedIndex);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2817 LocalVariable value = createValue(execution, evaluatedType);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2818 if (varargs) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2819 value = value.accessWith(createReadVarargs(evaluatedIndex));
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2820 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2821 values.put(value.getName(), value.makeOriginal());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2822 evaluatedIndex++;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2823 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2824 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2825 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2826
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2827 public static LocalContext load(NodeGenFactory factory) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2828 return load(factory, factory.createSpecializationNodeSignature(factory.node.getSignatureSize()), factory.varArgsThreshold);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2829 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2830
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2831 public LocalContext copy() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2832 LocalContext copy = new LocalContext(factory);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2833 copy.values.putAll(values);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2834 return copy;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2835 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2836
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2837 private static String fieldValueName(NodeFieldData field) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2838 return field.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2839 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2840
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2841 @SuppressWarnings("static-method")
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2842 public LocalVariable createValue(NodeExecutionData execution, TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2843 return new LocalVariable(type, valueName(execution), null, null);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2844 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2845
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2846 public LocalVariable createShortCircuitValue(NodeExecutionData execution) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2847 return new LocalVariable(factory.getType(boolean.class), shortCircuitName(execution), null, null);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2848 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2849
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2850 private static String valueName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2851 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2852 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2853
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2854 private static String shortCircuitName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2855 return "has" + ElementUtils.firstLetterUpperCase(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2856 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2857
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2858 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
2859 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
2860 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
2861
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2862 public LocalVariable get(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2863 return values.get(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2864 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2865
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2866 public LocalVariable get(Parameter parameter, int signatureIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2867 LocalVariable var = get(parameter.getLocalName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2868 if (var == null && parameter.getSpecification().isSignature()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2869 // 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
2870 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
2871 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
2872 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
2873 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
2874 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2875 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2876 return var;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2877 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2878
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2879 public LocalVariable getValue(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2880 return get(valueName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2881 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2882
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2883 public LocalVariable getValue(int signatureIndex) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2884 List<NodeExecutionData> childExecutions = factory.node.getChildExecutions();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2885 if (signatureIndex < childExecutions.size()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2886 return getValue(childExecutions.get(signatureIndex));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2887 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2888 return null;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
2889 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2890 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2891
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2892 public void removeValue(String id) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2893 values.remove(id);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2894 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2895
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2896 public void setValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2897 values.put(valueName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2898 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2899
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2900 public void setShortCircuitValue(NodeExecutionData execution, LocalVariable var) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2901 if (var == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2902 return;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2903 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2904 values.put(shortCircuitName(execution), var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2905 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2906
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
2907 private boolean needsVarargs(boolean requireLoaded, int varArgsThreshold) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2908 int size = 0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2909 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2910 if (requireLoaded && getValue(execution) == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2911 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2912 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2913 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2914 size += 2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2915 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2916 size++;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2917 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2918 }
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
2919 return size >= varArgsThreshold;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2920 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2921
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2922 private static CodeTree createReadVarargs(int i) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2923 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
2924 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2925
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2926 public void addReferencesTo(CodeTreeBuilder builder, String... optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2927 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2928 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2929 if (local == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2930 builder.nullLiteral();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2931 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2932 builder.tree(local.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2933 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2934 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2935
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2936 List<NodeExecutionData> executions = factory.node.getChildExecutions();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2937 for (NodeExecutionData execution : executions) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2938 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2939 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2940 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2941 builder.tree(shortCircuitVar.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2942 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2943 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2944 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2945 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2946 builder.startGroup();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2947 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
2948 // 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
2949 builder.string("(Object) ");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2950 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2951 builder.tree(var.createReference());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2952 builder.end();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2953 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2954 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2955 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2956
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2957 public void addParametersTo(CodeExecutableElement method, int varArgsThreshold, String... optionalNames) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2958 for (String var : optionalNames) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2959 LocalVariable local = values.get(var);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2960 if (local != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2961 method.addParameter(local.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2962 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2963 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
2964 if (needsVarargs(true, varArgsThreshold)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2965 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
2966 method.setVarArgs(true);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2967 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2968 for (NodeExecutionData execution : factory.node.getChildExecutions()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2969 if (execution.isShortCircuit()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2970 LocalVariable shortCircuitVar = getShortCircuit(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2971 if (shortCircuitVar != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2972 method.addParameter(shortCircuitVar.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2973 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2974 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2975
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2976 LocalVariable var = getValue(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2977 if (var != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2978 method.addParameter(var.createParameter());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2979 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2980 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2981 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2982 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2983
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2984 private LocalVariable getShortCircuit(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2985 return values.get(shortCircuitName(execution));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2986 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2987
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2988 @Override
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2989 public String toString() {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2990 return "LocalContext [values=" + values + "]";
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2991 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
2992
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2993 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2994
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
2995 public static final class LocalVariable {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2996
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2997 private final TypeMirror typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2998 private final CodeTree accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2999 private final String name;
19704
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3000 private final LocalVariable previous;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3001
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3002 public static LocalVariable fromParameter(Parameter parameter) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3003 NodeExecutionData execution = parameter.getSpecification().getExecution();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3004 String name = null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3005 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3006 name = parameter.getLocalName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3007 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3008 name = createName(execution);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3009 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3010 return new LocalVariable(parameter.getType(), name, null, null);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3011 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3012
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3013 private LocalVariable(TypeMirror typeMirror, String name, CodeTree accessorTree, LocalVariable previous) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3014 Objects.requireNonNull(typeMirror);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3015 this.typeMirror = typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3016 this.accessorTree = accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3017 this.name = name;
19704
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3018 this.previous = previous;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3019 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3020
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3021 public String getShortCircuitName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3022 return "has" + ElementUtils.firstLetterUpperCase(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3023 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3024
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3025 public String getName() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3026 return name;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3027 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3028
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3029 private static String createNextName(String name) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3030 return name + "_";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3031 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3032
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3033 private static String createName(NodeExecutionData execution) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3034 if (execution == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3035 return "<error>";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3036 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3037 return execution.getName() + "Value";
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3038 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3039
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3040 public TypeMirror getTypeMirror() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3041 return typeMirror;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3042 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3043
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3044 public CodeVariableElement createParameter() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3045 return new CodeVariableElement(getTypeMirror(), getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3046 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3047
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3048 public CodeTree createDeclaration(CodeTree init) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3049 return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3050 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3051
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3052 public CodeTree createReference() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3053 if (accessorTree != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3054 return accessorTree;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3055 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3056 return CodeTreeBuilder.singleString(getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3057 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3058 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3059
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
3060 public LocalVariable newType(TypeMirror newType) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3061 return new LocalVariable(newType, name, accessorTree, this);
18788
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
3062 }
714f4931b02c Truffle-DSL: inline specialized node into gen node if single specializable.
Christian Humer <christian.humer@gmail.com>
parents: 18787
diff changeset
3063
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
3064 public LocalVariable accessWith(CodeTree tree) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3065 return new LocalVariable(typeMirror, name, tree, this);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3066 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3067
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
3068 public LocalVariable nextName() {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3069 return new LocalVariable(typeMirror, createNextName(name), accessorTree, this);
19704
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3070 }
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3071
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3072 public LocalVariable makeOriginal() {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3073 return new LocalVariable(typeMirror, name, accessorTree, null);
19704
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3074 }
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3075
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3076 public LocalVariable original() {
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3077 LocalVariable variable = this;
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3078 while (variable.previous != null) {
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3079 variable = variable.previous;
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3080 }
e9e99d8dca54 Truffle-DSL: fixed possible wrong variable accesses when calling node constructors.
Christian Humer <christian.humer@gmail.com>
parents: 19348
diff changeset
3081 return variable;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3082 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3083
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3084 public LocalVariable makeGeneric(ProcessorContext context) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20005
diff changeset
3085 return newType(context.getType(Object.class));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3086 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3087
19294
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
3088 @Override
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
3089 public String toString() {
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
3090 return "Local[type = " + getTypeMirror() + ", name = " + name + ", accessWith = " + accessorTree + "]";
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
3091 }
b31b2f289e7d Truffle-DSL: fix unnecessary frame cast warning.
Christian Humer <christian.humer@gmail.com>
parents: 19293
diff changeset
3092
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3093 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3094
19757
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3095 private abstract class SpecializationBody {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3096
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3097 private final boolean fastPath;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3098 private final boolean needsCastedValues;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3099
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3100 public SpecializationBody(boolean fastPath, boolean needsCastedValues) {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3101 this.fastPath = fastPath;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3102 this.needsCastedValues = needsCastedValues;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3103 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3104
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3105 public final boolean isFastPath() {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3106 return fastPath;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3107 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3108
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3109 public final boolean needsCastedValues() {
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3110 return needsCastedValues;
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3111 }
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3112
e8d2f3f95dcd Truffle-DSL: implemented duplication check for specializations with @Cached to avoid duplicates for multithreaded AST execution.
Christian Humer <christian.humer@gmail.com>
parents: 19756
diff changeset
3113 public abstract CodeTree createBody(SpecializationData specialization, LocalContext currentValues);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3114
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3115 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3116
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3117 }