@@ -181,6 +181,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
181
181
}
182
182
insert_executor (code , src , index , executor );
183
183
assert (frame -> prev_instr == src );
184
+ frame -> prev_instr = dest - 1 ;
184
185
return executor -> execute (executor , frame , stack_pointer );
185
186
jump_to_destination :
186
187
frame -> prev_instr = dest - 1 ;
@@ -201,7 +202,7 @@ PyUnstable_GetExecutor(PyCodeObject *code, int offset)
201
202
}
202
203
i += _PyInstruction_GetLength (code , i );
203
204
}
204
- PyErr_SetString (PyExc_ValueError , "no executor at given offset" );
205
+ PyErr_SetString (PyExc_ValueError , "no executor at given byte offset" );
205
206
return NULL ;
206
207
}
207
208
@@ -399,22 +400,28 @@ translate_bytecode_to_trace(
399
400
trace_length++;
400
401
401
402
DPRINTF (4 ,
402
- "Optimizing %s (%s:%d) at offset %ld\n" ,
403
+ "Optimizing %s (%s:%d) at byte offset %ld\n" ,
403
404
PyUnicode_AsUTF8 (code -> co_qualname ),
404
405
PyUnicode_AsUTF8 (code -> co_filename ),
405
406
code -> co_firstlineno ,
406
- (long )(instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
407
+ 2 * (long )(initial_instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
407
408
408
409
for (;;) {
409
410
ADD_TO_TRACE (SAVE_IP , (int )(instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
410
411
int opcode = instr -> op .code ;
411
412
uint64_t operand = instr -> op .arg ;
412
- // TODO: EXTENDED_ARG handling
413
+ int extras = 0 ;
414
+ while (opcode == EXTENDED_ARG ) {
415
+ instr ++ ;
416
+ extras += 1 ;
417
+ opcode = instr -> op .code ;
418
+ operand = (operand << 8 ) | instr -> op .arg ;
419
+ }
413
420
if (opcode == ENTER_EXECUTOR ) {
414
421
_PyExecutorObject * executor = (_PyExecutorObject * )code -> co_executors -> executors [operand & 255 ];
415
422
opcode = executor -> vm_data .opcode ;
416
423
DPRINTF (2 , " * ENTER_EXECUTOR -> %s\n" , _PyOpcode_OpName [opcode ]);
417
- operand = executor -> vm_data .oparg ; // TODO: EXTENDED_ARG handling
424
+ operand = ( operand & 0xffffff00 ) | executor -> vm_data .oparg ;
418
425
}
419
426
switch (opcode ) {
420
427
case LOAD_FAST_LOAD_FAST :
@@ -474,6 +481,15 @@ translate_bytecode_to_trace(
474
481
int offset = expansion -> uops [i ].offset ;
475
482
switch (expansion -> uops [i ].size ) {
476
483
case 0 :
484
+ if (extras && OPCODE_HAS_JUMP (opcode )) {
485
+ if (opcode == JUMP_BACKWARD_NO_INTERRUPT ) {
486
+ operand -= extras ;
487
+ }
488
+ else {
489
+ assert (opcode != JUMP_BACKWARD );
490
+ operand += extras ;
491
+ }
492
+ }
477
493
break ;
478
494
case 1 :
479
495
operand = read_u16 (& instr [offset ].cache );
@@ -512,21 +528,21 @@ translate_bytecode_to_trace(
512
528
if (trace_length > 3 ) {
513
529
ADD_TO_TRACE (EXIT_TRACE , 0 );
514
530
DPRINTF (1 ,
515
- "Created a trace for %s (%s:%d) at offset %ld -- length %d\n" ,
531
+ "Created a trace for %s (%s:%d) at byte offset %ld -- length %d\n" ,
516
532
PyUnicode_AsUTF8 (code -> co_qualname ),
517
533
PyUnicode_AsUTF8 (code -> co_filename ),
518
534
code -> co_firstlineno ,
519
- (long )(instr - (_Py_CODEUNIT * )code -> co_code_adaptive ),
535
+ 2 * (long )(initial_instr - (_Py_CODEUNIT * )code -> co_code_adaptive ),
520
536
trace_length );
521
537
return trace_length ;
522
538
}
523
539
else {
524
540
DPRINTF (4 ,
525
- "No trace for %s (%s:%d) at offset %ld\n" ,
541
+ "No trace for %s (%s:%d) at byte offset %ld\n" ,
526
542
PyUnicode_AsUTF8 (code -> co_qualname ),
527
543
PyUnicode_AsUTF8 (code -> co_filename ),
528
544
code -> co_firstlineno ,
529
- (long )(instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
545
+ 2 * (long )(initial_instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
530
546
}
531
547
return 0 ;
532
548
0 commit comments