25
25
*/
26
26
package com .oracle .graal .python .nodes .call ;
27
27
28
+ import com .oracle .graal .python .PythonLanguage ;
28
29
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
29
30
import com .oracle .graal .python .builtins .objects .function .PFunction ;
30
31
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
31
32
import com .oracle .graal .python .builtins .objects .function .PythonCallable ;
32
33
import com .oracle .graal .python .builtins .objects .method .PBuiltinMethod ;
33
34
import com .oracle .graal .python .builtins .objects .method .PMethod ;
34
35
import com .oracle .graal .python .runtime .PythonOptions ;
36
+ import com .oracle .truffle .api .Assumption ;
37
+ import com .oracle .truffle .api .RootCallTarget ;
35
38
import com .oracle .truffle .api .dsl .Cached ;
36
39
import com .oracle .truffle .api .dsl .ImportStatic ;
37
40
import com .oracle .truffle .api .dsl .Specialization ;
@@ -45,40 +48,76 @@ protected static InvokeNode createInvokeNode(PythonCallable callee) {
45
48
return InvokeNode .create (callee );
46
49
}
47
50
51
+ protected static CallTargetInvokeNode createCtInvokeNode (PythonCallable callee ) {
52
+ return CallTargetInvokeNode .create (callee );
53
+ }
54
+
48
55
public static CallDispatchNode create () {
49
56
return CallDispatchNodeGen .create ();
50
57
}
51
58
59
+ protected Assumption singleContextAssumption () {
60
+ return PythonLanguage .singleContextAssumption ;
61
+ }
62
+
52
63
public abstract Object executeCall (VirtualFrame frame , Object callee , Object [] arguments , PKeyword [] keywords );
53
64
54
- /**
55
- * We have to treat PMethods specially, because we want the PIC to be on the function, not on
56
- * the (transient) bound method.
57
- */
58
65
@ SuppressWarnings ("unused" )
59
- @ Specialization (guards = "method.getFunction() == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" )
66
+ @ Specialization (guards = "method.getFunction() == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "singleContextAssumption()" )
60
67
protected Object callMethod (VirtualFrame frame , PMethod method , Object [] arguments , PKeyword [] keywords ,
61
68
@ Cached ("method.getFunction()" ) PFunction cachedCallee ,
62
69
@ Cached ("createInvokeNode(cachedCallee)" ) InvokeNode invoke ) {
63
70
return invoke .execute (frame , arguments , keywords );
64
71
}
65
72
66
73
@ SuppressWarnings ("unused" )
67
- @ Specialization (guards = "method.getFunction() == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" )
74
+ @ Specialization (guards = "method.getFunction().getCallTarget() == ct" , limit = "getCallSiteInlineCacheMaxDepth()" )
75
+ protected Object callMethod (VirtualFrame frame , PMethod method , Object [] arguments , PKeyword [] keywords ,
76
+ @ Cached ("method.getFunction().getCallTarget()" ) RootCallTarget ct ,
77
+ @ Cached ("createCtInvokeNode(method)" ) CallTargetInvokeNode invoke ) {
78
+ return invoke .execute (frame , method .getGlobals (), method .getClosure (), method .getArity (), arguments , keywords );
79
+ }
80
+
81
+ @ SuppressWarnings ("unused" )
82
+ @ Specialization (guards = "method.getFunction() == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "singleContextAssumption()" )
68
83
protected Object callBuiltinMethod (VirtualFrame frame , PBuiltinMethod method , Object [] arguments , PKeyword [] keywords ,
69
84
@ Cached ("method.getFunction()" ) PBuiltinFunction cachedCallee ,
70
85
@ Cached ("createInvokeNode(cachedCallee)" ) InvokeNode invoke ) {
71
86
return invoke .execute (frame , arguments , keywords );
72
87
}
73
88
74
89
@ SuppressWarnings ("unused" )
75
- @ Specialization (guards = "callee == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" )
90
+ @ Specialization (guards = "method.getFunction().getCallTarget() == ct" , limit = "getCallSiteInlineCacheMaxDepth()" )
91
+ protected Object callBuiltinMethod (VirtualFrame frame , PBuiltinMethod method , Object [] arguments , PKeyword [] keywords ,
92
+ @ Cached ("method.getFunction().getCallTarget()" ) RootCallTarget ct ,
93
+ @ Cached ("createCtInvokeNode(method)" ) CallTargetInvokeNode invoke ) {
94
+ return invoke .execute (frame , method .getGlobals (), method .getClosure (), method .getArity (), arguments , keywords );
95
+ }
96
+
97
+ @ SuppressWarnings ("unused" )
98
+ @ Specialization (guards = "callee == cachedCallee" , limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "singleContextAssumption()" )
76
99
protected Object callFunction (VirtualFrame frame , PythonCallable callee , Object [] arguments , PKeyword [] keywords ,
77
100
@ Cached ("callee" ) PythonCallable cachedCallee ,
78
101
@ Cached ("createInvokeNode(cachedCallee)" ) InvokeNode invoke ) {
79
102
return invoke .execute (frame , arguments , keywords );
80
103
}
81
104
105
+ @ SuppressWarnings ("unused" )
106
+ @ Specialization (guards = "callee.getCallTarget() == ct" , limit = "getCallSiteInlineCacheMaxDepth()" )
107
+ protected Object callFunction (VirtualFrame frame , PFunction callee , Object [] arguments , PKeyword [] keywords ,
108
+ @ Cached ("callee.getCallTarget()" ) RootCallTarget ct ,
109
+ @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ) {
110
+ return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), callee .getArity (), arguments , keywords );
111
+ }
112
+
113
+ @ SuppressWarnings ("unused" )
114
+ @ Specialization (guards = "callee.getCallTarget() == ct" , limit = "getCallSiteInlineCacheMaxDepth()" )
115
+ protected Object callFunction (VirtualFrame frame , PBuiltinFunction callee , Object [] arguments , PKeyword [] keywords ,
116
+ @ Cached ("callee.getCallTarget()" ) RootCallTarget ct ,
117
+ @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ) {
118
+ return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), callee .getArity (), arguments , keywords );
119
+ }
120
+
82
121
@ Specialization (replaces = {"callMethod" , "callBuiltinMethod" , "callFunction" })
83
122
protected Object callGeneric (VirtualFrame frame , PythonCallable callee , Object [] arguments , PKeyword [] keywords ,
84
123
@ Cached ("create()" ) GenericInvokeNode invoke ) {
0 commit comments