1
1
/*
2
- * Copyright (c) 2017, 2023 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2025 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2014, Regents of the University of California
4
4
*
5
5
* All rights reserved.
25
25
*/
26
26
package com .oracle .graal .python .nodes .call ;
27
27
28
- import com .oracle .graal .python .builtins .objects .code .CodeNodes .GetCodeCallTargetNode ;
29
28
import com .oracle .graal .python .builtins .objects .code .PCode ;
30
29
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
31
30
import com .oracle .graal .python .builtins .objects .function .PFunction ;
32
31
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 ;
35
32
import com .oracle .graal .python .runtime .PythonOptions ;
36
- import com .oracle .truffle .api .CompilerAsserts ;
37
33
import com .oracle .truffle .api .RootCallTarget ;
38
34
import com .oracle .truffle .api .dsl .Bind ;
39
35
import com .oracle .truffle .api .dsl .Cached ;
46
42
import com .oracle .truffle .api .frame .Frame ;
47
43
import com .oracle .truffle .api .frame .VirtualFrame ;
48
44
import com .oracle .truffle .api .nodes .Node ;
45
+ import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
49
46
50
47
@ ImportStatic (PythonOptions .class )
51
48
@ GenerateUncached
@@ -101,38 +98,25 @@ protected static Object callFunctionCached(VirtualFrame frame, @SuppressWarnings
101
98
return invoke .execute (frame , arguments );
102
99
}
103
100
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
-
126
101
// 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 " )
128
103
protected static Object callFunctionCachedCt (VirtualFrame frame , PFunction callee , Object [] arguments ,
129
104
@ 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 ,
132
108
@ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ) {
133
109
return invoke .execute (frame , callee , callee .getGlobals (), callee .getClosure (), arguments );
134
110
}
135
111
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
+
136
120
@ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" }, limit = "getCallSiteInlineCacheMaxDepth()" )
137
121
protected static Object callBuiltinFunctionCached (VirtualFrame frame , @ SuppressWarnings ("unused" ) PBuiltinFunction callee , Object [] arguments ,
138
122
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PBuiltinFunction cachedCallee ,
@@ -147,7 +131,7 @@ protected static Object callBuiltinFunctionCachedCt(VirtualFrame frame, @Suppres
147
131
return invoke .execute (frame , null , null , null , arguments );
148
132
}
149
133
150
- @ Specialization (replaces = {"callFunctionCached" , "callFunctionCachedCode" , " callFunctionCachedCt" })
134
+ @ Specialization (replaces = {"callFunctionCached" , "callFunctionCachedCt" })
151
135
@ Megamorphic
152
136
protected static Object callFunctionUncached (Frame frame , PFunction callee , Object [] arguments ,
153
137
@ Shared @ Cached GenericInvokeNode invoke ) {
0 commit comments