5252import com .oracle .graal .python .runtime .PythonOptions ;
5353import com .oracle .graal .python .runtime .object .PFactory ;
5454import com .oracle .graal .python .util .PythonUtils ;
55+ import com .oracle .truffle .api .CompilerAsserts ;
5556import com .oracle .truffle .api .Truffle ;
5657import com .oracle .truffle .api .bytecode .BytecodeNode ;
5758import com .oracle .truffle .api .dsl .Bind ;
6768import com .oracle .truffle .api .frame .Frame ;
6869import com .oracle .truffle .api .frame .FrameDescriptor ;
6970import com .oracle .truffle .api .frame .MaterializedFrame ;
70- import com .oracle .truffle .api .nodes .ExplodeLoop ;
7171import com .oracle .truffle .api .nodes .Node ;
72- import com .oracle .truffle .api .nodes .RootNode ;
7372import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
73+ import com .oracle .truffle .api .profiles .InlinedIntValueProfile ;
74+ import com .oracle .truffle .api .profiles .ValueProfile ;
7475
7576/**
7677 * This node makes sure that the current frame has a filled-in PFrame object with a backref
@@ -125,14 +126,17 @@ public final PFrame executeOnStack(Frame frameToMaterialize, PRootNode location,
125126 * root nodes, we fetch the root node from the frame descriptor.
126127 */
127128 public final PFrame executeOnStack (boolean markAsEscaped , boolean forceSync , Frame frameToMaterialize ) {
128- Node location ;
129- RootNode rootNode = PArguments .getCurrentFrameInfo (frameToMaterialize ).getRootNode ();
130- if (PythonOptions .ENABLE_BYTECODE_DSL_INTERPRETER && PGenerator .unwrapContinuationRoot (rootNode ) instanceof PBytecodeDSLRootNode ) {
131- assert this .isAdoptable ();
132- location = BytecodeNode .get (this );
133- assert location != null ;
129+ Node location = this ;
130+ if (!PythonOptions .ENABLE_BYTECODE_DSL_INTERPRETER ) {
131+ if (!location .isAdoptable ()) {
132+ // This should only happen in uncached manual bytecode interpreter, we are fine with
133+ // root node in such case
134+ location = PArguments .getCurrentFrameInfo (frameToMaterialize ).getRootNode ();
135+ }
134136 } else {
135- location = rootNode ;
137+ // We will need EncapsulatingNodeReference or thread the BytecodeNode as argument for
138+ // BytecodeDSL uncached execution
139+ assert this .isAdoptable ();
136140 }
137141 return execute (location , markAsEscaped , forceSync , frameToMaterialize );
138142 }
@@ -155,29 +159,17 @@ public final PFrame execute(Node location, boolean markAsEscaped, boolean forceS
155159
156160 abstract PFrame executeImpl (Node location , boolean markAsEscaped , boolean forceSync , Frame frameToMaterialize );
157161
158- @ Specialization (guards = {
159- "cachedFD == frameToMaterialize.getFrameDescriptor()" , //
160- "getPFrame(frameToMaterialize) == null" , //
161- "!isGeneratorFrame(frameToMaterialize)" , //
162- "!hasCustomLocals(frameToMaterialize)" }, limit = "1" )
162+ @ Specialization (guards = {"getPFrame(frameToMaterialize) == null" , "!isGeneratorFrame(frameToMaterialize)" , "!hasCustomLocals(frameToMaterialize)" })
163163 static PFrame freshPFrameCachedFD (Node location , boolean markAsEscaped , boolean forceSync , Frame frameToMaterialize ,
164- @ Cached (value = "frameToMaterialize.getFrameDescriptor()" ) FrameDescriptor cachedFD ,
165164 @ Bind PythonLanguage language ,
165+ @ Cached (inline = false ) ValueProfile cachedFDProfile ,
166166 @ Shared ("syncValuesNode" ) @ Cached SyncFrameValuesNode syncValuesNode ) {
167+ FrameDescriptor cachedFD = cachedFDProfile .profile (frameToMaterialize .getFrameDescriptor ());
167168 MaterializedFrame locals = createLocalsFrame (cachedFD );
168169 PFrame escapedFrame = PFactory .createPFrame (language , PArguments .getCurrentFrameInfo (frameToMaterialize ), location , locals );
169170 return doEscapeFrame (frameToMaterialize , escapedFrame , markAsEscaped , forceSync , location , syncValuesNode );
170171 }
171172
172- @ Specialization (guards = {"getPFrame(frameToMaterialize) == null" , "!isGeneratorFrame(frameToMaterialize)" , "!hasCustomLocals(frameToMaterialize)" }, replaces = "freshPFrameCachedFD" )
173- static PFrame freshPFrame (Node location , boolean markAsEscaped , boolean forceSync , Frame frameToMaterialize ,
174- @ Bind PythonLanguage language ,
175- @ Shared ("syncValuesNode" ) @ Cached SyncFrameValuesNode syncValuesNode ) {
176- MaterializedFrame locals = createLocalsFrame (frameToMaterialize .getFrameDescriptor ());
177- PFrame escapedFrame = PFactory .createPFrame (language , PArguments .getCurrentFrameInfo (frameToMaterialize ), location , locals );
178- return doEscapeFrame (frameToMaterialize , escapedFrame , markAsEscaped , forceSync , location , syncValuesNode );
179- }
180-
181173 @ Specialization (guards = {"getPFrame(frameToMaterialize) == null" , "!isGeneratorFrame(frameToMaterialize)" , "hasCustomLocals(frameToMaterialize)" })
182174 static PFrame freshPFrameCusstomLocals (Node location , boolean markAsEscaped , @ SuppressWarnings ("unused" ) boolean forceSync ,
183175 Frame frameToMaterialize ,
@@ -231,6 +223,7 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
231223 if (PythonOptions .ENABLE_BYTECODE_DSL_INTERPRETER ) {
232224 BytecodeNode bytecodeNode ;
233225 assert !(location instanceof PBytecodeDSLRootNode ); // we need BytecodeNode or its child
226+ CompilerAsserts .partialEvaluationConstant (location );
234227 bytecodeNode = BytecodeNode .get (location );
235228 if (bytecodeNode != null ) {
236229 pyFrame .setBci (bytecodeNode .getBytecodeIndex (frameToMaterialize ));
@@ -284,14 +277,15 @@ public abstract static class SyncFrameValuesNode extends Node {
284277
285278 public abstract void execute (PFrame pyFrame , Frame frameToSync );
286279
287- @ Specialization (guards = {"!pyFrame.hasCustomLocals()" ,
288- "frameToSync.getFrameDescriptor() == cachedFd" }, limit = "1" )
289- @ ExplodeLoop
290- static void doSyncCached (PFrame pyFrame , Frame frameToSync ,
291- @ Cached (value = "frameToSync.getFrameDescriptor()" ) FrameDescriptor cachedFd ) {
280+ @ Specialization (guards = "!pyFrame.hasCustomLocals()" )
281+ static void doSync (PFrame pyFrame , Frame frameToSync ,
282+ @ Bind Node inliningTarget ,
283+ @ Cached (inline = false ) ValueProfile frameDescriptorProfile ,
284+ @ Cached InlinedIntValueProfile slotCountProfile ) {
285+ FrameDescriptor cachedFd = frameDescriptorProfile .profile (frameToSync .getFrameDescriptor ());
292286 MaterializedFrame target = pyFrame .getLocals ();
293287 assert cachedFd == target .getFrameDescriptor ();
294- int slotCount = variableSlotCount (cachedFd );
288+ int slotCount = slotCountProfile . profile ( inliningTarget , variableSlotCount (cachedFd ) );
295289
296290 if (PythonOptions .ENABLE_BYTECODE_DSL_INTERPRETER ) {
297291 FrameInfo info = (FrameInfo ) cachedFd .getInfo ();
@@ -304,12 +298,6 @@ static void doSyncCached(PFrame pyFrame, Frame frameToSync,
304298 }
305299 }
306300
307- @ Specialization (guards = "!pyFrame.hasCustomLocals()" , replaces = "doSyncCached" )
308- @ ExplodeLoop
309- static void doSync (PFrame pyFrame , Frame frameToSync ) {
310- doSyncCached (pyFrame , frameToSync , frameToSync .getFrameDescriptor ());
311- }
312-
313301 @ Specialization (guards = "pyFrame.hasCustomLocals()" )
314302 @ SuppressWarnings ("unused" )
315303 static void doCustomLocals (PFrame pyFrame , Frame frameToSync ) {
0 commit comments