# HG changeset patch # User Christian Humer # Date 1390909977 -3600 # Node ID 3840d61e0e6883497d8650530790e0848d803e77 # Parent e076c87ab1750d4d676f02397db509085ea4d0a2 Merge. diff -r e076c87ab175 -r 3840d61e0e68 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Fri Jan 24 15:55:41 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Tue Jan 28 12:52:57 2014 +0100 @@ -84,7 +84,7 @@ if (inlined) { for (InlinableCallSiteInfo callSite : inlinableCallSites) { - if (callSite.getCallSite().isInlinable()) { + if (callSite.getCallSite().isInlinable() && !callSite.getCallSite().isInlined()) { CallNode.internalResetCallCount(callSite.getCallSite()); } } @@ -215,7 +215,7 @@ public boolean visit(Node node) { if (node instanceof CallNode) { CallNode callNode = (CallNode) node; - if (callNode.isInlinable()) { + if (callNode.isInlinable() && !callNode.isInlined()) { inlinableCallSites.add(new InlinableCallSiteInfo(callNode)); } } diff -r e076c87ab175 -r 3840d61e0e68 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java Fri Jan 24 15:55:41 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java Tue Jan 28 12:52:57 2014 +0100 @@ -29,9 +29,9 @@ import com.oracle.truffle.api.impl.*; /** - * This node represents a call to a constant {@link CallTarget} in the Truffle AST. This node should - * be used whenever a {@link CallTarget} is considered constant at a certain location. This enables - * the Truffle runtime to perform inlining or other optimizations for this call-site. + * This node represents a call to a static {@link CallTarget}. This node should be used whenever a + * {@link CallTarget} is considered constant at a certain location in the tree. This enables the + * Truffle runtime to perform inlining or other optimizations for this call-site. * * @see #create(CallTarget) to create a CallNode instance. */ @@ -44,7 +44,7 @@ } /** - * Returns the constant {@link CallTarget} that is associated with this {@link CallNode}. + * @return the constant {@link CallTarget} that is associated with this {@link CallNode}. */ public CallTarget getCallTarget() { return callTarget; @@ -60,44 +60,34 @@ public abstract Object call(PackedFrame caller, Arguments arguments); /** - * Returns true if this {@link CallNode} can be inlined. A {@link CallTarget} is - * considered inlinable if it was created using + * Returns true if the {@link CallTarget} contained in this {@link CallNode} can be + * inlined. A {@link CallTarget} is considered inlinable if it was created using * {@link TruffleRuntime#createCallTarget(RootNode)} and if the enclosed {@link RootNode} * returns true for {@link RootNode#isInlinable()}. */ - public boolean isInlinable() { - return false; - } + public abstract boolean isInlinable(); /** - * Returns true if this {@link CallNode} was already inlined. + * @return true if this {@link CallNode} was already inlined. */ - public boolean isInlined() { - return false; - } + public abstract boolean isInlined(); /** * Enforces an inlining optimization on this {@link CallNode} instance. If not performed * manually the Truffle runtime may perform inlining using an heuristic to optimize the - * performance of the execution. It is recommended to implement an optimized version of - * {@link RootNode#inline()}. + * performance of the execution. It is recommended to implement an version of + * {@link RootNode#inline()} that adapts the inlining for possible guest language specific + * behavior. If the this {@link CallNode} is not inlinable or is already inlined + * false is returned. * - * @return true if the inlining operation was successful. - * @throws IllegalStateException if {@link #isInlinable()} is false. + * @return true if the inlining operation was successful. */ - public boolean inline() { - CompilerDirectives.transferToInterpreter(); - if (!isInlinable()) { - throw new IllegalStateException("Invoked inline on a non inlinable CallNode."); - } - assert !isInlined(); - return false; - } + public abstract boolean inline(); /** - * Creates a new {@link CallNode} using a constant {@link CallTarget}. + * Creates a new {@link CallNode} using a {@link CallTarget}. * - * @param target the {@link CallTarget} the {@link CallNode} should call + * @param target the {@link CallTarget} to call * @return a call node that calls the provided target */ public static CallNode create(CallTarget target) { @@ -112,7 +102,7 @@ * Warning: this is internal API and may change without notice. */ public static int internalGetCallCount(CallNode callNode) { - if (callNode.isInlinable()) { + if (callNode.isInlinable() && !callNode.isInlined()) { return ((InlinableCallNode) callNode).getCallCount(); } throw new UnsupportedOperationException(); @@ -122,7 +112,7 @@ * Warning: this is internal API and may change without notice. */ public static void internalResetCallCount(CallNode callNode) { - if (callNode.isInlinable()) { + if (callNode.isInlinable() && !callNode.isInlined()) { ((InlinableCallNode) callNode).resetCallCount(); return; } @@ -147,6 +137,21 @@ return callTarget.call(caller, arguments); } + @Override + public boolean inline() { + return false; + } + + @Override + public boolean isInlinable() { + return false; + } + + @Override + public boolean isInlined() { + return false; + } + } static final class InlinableCallNode extends CallNode { @@ -167,7 +172,6 @@ @Override public boolean inline() { - super.inline(); DefaultCallTarget defaultTarget = (DefaultCallTarget) getCallTarget(); RootNode originalRootNode = defaultTarget.getRootNode(); boolean inlined = false; @@ -180,6 +184,11 @@ } @Override + public boolean isInlined() { + return false; + } + + @Override public boolean isInlinable() { return true; } @@ -216,8 +225,13 @@ } @Override + public boolean inline() { + return false; + } + + @Override public boolean isInlinable() { - return false; + return true; } @Override diff -r e076c87ab175 -r 3840d61e0e68 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Fri Jan 24 15:55:41 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Tue Jan 28 12:52:57 2014 +0100 @@ -77,7 +77,7 @@ /** * Returns the number of nodes that would be returned if {@link #inline()} would get invoked. - * This node count may be used for the calculation of a smart inlining heuristic. + * This node count may be used for the calculation in a smart inlining heuristic. * * @see RootNode#inline() * @see RootNode#isInlinable() @@ -93,9 +93,9 @@ } /** - * Returns true if this RootNode can be inlined. If this method returns true proper - * implementations of {@link #inline()} and {@link #getInlineNodeCount()} must be provided. - * Returns true by default. + * Returns true if this RootNode can be inlined. If this method returns true implementations of + * {@link #inline()} and {@link #getInlineNodeCount()} must be provided. Returns + * true by default. * * @see RootNode#inline() * @see RootNode#getInlineNodeCount() diff -r e076c87ab175 -r 3840d61e0e68 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionCallNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionCallNode.java Fri Jan 24 15:55:41 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionCallNode.java Tue Jan 28 12:52:57 2014 +0100 @@ -105,9 +105,7 @@ // inline usually known functions that should always be inlined if (findSLFunctionRoot(cachedFunction).isInlineImmediatly()) { - if (callNode.isInlinable() && !callNode.isInlined()) { - callNode.inline(); - } + callNode.inline(); } }