Skip to content

Commit 560b247

Browse files
committed
[GR-62791] Simplify CallDispatchNode
PullRequest: graalpython/3714
2 parents 4a48717 + 438997b commit 560b247

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_strptime.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ test.test_strptime.StrptimeTests.test_percent @ darwin-arm64,darwin-x86_64,linux
3535
test.test_strptime.StrptimeTests.test_second @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
3636
test.test_strptime.StrptimeTests.test_strptime_exception_context @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
3737
test.test_strptime.StrptimeTests.test_time @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
38-
test.test_strptime.StrptimeTests.test_timezone @ darwin-arm64,darwin-x86_64,win32-AMD64
38+
# Seems to be dependent on the actual time/date/timezone of the machine, at least on GraalPy. Needs investigation
39+
!test.test_strptime.StrptimeTests.test_timezone
3940
test.test_strptime.StrptimeTests.test_unconverteddata @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
4041
test.test_strptime.StrptimeTests.test_year @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
4142
test.test_strptime.TimeRETests.test_blankpattern @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ public RootCallTarget getRootCallTarget() {
632632
return callTarget;
633633
}
634634

635+
public RootCallTarget getRootCallTargetOrNull() {
636+
return callTarget;
637+
}
638+
635639
@TruffleBoundary
636640
synchronized RootCallTarget initializeCallTarget() {
637641
assert PythonContext.get(null).ownsGil(); // otherwise this is racy

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchNode.java

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -25,15 +25,11 @@
2525
*/
2626
package com.oracle.graal.python.nodes.call;
2727

28-
import com.oracle.graal.python.builtins.objects.code.CodeNodes.GetCodeCallTargetNode;
2928
import com.oracle.graal.python.builtins.objects.code.PCode;
3029
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
3130
import com.oracle.graal.python.builtins.objects.function.PFunction;
3231
import com.oracle.graal.python.nodes.PNodeWithContext;
33-
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
34-
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetFunctionCodeNode;
3532
import com.oracle.graal.python.runtime.PythonOptions;
36-
import com.oracle.truffle.api.CompilerAsserts;
3733
import com.oracle.truffle.api.RootCallTarget;
3834
import com.oracle.truffle.api.dsl.Bind;
3935
import com.oracle.truffle.api.dsl.Cached;
@@ -46,6 +42,7 @@
4642
import com.oracle.truffle.api.frame.Frame;
4743
import com.oracle.truffle.api.frame.VirtualFrame;
4844
import com.oracle.truffle.api.nodes.Node;
45+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
4946

5047
@ImportStatic(PythonOptions.class)
5148
@GenerateUncached
@@ -101,38 +98,25 @@ protected static Object callFunctionCached(VirtualFrame frame, @SuppressWarnings
10198
return invoke.execute(frame, arguments);
10299
}
103100

104-
// We only have a single context and this function changed its code before, but now it's
105-
// constant
106-
protected PCode getCode(Node inliningTarget, GetFunctionCodeNode getFunctionCodeNode, PFunction function) {
107-
return getFunctionCodeNode.execute(inliningTarget, function);
108-
}
109-
110-
@Specialization(guards = {"isSingleContext()", "callee == cachedCallee", "getCode(inliningTarget, getFunctionCodeNode, callee) == cachedCode"}, //
111-
replaces = "callFunctionCached", limit = "getCallSiteInlineCacheMaxDepth()")
112-
protected static Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("unused") PFunction callee, Object[] arguments,
113-
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
114-
@SuppressWarnings("unused") @Cached("callee") PFunction cachedCallee,
115-
@SuppressWarnings("unused") @Cached GetFunctionCodeNode getFunctionCodeNode,
116-
@SuppressWarnings("unused") @Cached("getCode(inliningTarget, getFunctionCodeNode, callee)") PCode cachedCode,
117-
@Cached("createInvokeNode(cachedCallee)") FunctionInvokeNode invoke) {
118-
return invoke.execute(frame, arguments);
119-
}
120-
121-
protected static RootCallTarget getCallTargetUncached(PFunction callee) {
122-
CompilerAsserts.neverPartOfCompilation();
123-
return GetCallTargetNode.getUncached().execute(callee);
124-
}
125-
126101
// We have multiple contexts, don't cache the objects so that contexts can be cleaned up
127-
@Specialization(guards = {"getCt.execute(inliningTarget, callee.getCode()) == ct"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCachedCode")
102+
@Specialization(guards = {"getCallTarget(inliningTarget, code, initializeCodeProfile) == ct"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached")
128103
protected static Object callFunctionCachedCt(VirtualFrame frame, PFunction callee, Object[] arguments,
129104
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
130-
@SuppressWarnings("unused") @Cached("getCallTargetUncached(callee)") RootCallTarget ct,
131-
@SuppressWarnings("unused") @Cached GetCodeCallTargetNode getCt,
105+
@SuppressWarnings("unused") @Bind("callee.getCode()") PCode code,
106+
@SuppressWarnings("unused") @Cached InlinedBranchProfile initializeCodeProfile,
107+
@SuppressWarnings("unused") @Cached("code.getRootCallTarget()") RootCallTarget ct,
132108
@Cached("createCtInvokeNode(callee)") CallTargetInvokeNode invoke) {
133109
return invoke.execute(frame, callee, callee.getGlobals(), callee.getClosure(), arguments);
134110
}
135111

112+
protected static RootCallTarget getCallTarget(Node inliningTarget, PCode code, InlinedBranchProfile initializeCodeProfile) {
113+
if (code.getRootCallTargetOrNull() == null) {
114+
initializeCodeProfile.enter(inliningTarget);
115+
return code.getRootCallTarget();
116+
}
117+
return code.getRootCallTargetOrNull();
118+
}
119+
136120
@Specialization(guards = {"isSingleContext()", "callee == cachedCallee"}, limit = "getCallSiteInlineCacheMaxDepth()")
137121
protected static Object callBuiltinFunctionCached(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction callee, Object[] arguments,
138122
@SuppressWarnings("unused") @Cached("callee") PBuiltinFunction cachedCallee,
@@ -147,7 +131,7 @@ protected static Object callBuiltinFunctionCachedCt(VirtualFrame frame, @Suppres
147131
return invoke.execute(frame, null, null, null, arguments);
148132
}
149133

150-
@Specialization(replaces = {"callFunctionCached", "callFunctionCachedCode", "callFunctionCachedCt"})
134+
@Specialization(replaces = {"callFunctionCached", "callFunctionCachedCt"})
151135
@Megamorphic
152136
protected static Object callFunctionUncached(Frame frame, PFunction callee, Object[] arguments,
153137
@Shared @Cached GenericInvokeNode invoke) {

0 commit comments

Comments
 (0)