@@ -107,8 +107,8 @@ jit_compile(
107
107
written ++ ;
108
108
i += caches ;
109
109
}
110
- // Nothing to compile...
111
- if (written == 0 ) {
110
+ // Nothing to compile, or too short to make it worth it!
111
+ if (written <= 2 ) {
112
112
PyMem_Free (trace );
113
113
return 0 ;
114
114
}
@@ -1239,6 +1239,7 @@ IS_FORBIDDEN_OPCODE(int opcode, int nextop)
1239
1239
case GET_ANEXT :
1240
1240
case BEFORE_ASYNC_WITH :
1241
1241
case END_ASYNC_FOR :
1242
+ case GET_YIELD_FROM_ITER :
1242
1243
// Raise keyword
1243
1244
case RAISE_VARARGS :
1244
1245
// Exceptions, we could support these theoretically.
@@ -1638,7 +1639,7 @@ add_metadata_to_jump_2d_array(_PyTier2Info *t2_info, int target_bb_id,
1638
1639
_Py_CODEUNIT * tier1_start )
1639
1640
{
1640
1641
#if BB_DEBUG
1641
- fprintf (stderr , "Attempting to add jump id %d as jump target\n" , meta -> id );
1642
+ fprintf (stderr , "Attempting to add jump id %d as jump target\n" , target_bb_id );
1642
1643
#endif
1643
1644
// Locate where to insert the BB ID
1644
1645
int backward_jump_offset_index = 0 ;
@@ -1658,7 +1659,7 @@ add_metadata_to_jump_2d_array(_PyTier2Info *t2_info, int target_bb_id,
1658
1659
if (t2_info -> backward_jump_target_bb_pairs [backward_jump_offset_index ][jump_i ].id ==
1659
1660
-1 ) {
1660
1661
#if BB_DEBUG
1661
- fprintf (stderr , "Added jump id %d as jump target\n" , meta -> id );
1662
+ fprintf (stderr , "Added jump id %d as jump target\n" , target_bb_id );
1662
1663
#endif
1663
1664
t2_info -> backward_jump_target_bb_pairs [backward_jump_offset_index ][jump_i ].id = target_bb_id ;
1664
1665
t2_info -> backward_jump_target_bb_pairs [backward_jump_offset_index ][jump_i ].start_type_context = starting_context ;
@@ -2383,8 +2384,8 @@ _PyTier2_Code_DetectAndEmitBB(
2383
2384
// Tell BB space the number of bytes we wrote.
2384
2385
bb_space -> water_level += (write_i - t2_start ) * sizeof (_Py_CODEUNIT );
2385
2386
#if BB_DEBUG
2386
- fprintf (stderr , "Generated BB T2 Start: %p, T1 offset: %zu\n" , meta -> tier2_start ,
2387
- meta -> tier1_end - _PyCode_CODE (co ));
2387
+ fprintf (stderr , "Generated BB T2 Start: %p, T1 offset: %zu\n" , metas [ 0 ] -> tier2_start ,
2388
+ metas [ 0 ] -> tier1_end - _PyCode_CODE (co ));
2388
2389
#endif
2389
2390
assert (metas_size >= 0 );
2390
2391
// JIT compile the bb
@@ -3137,9 +3138,9 @@ diff_typecontext(_PyTier2TypeContext *ctx1, _PyTier2TypeContext *ctx2)
3137
3138
* @param tier1_fallback Signals the tier 1 instruction to fall back to should generation fail.
3138
3139
* @param curr Current executing instruction
3139
3140
* @param stacklevel The stack level of the operand stack.
3140
- * @return The next tier 2 instruction to execute .
3141
+ * @return The target BB's metadata .
3141
3142
*/
3142
- _Py_CODEUNIT *
3143
+ _PyTier2BBMetadata *
3143
3144
_PyTier2_LocateJumpBackwardsBB (_PyInterpreterFrame * frame , uint16_t bb_id_tagged , int jumpby ,
3144
3145
_Py_CODEUNIT * * tier1_fallback ,
3145
3146
_Py_CODEUNIT * curr , int stacklevel )
@@ -3265,15 +3266,15 @@ _PyTier2_LocateJumpBackwardsBB(_PyInterpreterFrame *frame, uint16_t bb_id_tagged
3265
3266
}
3266
3267
}
3267
3268
assert (found );
3268
- return meta -> tier2_start ;
3269
+ return meta ;
3269
3270
}
3270
3271
assert (matching_bb_id >= 0 );
3271
3272
assert (matching_bb_id <= t2_info -> bb_data_curr );
3272
3273
#if BB_DEBUG
3273
3274
fprintf (stderr , "Using jump target BB ID: %d\n" , matching_bb_id );
3274
3275
#endif
3275
3276
_PyTier2BBMetadata * target_metadata = t2_info -> bb_data [matching_bb_id ];
3276
- return target_metadata -> tier2_start ;
3277
+ return target_metadata ;
3277
3278
}
3278
3279
3279
3280
@@ -3325,7 +3326,7 @@ _PyTier2_RewriteForwardJump(_Py_CODEUNIT *bb_branch, _Py_CODEUNIT *target)
3325
3326
3326
3327
3327
3328
/**
3328
- * @brief Rewrites a BB_dD_LAZY to a more efficient standard BACKWARD_JUMP.
3329
+ * @brief Rewrites a BB_JUMP_BACKWARD_LAZY to a more efficient standard BACKWARD_JUMP.
3329
3330
*
3330
3331
* Before:
3331
3332
*
@@ -3343,9 +3344,10 @@ _PyTier2_RewriteForwardJump(_Py_CODEUNIT *bb_branch, _Py_CODEUNIT *target)
3343
3344
*
3344
3345
* @param jump_backward_lazy The backwards jump instruction.
3345
3346
* @param target The target we're jumping to.
3347
+ * @param meta The target's BB metadata.
3346
3348
*/
3347
3349
void
3348
- _PyTier2_RewriteBackwardJump (_Py_CODEUNIT * jump_backward_lazy , _Py_CODEUNIT * target )
3350
+ _PyTier2_RewriteBackwardJump (_Py_CODEUNIT * jump_backward_lazy , _Py_CODEUNIT * target , _PyTier2BBMetadata * meta )
3349
3351
{
3350
3352
_Py_CODEUNIT * write_curr = jump_backward_lazy - 1 ;
3351
3353
_Py_CODEUNIT * prev = jump_backward_lazy - 1 ;
@@ -3379,6 +3381,11 @@ _PyTier2_RewriteBackwardJump(_Py_CODEUNIT *jump_backward_lazy, _Py_CODEUNIT *tar
3379
3381
? JUMP_BACKWARD_QUICK
3380
3382
: JUMP_FORWARD );
3381
3383
write_curr -> op .arg = oparg & 0xFF ;
3384
+ write_curr ++ ;
3385
+ _PyBBBranchCache * cache = (_PyBBBranchCache * )write_curr ;
3386
+ if (meta != NULL && is_backwards_jump ) {
3387
+ write_obj (cache -> consequent_trace , (PyObject * )meta -> machine_code );
3388
+ }
3382
3389
return ;
3383
3390
}
3384
3391
0 commit comments