Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java @ 13803:e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 24 Jan 2014 15:55:41 +0100 |
parents | 40fd9958cdf5 |
children |
rev | line source |
---|---|
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
11906
82ec5f898e6c
SL: remove use of RootNode() constructor
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
9834
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.nodes; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
25 import com.oracle.truffle.api.*; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
26 import com.oracle.truffle.api.dsl.*; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.frame.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.nodes.*; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
29 import com.oracle.truffle.sl.builtins.*; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
30 import com.oracle.truffle.sl.runtime.*; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
31 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
32 public final class FunctionRootNode extends RootNode { |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
33 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
34 @Child private TypedNode body; |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
35 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
36 private final TypedNode uninitializedBody; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
37 private final String name; |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
38 private final boolean inlineImmediatly; |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
7292
diff
changeset
|
39 |
13707
40fd9958cdf5
SL: required fixes for moving FrameDescriptor to the RootNode.
Christian Humer <christian.humer@gmail.com>
parents:
13338
diff
changeset
|
40 private FunctionRootNode(FrameDescriptor frameDescriptor, TypedNode body, String name, boolean inlineImmediatly) { |
40fd9958cdf5
SL: required fixes for moving FrameDescriptor to the RootNode.
Christian Humer <christian.humer@gmail.com>
parents:
13338
diff
changeset
|
41 super(null, frameDescriptor); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
42 this.uninitializedBody = NodeUtil.cloneNode(body); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 this.body = adoptChild(body); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
44 this.name = name; |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
45 this.inlineImmediatly = inlineImmediatly; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
46 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
47 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
48 public static CallTarget createBuiltin(SLContext context, NodeFactory<? extends BuiltinNode> factory, String name) { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
49 int argumentCount = factory.getExecutionSignature().size(); |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
50 TypedNode[] arguments = new TypedNode[argumentCount]; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
51 for (int i = 0; i < arguments.length; i++) { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
52 arguments[i] = new ReadArgumentNode(i); |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
53 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
54 BuiltinNode buitinBody = factory.createNode(arguments, context); |
13707
40fd9958cdf5
SL: required fixes for moving FrameDescriptor to the RootNode.
Christian Humer <christian.humer@gmail.com>
parents:
13338
diff
changeset
|
55 FunctionRootNode root = new FunctionRootNode(new FrameDescriptor(), buitinBody, name, true); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
56 return Truffle.getRuntime().createCallTarget(root); |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
57 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
58 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
59 public static CallTarget createFunction(StatementNode body, FrameDescriptor frameDescriptor, String name, TypedNode returnValue, String[] parameterNames) { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
60 FunctionBodyNode bodyContainer = new FunctionBodyNode(frameDescriptor, body, returnValue, parameterNames); |
13707
40fd9958cdf5
SL: required fixes for moving FrameDescriptor to the RootNode.
Christian Humer <christian.humer@gmail.com>
parents:
13338
diff
changeset
|
61 FunctionRootNode root = new FunctionRootNode(frameDescriptor, bodyContainer, name, false); |
40fd9958cdf5
SL: required fixes for moving FrameDescriptor to the RootNode.
Christian Humer <christian.humer@gmail.com>
parents:
13338
diff
changeset
|
62 return Truffle.getRuntime().createCallTarget(root); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 @Override |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 public Object execute(VirtualFrame frame) { |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
67 return body.executeGeneric(frame); |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
68 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
69 |
13338
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
70 public boolean isInlineImmediatly() { |
652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
71 return inlineImmediatly; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 |
13803
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
74 @Override |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
75 public RootNode inline() { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
76 return new FunctionRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBody), name, inlineImmediatly); |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
77 } |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
78 |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
79 @Override |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
80 public int getInlineNodeCount() { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
81 return NodeUtil.countNodes(uninitializedBody); |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
82 } |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
83 |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
84 @Override |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
85 public boolean isInlinable() { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13707
diff
changeset
|
86 return true; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
87 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
88 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
89 public Node getUninitializedBody() { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
90 return uninitializedBody; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 @Override |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 public String toString() { |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
95 return "function " + name; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
96 } |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
97 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
98 public String getName() { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
99 return name; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
100 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
11906
diff
changeset
|
101 |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
102 } |