1
1
/*
2
- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2017, 2020 , Oracle and/or its affiliates.
3
3
* Copyright (c) 2014, Regents of the University of California
4
4
*
5
5
* All rights reserved.
27
27
28
28
import com .oracle .graal .python .PythonLanguage ;
29
29
import com .oracle .graal .python .builtins .objects .code .PCode ;
30
+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
30
31
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
31
32
import com .oracle .graal .python .builtins .objects .function .PFunction ;
33
+ import com .oracle .graal .python .builtins .objects .function .PGeneratorFunction ;
32
34
import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetFunctionCodeNode ;
33
35
import com .oracle .graal .python .runtime .PythonOptions ;
34
36
import com .oracle .truffle .api .Assumption ;
41
43
import com .oracle .truffle .api .frame .Frame ;
42
44
import com .oracle .truffle .api .frame .VirtualFrame ;
43
45
import com .oracle .truffle .api .nodes .Node ;
46
+ import com .oracle .truffle .api .profiles .ConditionProfile ;
44
47
45
48
@ ImportStatic (PythonOptions .class )
46
49
@ ReportPolymorphism
@@ -89,9 +92,13 @@ public final Object executeCall(VirtualFrame frame, PBuiltinFunction callee, Obj
89
92
90
93
// We only have a single context and this function never changed its code
91
94
@ Specialization (guards = {"callee == cachedCallee" }, limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = {"singleContextAssumption()" , "cachedCallee.getCodeStableAssumption()" })
92
- protected Object callFunctionCached (VirtualFrame frame , @ SuppressWarnings ( "unused" ) PFunction callee , Object [] arguments ,
95
+ protected Object callFunctionCached (VirtualFrame frame , PFunction callee , Object [] arguments ,
93
96
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
94
- @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
97
+ @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ,
98
+ @ Cached ConditionProfile isGeneratorProfile ) {
99
+ if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
100
+ PArguments .setGeneratorFunction (arguments , callee );
101
+ }
95
102
return invoke .execute (frame , arguments );
96
103
}
97
104
@@ -106,15 +113,23 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
106
113
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
107
114
@ SuppressWarnings ("unused" ) @ Cached ("create()" ) GetFunctionCodeNode getFunctionCodeNode ,
108
115
@ SuppressWarnings ("unused" ) @ Cached ("getCode(getFunctionCodeNode, callee)" ) PCode cachedCode ,
109
- @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
116
+ @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ,
117
+ @ Cached ConditionProfile isGeneratorProfile ) {
118
+ if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
119
+ PArguments .setGeneratorFunction (arguments , callee );
120
+ }
110
121
return invoke .execute (frame , arguments );
111
122
}
112
123
113
124
// We have multiple contexts, don't cache the objects so that contexts can be cleaned up
114
125
@ Specialization (guards = {"callee.getCallTarget() == ct" }, limit = "getCallSiteInlineCacheMaxDepth()" , replaces = "callFunctionCachedCode" )
115
126
protected Object callFunctionCachedCt (VirtualFrame frame , PFunction callee , Object [] arguments ,
116
127
@ SuppressWarnings ("unused" ) @ Cached ("callee.getCallTarget()" ) RootCallTarget ct ,
117
- @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ) {
128
+ @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ,
129
+ @ Cached ConditionProfile isGeneratorProfile ) {
130
+ if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
131
+ PArguments .setGeneratorFunction (arguments , callee );
132
+ }
118
133
return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), arguments );
119
134
}
120
135
@@ -134,7 +149,11 @@ protected Object callBuiltinFunctionCachedCt(VirtualFrame frame, @SuppressWarnin
134
149
135
150
@ Specialization (replaces = {"callFunctionCached" , "callFunctionCachedCode" , "callFunctionCachedCt" })
136
151
protected Object callFunctionUncached (Frame frame , PFunction callee , Object [] arguments ,
137
- @ Cached GenericInvokeNode invoke ) {
152
+ @ Cached GenericInvokeNode invoke ,
153
+ @ Cached ConditionProfile isGeneratorProfile ) {
154
+ if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
155
+ PArguments .setGeneratorFunction (arguments , callee );
156
+ }
138
157
return invoke .executeInternal (frame , callee , arguments );
139
158
}
140
159
0 commit comments