Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java @ 13338:652f24858aad
SL: simplified call nodes. aligned builtin inlining with user function inlining.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sun, 15 Dec 2013 23:32:41 +0100 |
parents | 71991b7a0f14 |
children | 40fd9958cdf5 |
comparison
equal
deleted
inserted
replaced
13337:ecf152c6bd16 | 13338:652f24858aad |
---|---|
33 | 33 |
34 @Child private TypedNode body; | 34 @Child private TypedNode body; |
35 | 35 |
36 private final TypedNode uninitializedBody; | 36 private final TypedNode uninitializedBody; |
37 private final String name; | 37 private final String name; |
38 private final boolean alwaysInline; | 38 private final boolean inlineImmediatly; |
39 | 39 |
40 private FunctionRootNode(TypedNode body, String name, boolean alwaysInline) { | 40 private FunctionRootNode(TypedNode body, String name, boolean inlineImmediatly) { |
41 super(null); | 41 super(null); |
42 this.uninitializedBody = NodeUtil.cloneNode(body); | 42 this.uninitializedBody = NodeUtil.cloneNode(body); |
43 this.body = adoptChild(body); | 43 this.body = adoptChild(body); |
44 this.name = name; | 44 this.name = name; |
45 this.alwaysInline = alwaysInline; | 45 this.inlineImmediatly = inlineImmediatly; |
46 } | 46 } |
47 | 47 |
48 public static CallTarget createBuiltin(SLContext context, NodeFactory<? extends BuiltinNode> factory, String name) { | 48 public static CallTarget createBuiltin(SLContext context, NodeFactory<? extends BuiltinNode> factory, String name) { |
49 int argumentCount = factory.getExecutionSignature().size(); | 49 int argumentCount = factory.getExecutionSignature().size(); |
50 TypedNode[] arguments = new TypedNode[argumentCount]; | 50 TypedNode[] arguments = new TypedNode[argumentCount]; |
65 @Override | 65 @Override |
66 public Object execute(VirtualFrame frame) { | 66 public Object execute(VirtualFrame frame) { |
67 return body.executeGeneric(frame); | 67 return body.executeGeneric(frame); |
68 } | 68 } |
69 | 69 |
70 public boolean isAlwaysInline() { | 70 public boolean isInlineImmediatly() { |
71 return alwaysInline; | 71 return inlineImmediatly; |
72 } | 72 } |
73 | 73 |
74 public TypedNode inline(ArgumentsNode clonedArgs) { | 74 public TypedNode inline() { |
75 TypedNode clonedBody = NodeUtil.cloneNode(uninitializedBody); | 75 return NodeUtil.cloneNode(uninitializedBody); |
76 if (clonedBody instanceof BuiltinNode) { | |
77 return inlineBuiltin(clonedArgs, (BuiltinNode) clonedBody); | |
78 } else if (clonedBody instanceof FunctionBodyNode) { | |
79 return inlineFunction(clonedArgs, (FunctionBodyNode) clonedBody); | |
80 } else { | |
81 throw new UnsupportedOperationException(); | |
82 } | |
83 } | |
84 | |
85 private InlinedFunctionNode inlineFunction(ArgumentsNode clonedArgs, FunctionBodyNode clonedBody) { | |
86 return new InlinedFunctionNode(getCallTarget(), clonedBody, clonedArgs); | |
87 } | |
88 | |
89 private static TypedNode inlineBuiltin(ArgumentsNode clonedArgs, BuiltinNode builtin) { | |
90 TypedNode[] callerArgs = clonedArgs.getArguments(); | |
91 TypedNode[] builtinArgs = builtin.getArguments(); | |
92 for (int i = 0; i < builtinArgs.length; i++) { | |
93 if (i < callerArgs.length) { | |
94 builtinArgs[i].replace(callerArgs[i]); | |
95 } else { | |
96 builtinArgs[i].replace(new NullLiteralNode()); | |
97 } | |
98 } | |
99 return builtin; | |
100 } | 76 } |
101 | 77 |
102 public Node getUninitializedBody() { | 78 public Node getUninitializedBody() { |
103 return uninitializedBody; | 79 return uninitializedBody; |
104 } | 80 } |
106 @Override | 82 @Override |
107 public String toString() { | 83 public String toString() { |
108 return "function " + name; | 84 return "function " + name; |
109 } | 85 } |
110 | 86 |
111 private static final class InlinedFunctionNode extends TypedNode implements InlinedCallSite { | |
112 | |
113 @Child private FunctionBodyNode body; | |
114 @Child private ArgumentsNode arguments; | |
115 | |
116 private final CallTarget callTarget; | |
117 private final FrameDescriptor frameDescriptor; | |
118 | |
119 public InlinedFunctionNode(CallTarget callTarget, FunctionBodyNode body, ArgumentsNode arguments) { | |
120 this.callTarget = callTarget; | |
121 this.body = adoptChild(body); | |
122 this.frameDescriptor = body.getFrameDescriptor(); | |
123 this.arguments = adoptChild(arguments); | |
124 } | |
125 | |
126 @Override | |
127 public Object executeGeneric(VirtualFrame frame) { | |
128 SLArguments args = new SLArguments(arguments.executeArray(frame)); | |
129 VirtualFrame childFrame = Truffle.getRuntime().createVirtualFrame(frame.pack(), args, frameDescriptor); | |
130 return body.executeGeneric(childFrame); | |
131 } | |
132 | |
133 public CallTarget getCallTarget() { | |
134 return callTarget; | |
135 } | |
136 | |
137 } | |
138 | |
139 public String getName() { | 87 public String getName() { |
140 return name; | 88 return name; |
141 } | 89 } |
142 | 90 |
143 } | 91 } |