@@ -313,7 +313,7 @@ _PyUOpPrint(const _PyUOpInstruction *uop)
313313 else {
314314 printf ("%s" , name );
315315 }
316- printf (" (%d, target=%d, operand=%" PRIx64 ")" ,
316+ printf (" (%d, target=%d, operand=%# " PRIx64 ")" ,
317317 uop -> oparg ,
318318 uop -> target ,
319319 (uint64_t )uop -> operand );
@@ -528,7 +528,7 @@ translate_bytecode_to_trace(
528528 }
529529#endif
530530
531- DPRINTF (4 ,
531+ DPRINTF (2 ,
532532 "Optimizing %s (%s:%d) at byte offset %d\n" ,
533533 PyUnicode_AsUTF8 (code -> co_qualname ),
534534 PyUnicode_AsUTF8 (code -> co_filename ),
@@ -546,7 +546,7 @@ translate_bytecode_to_trace(
546546 uint32_t oparg = instr -> op .arg ;
547547 uint32_t extended = 0 ;
548548
549- DPRINTF (3 , "%d: %s(%d)\n" , target , _PyOpcode_OpName [opcode ], oparg );
549+ DPRINTF (2 , "%d: %s(%d)\n" , target , _PyOpcode_OpName [opcode ], oparg );
550550
551551 if (opcode == ENTER_EXECUTOR ) {
552552 assert (oparg < 256 );
@@ -606,7 +606,7 @@ translate_bytecode_to_trace(
606606 confidence = confidence * (18 - bitcount ) / 20 ;
607607 }
608608 uint32_t uopcode = BRANCH_TO_GUARD [opcode - POP_JUMP_IF_FALSE ][jump_likely ];
609- DPRINTF (2 , "%d: %s(%d): counter=%x , bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n" ,
609+ DPRINTF (2 , "%d: %s(%d): counter=%04x , bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n" ,
610610 target , _PyOpcode_OpName [opcode ], oparg ,
611611 counter , bitcount , jump_likely , confidence , _PyUOpName (uopcode ));
612612 if (confidence < CONFIDENCE_CUTOFF ) {
@@ -617,7 +617,7 @@ translate_bytecode_to_trace(
617617 _Py_CODEUNIT * next_instr = instr + 1 + _PyOpcode_Caches [_PyOpcode_Deopt [opcode ]];
618618 _Py_CODEUNIT * target_instr = next_instr + oparg ;
619619 if (jump_likely ) {
620- DPRINTF (2 , "Jump likely (%x = %d bits), continue at byte offset %d\n" ,
620+ DPRINTF (2 , "Jump likely (%04x = %d bits), continue at byte offset %d\n" ,
621621 instr [1 ].cache , bitcount , 2 * INSTR_IP (target_instr , code ));
622622 instr = target_instr ;
623623 ADD_TO_TRACE (uopcode , max_length , 0 , INSTR_IP (next_instr , code ));
@@ -716,12 +716,12 @@ translate_bytecode_to_trace(
716716 expansion -> uops [i ].offset );
717717 Py_FatalError ("garbled expansion" );
718718 }
719- ADD_TO_TRACE ( uop , oparg , operand , target );
719+
720720 if (uop == _POP_FRAME ) {
721721 TRACE_STACK_POP ();
722722 /* Set the operand to the function object returned to,
723723 * to assist optimization passes */
724- trace [ trace_length - 1 ]. operand = (uintptr_t )func ;
724+ ADD_TO_TRACE ( uop , oparg , (uintptr_t )func , target ) ;
725725 DPRINTF (2 ,
726726 "Returning to %s (%s:%d) at byte offset %d\n" ,
727727 PyUnicode_AsUTF8 (code -> co_qualname ),
@@ -730,6 +730,7 @@ translate_bytecode_to_trace(
730730 2 * INSTR_IP (instr , code ));
731731 goto top ;
732732 }
733+
733734 if (uop == _PUSH_FRAME ) {
734735 assert (i + 1 == nuops );
735736 int func_version_offset =
@@ -738,7 +739,7 @@ translate_bytecode_to_trace(
738739 + 1 ;
739740 uint32_t func_version = read_u32 (& instr [func_version_offset ].cache );
740741 PyFunctionObject * new_func = _PyFunction_LookupByVersion (func_version );
741- DPRINTF (3 , "Function object: % p\n" , func );
742+ DPRINTF (2 , "Function: version=%#x; object=% p\n" , ( int ) func_version , new_func );
742743 if (new_func != NULL ) {
743744 PyCodeObject * new_code = (PyCodeObject * )PyFunction_GET_CODE (new_func );
744745 if (new_code == code ) {
@@ -748,6 +749,7 @@ translate_bytecode_to_trace(
748749 PyUnicode_AsUTF8 (new_code -> co_filename ),
749750 new_code -> co_firstlineno );
750751 OPT_STAT_INC (recursive_call );
752+ ADD_TO_TRACE (uop , oparg , 0 , target );
751753 ADD_TO_TRACE (_EXIT_TRACE , 0 , 0 , 0 );
752754 goto done ;
753755 }
@@ -756,16 +758,17 @@ translate_bytecode_to_trace(
756758 // Perhaps it may happen again, so don't bother tracing.
757759 // TODO: Reason about this -- is it better to bail or not?
758760 DPRINTF (2 , "Bailing because co_version != func_version\n" );
761+ ADD_TO_TRACE (uop , oparg , 0 , target );
759762 ADD_TO_TRACE (_EXIT_TRACE , 0 , 0 , 0 );
760763 goto done ;
761764 }
762765 // Increment IP to the return address
763766 instr += _PyOpcode_Caches [_PyOpcode_Deopt [opcode ]] + 1 ;
764767 TRACE_STACK_PUSH ();
765768 _Py_BloomFilter_Add (dependencies , new_code );
766- /* Set the operand to the callee's code object,
767- * to assist optimization passes */
768- trace [ trace_length - 1 ]. operand = (uintptr_t )new_func ;
769+ /* Set the operand to the callee's function object,
770+ * to assist optimization passes */
771+ ADD_TO_TRACE ( uop , oparg , (uintptr_t )new_func , target ) ;
769772 code = new_code ;
770773 func = new_func ;
771774 instr = _PyCode_CODE (code );
@@ -777,9 +780,14 @@ translate_bytecode_to_trace(
777780 2 * INSTR_IP (instr , code ));
778781 goto top ;
779782 }
783+ DPRINTF (2 , "Bail, new_func == NULL\n" );
784+ ADD_TO_TRACE (uop , oparg , operand , target );
780785 ADD_TO_TRACE (_EXIT_TRACE , 0 , 0 , 0 );
781786 goto done ;
782787 }
788+
789+ // All other instructions
790+ ADD_TO_TRACE (uop , oparg , operand , target );
783791 }
784792 break ;
785793 }
@@ -803,17 +811,18 @@ translate_bytecode_to_trace(
803811 // Skip short traces like _SET_IP, LOAD_FAST, _SET_IP, _EXIT_TRACE
804812 if (progress_needed || trace_length < 5 ) {
805813 OPT_STAT_INC (trace_too_short );
806- DPRINTF (4 ,
807- "No trace for %s (%s:%d) at byte offset %d\n" ,
814+ DPRINTF (2 ,
815+ "No trace for %s (%s:%d) at byte offset %d (%s) \n" ,
808816 PyUnicode_AsUTF8 (code -> co_qualname ),
809817 PyUnicode_AsUTF8 (code -> co_filename ),
810818 code -> co_firstlineno ,
811- 2 * INSTR_IP (initial_instr , code ));
819+ 2 * INSTR_IP (initial_instr , code ),
820+ progress_needed ? "no progress" : "too short" );
812821 return 0 ;
813822 }
814823 ADD_TO_TRACE (_EXIT_TRACE , 0 , 0 , target );
815824 DPRINTF (1 ,
816- "Created a trace for %s (%s:%d) at byte offset %d -- length %d\n" ,
825+ "Created a proto- trace for %s (%s:%d) at byte offset %d -- length %d\n" ,
817826 PyUnicode_AsUTF8 (code -> co_qualname ),
818827 PyUnicode_AsUTF8 (code -> co_filename ),
819828 code -> co_firstlineno ,
@@ -938,6 +947,8 @@ make_executor_from_uops(_PyUOpInstruction *buffer, const _PyBloomFilter *depende
938947 assert (next_exit == -1 );
939948 assert (dest == executor -> trace );
940949 dest -> opcode = _START_EXECUTOR ;
950+ dest -> oparg = 0 ;
951+ dest -> target = 0 ;
941952 dest -> operand = (uintptr_t )executor ;
942953 _Py_ExecutorInit (executor , dependencies );
943954#ifdef Py_DEBUG
@@ -947,7 +958,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, const _PyBloomFilter *depende
947958 lltrace = * python_lltrace - '0' ; // TODO: Parse an int and all that
948959 }
949960 if (lltrace >= 2 ) {
950- printf ("Optimized executor (length %d):\n" , length );
961+ printf ("Optimized trace (length %d):\n" , length );
951962 for (int i = 0 ; i < length ; i ++ ) {
952963 printf ("%4d OPTIMIZED: " , i );
953964 _PyUOpPrint (& executor -> trace [i ]);
0 commit comments