11/*
2- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates.
2+ * Copyright (c) 2017, 2020 , Oracle and/or its affiliates.
33 * Copyright (c) 2014, Regents of the University of California
44 *
55 * All rights reserved.
2727
2828import com .oracle .graal .python .PythonLanguage ;
2929import com .oracle .graal .python .builtins .objects .code .PCode ;
30+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
3031import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
3132import com .oracle .graal .python .builtins .objects .function .PFunction ;
33+ import com .oracle .graal .python .builtins .objects .function .PGeneratorFunction ;
3234import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetFunctionCodeNode ;
3335import com .oracle .graal .python .runtime .PythonOptions ;
3436import com .oracle .truffle .api .Assumption ;
4143import com .oracle .truffle .api .frame .Frame ;
4244import com .oracle .truffle .api .frame .VirtualFrame ;
4345import com .oracle .truffle .api .nodes .Node ;
46+ import com .oracle .truffle .api .profiles .ConditionProfile ;
4447
4548@ ImportStatic (PythonOptions .class )
4649@ ReportPolymorphism
@@ -89,9 +92,13 @@ public final Object executeCall(VirtualFrame frame, PBuiltinFunction callee, Obj
8992
9093 // We only have a single context and this function never changed its code
9194 @ 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 ,
9396 @ 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+ }
95102 return invoke .execute (frame , arguments );
96103 }
97104
@@ -106,15 +113,23 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
106113 @ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
107114 @ SuppressWarnings ("unused" ) @ Cached ("create()" ) GetFunctionCodeNode getFunctionCodeNode ,
108115 @ 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+ }
110121 return invoke .execute (frame , arguments );
111122 }
112123
113124 // We have multiple contexts, don't cache the objects so that contexts can be cleaned up
114125 @ Specialization (guards = {"callee.getCallTarget() == ct" }, limit = "getCallSiteInlineCacheMaxDepth()" , replaces = "callFunctionCachedCode" )
115126 protected Object callFunctionCachedCt (VirtualFrame frame , PFunction callee , Object [] arguments ,
116127 @ 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+ }
118133 return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), arguments );
119134 }
120135
@@ -134,7 +149,11 @@ protected Object callBuiltinFunctionCachedCt(VirtualFrame frame, @SuppressWarnin
134149
135150 @ Specialization (replaces = {"callFunctionCached" , "callFunctionCachedCode" , "callFunctionCachedCt" })
136151 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+ }
138157 return invoke .executeInternal (frame , callee , arguments );
139158 }
140159
0 commit comments