Skip to content

Commit d23b4c2

Browse files
committed
use @GenerateUncached for our CallSpecialMethodNode
1 parent bbd23ae commit d23b4c2

File tree

6 files changed

+520
-707
lines changed

6 files changed

+520
-707
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 209 additions & 282 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static CallQuaternaryMethodNode create() {
5858
public abstract Object execute(VirtualFrame frame, Object callable, Object arg1, Object arg2, Object arg3, Object arg4);
5959

6060
@Specialization(guards = {"func == cachedFunc", "builtinNode != null", "frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()", assumptions = "singleContextAssumption()")
61-
Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4,
61+
Object callSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4,
6262
@SuppressWarnings("unused") @Cached("func") PBuiltinFunction cachedFunc,
6363
@Cached("getQuaternary(frame, func)") PythonQuaternaryBuiltinNode builtinNode,
6464
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
@@ -75,7 +75,7 @@ Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction fun
7575

7676
@Specialization(guards = {"func == cachedFunc", "builtinNode != null", "!takesSelfArg",
7777
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()", assumptions = "singleContextAssumption()")
78-
Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
78+
Object callMethodSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
7979
@SuppressWarnings("unused") @Cached("func") PBuiltinMethod cachedFunc,
8080
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
8181
@Cached("getQuaternary(frame, func.getFunction())") PythonQuaternaryBuiltinNode builtinNode,
@@ -84,16 +84,16 @@ Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func,
8484
}
8585

8686
@Specialization(guards = {"builtinNode != null", "getCallTarget(func) == ct", "!takesSelfArg", "frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
87-
Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
87+
Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
8888
@SuppressWarnings("unused") @Cached("getCallTarget(func)") RootCallTarget ct,
8989
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
9090
@Cached("getQuaternary(frame, func.getFunction())") PythonQuaternaryBuiltinNode builtinNode,
9191
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
9292
return builtinNode.execute(frame, arg1, arg2, arg3, arg4);
9393
}
9494

95-
@Specialization
96-
Object call(VirtualFrame frame, Object func, Object arg1, Object arg2, Object arg3, Object arg4,
95+
@Specialization(replaces = {"callSingle", "call", "callMethodSingle", "callMethod"})
96+
Object generic(VirtualFrame frame, Object func, Object arg1, Object arg2, Object arg3, Object arg4,
9797
@Cached CallNode callNode) {
9898
return callNode.execute(frame, func, new Object[]{arg1, arg2, arg3, arg4}, PKeyword.EMPTY_KEYWORDS);
9999
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallSpecialMethodNode.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.truffle.api.dsl.GeneratedBy;
6363
import com.oracle.truffle.api.dsl.ImportStatic;
6464
import com.oracle.truffle.api.dsl.NodeFactory;
65+
import com.oracle.truffle.api.dsl.NodeField;
6566
import com.oracle.truffle.api.dsl.ReportPolymorphism;
6667
import com.oracle.truffle.api.dsl.TypeSystemReference;
6768
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -73,13 +74,16 @@
7374
@TypeSystemReference(PythonTypes.class)
7475
@ImportStatic(PythonOptions.class)
7576
@ReportPolymorphism
77+
@NodeField(name = "maxSizeExceeded", type = boolean.class)
7678
abstract class CallSpecialMethodNode extends Node {
7779

7880
/**
79-
* for interpreter performance: cache if we exceeded the max caller size. Never allow inlining
81+
* for interpreter performance: cache if we exceeded the max caller size. We never allow inlining
8082
* in the uncached case.
8183
*/
82-
private boolean maxSizeExceeded = !isAdoptable();
84+
protected abstract boolean isMaxSizeExceeded();
85+
86+
protected abstract void setMaxSizeExceeded(boolean value);
8387

8488
/**
8589
* Returns a new instanceof the builtin if it's a subclass of the given class, and null
@@ -106,14 +110,14 @@ private <T extends PythonBuiltinBaseNode> T getBuiltin(VirtualFrame frame, PBuil
106110

107111
private <T extends PythonBuiltinBaseNode> boolean callerExceedsMaxSize(T builtinNode) {
108112
CompilerAsserts.neverPartOfCompilation();
109-
if (!maxSizeExceeded) {
113+
if (isAdoptable() && !isMaxSizeExceeded()) {
110114
RootNode root = getRootNode();
111115
int n = root instanceof PRootNode ? ((PRootNode) root).getNodeCount() : NodeUtil.countNodes(root);
112116
// nb: option 'BuiltinsInliningMaxCallerSize' is defined as a compatible option, i.e.,
113117
// ASTs will only we shared between contexts that have the same value for this option.
114118
int maxSize = lookupContextReference(PythonLanguage.class).get().getOption(PythonOptions.BuiltinsInliningMaxCallerSize);
115119
if (n >= maxSize || n + NodeUtil.countNodes(builtinNode) >= maxSize) {
116-
maxSizeExceeded = true;
120+
setMaxSizeExceeded(true);
117121
return true;
118122
}
119123
return false;

0 commit comments

Comments
 (0)