From 43ec16750c612d3a5e5ad1962002f834baff4d2e Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 3 May 2025 13:34:52 +0200 Subject: [PATCH 1/8] Split CALL_ISIINSTANCE into several uops --- Include/internal/pycore_opcode_metadata.h | 2 +- Include/internal/pycore_uop_ids.h | 388 +++++++++++----------- Include/internal/pycore_uop_metadata.h | 10 +- Lib/test/test_capi/test_opt.py | 17 + Python/bytecodes.c | 40 ++- Python/executor_cases.c.h | 73 ++-- Python/generated_cases.c.h | 90 +++-- Python/optimizer_bytecodes.c | 15 + Python/optimizer_cases.c.h | 21 ++ Python/specialize.c | 2 +- 10 files changed, 367 insertions(+), 291 deletions(-) diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index 4006a99382d18a..7f6822e1c071cb 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -1363,7 +1363,7 @@ _PyOpcode_macro_expansion[256] = { [CALL_BUILTIN_O] = { .nuops = 2, .uops = { { _CALL_BUILTIN_O, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC, OPARG_SIMPLE, 3 } } }, [CALL_INTRINSIC_1] = { .nuops = 1, .uops = { { _CALL_INTRINSIC_1, OPARG_SIMPLE, 0 } } }, [CALL_INTRINSIC_2] = { .nuops = 1, .uops = { { _CALL_INTRINSIC_2, OPARG_SIMPLE, 0 } } }, - [CALL_ISINSTANCE] = { .nuops = 1, .uops = { { _CALL_ISINSTANCE, OPARG_SIMPLE, 3 } } }, + [CALL_ISINSTANCE] = { .nuops = 3, .uops = { { _GUARD_CALLABLE_ISINSTANCE_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_ISINSTANCE, OPARG_SIMPLE, 3 }, { _CALL_ISINSTANCE, OPARG_SIMPLE, 3 } } }, [CALL_KW_BOUND_METHOD] = { .nuops = 6, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 1 }, { _CHECK_METHOD_VERSION_KW, 2, 1 }, { _EXPAND_METHOD_KW, OPARG_SIMPLE, 3 }, { _PY_FRAME_KW, OPARG_SIMPLE, 3 }, { _SAVE_RETURN_OFFSET, OPARG_SAVE_RETURN_OFFSET, 3 }, { _PUSH_FRAME, OPARG_SIMPLE, 3 } } }, [CALL_KW_NON_PY] = { .nuops = 3, .uops = { { _CHECK_IS_NOT_PY_CALLABLE_KW, OPARG_SIMPLE, 3 }, { _CALL_KW_NON_PY, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC, OPARG_SIMPLE, 3 } } }, [CALL_KW_PY] = { .nuops = 5, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 1 }, { _CHECK_FUNCTION_VERSION_KW, 2, 1 }, { _PY_FRAME_KW, OPARG_SIMPLE, 3 }, { _SAVE_RETURN_OFFSET, OPARG_SAVE_RETURN_OFFSET, 3 }, { _PUSH_FRAME, OPARG_SIMPLE, 3 } } }, diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index b4eef763da34ed..f90577e0853dde 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -43,124 +43,126 @@ extern "C" { #define _CALL_BUILTIN_O 323 #define _CALL_INTRINSIC_1 CALL_INTRINSIC_1 #define _CALL_INTRINSIC_2 CALL_INTRINSIC_2 -#define _CALL_ISINSTANCE CALL_ISINSTANCE -#define _CALL_KW_NON_PY 324 +#define _CALL_ISINSTANCE 324 +#define _CALL_KW_NON_PY 325 #define _CALL_LEN CALL_LEN #define _CALL_LIST_APPEND CALL_LIST_APPEND -#define _CALL_METHOD_DESCRIPTOR_FAST 325 -#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 326 -#define _CALL_METHOD_DESCRIPTOR_NOARGS 327 -#define _CALL_METHOD_DESCRIPTOR_O 328 -#define _CALL_NON_PY_GENERAL 329 -#define _CALL_STR_1 330 -#define _CALL_TUPLE_1 331 -#define _CALL_TYPE_1 332 -#define _CHECK_AND_ALLOCATE_OBJECT 333 -#define _CHECK_ATTR_CLASS 334 -#define _CHECK_ATTR_METHOD_LAZY_DICT 335 -#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 336 +#define _CALL_METHOD_DESCRIPTOR_FAST 326 +#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 327 +#define _CALL_METHOD_DESCRIPTOR_NOARGS 328 +#define _CALL_METHOD_DESCRIPTOR_O 329 +#define _CALL_NON_PY_GENERAL 330 +#define _CALL_STR_1 331 +#define _CALL_TUPLE_1 332 +#define _CALL_TYPE_1 333 +#define _CHECK_AND_ALLOCATE_OBJECT 334 +#define _CHECK_ATTR_CLASS 335 +#define _CHECK_ATTR_METHOD_LAZY_DICT 336 +#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 337 #define _CHECK_EG_MATCH CHECK_EG_MATCH #define _CHECK_EXC_MATCH CHECK_EXC_MATCH -#define _CHECK_FUNCTION 337 -#define _CHECK_FUNCTION_EXACT_ARGS 338 -#define _CHECK_FUNCTION_VERSION 339 -#define _CHECK_FUNCTION_VERSION_INLINE 340 -#define _CHECK_FUNCTION_VERSION_KW 341 -#define _CHECK_IS_NOT_PY_CALLABLE 342 -#define _CHECK_IS_NOT_PY_CALLABLE_KW 343 -#define _CHECK_MANAGED_OBJECT_HAS_VALUES 344 -#define _CHECK_METHOD_VERSION 345 -#define _CHECK_METHOD_VERSION_KW 346 -#define _CHECK_PEP_523 347 -#define _CHECK_PERIODIC 348 -#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 349 -#define _CHECK_RECURSION_REMAINING 350 -#define _CHECK_STACK_SPACE 351 -#define _CHECK_STACK_SPACE_OPERAND 352 -#define _CHECK_VALIDITY 353 -#define _COMPARE_OP 354 -#define _COMPARE_OP_FLOAT 355 -#define _COMPARE_OP_INT 356 -#define _COMPARE_OP_STR 357 -#define _CONTAINS_OP 358 -#define _CONTAINS_OP_DICT 359 -#define _CONTAINS_OP_SET 360 +#define _CHECK_FUNCTION 338 +#define _CHECK_FUNCTION_EXACT_ARGS 339 +#define _CHECK_FUNCTION_VERSION 340 +#define _CHECK_FUNCTION_VERSION_INLINE 341 +#define _CHECK_FUNCTION_VERSION_KW 342 +#define _CHECK_IS_NOT_PY_CALLABLE 343 +#define _CHECK_IS_NOT_PY_CALLABLE_KW 344 +#define _CHECK_MANAGED_OBJECT_HAS_VALUES 345 +#define _CHECK_METHOD_VERSION 346 +#define _CHECK_METHOD_VERSION_KW 347 +#define _CHECK_PEP_523 348 +#define _CHECK_PERIODIC 349 +#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 350 +#define _CHECK_RECURSION_REMAINING 351 +#define _CHECK_STACK_SPACE 352 +#define _CHECK_STACK_SPACE_OPERAND 353 +#define _CHECK_VALIDITY 354 +#define _COMPARE_OP 355 +#define _COMPARE_OP_FLOAT 356 +#define _COMPARE_OP_INT 357 +#define _COMPARE_OP_STR 358 +#define _CONTAINS_OP 359 +#define _CONTAINS_OP_DICT 360 +#define _CONTAINS_OP_SET 361 #define _CONVERT_VALUE CONVERT_VALUE #define _COPY COPY #define _COPY_FREE_VARS COPY_FREE_VARS -#define _CREATE_INIT_FRAME 361 +#define _CREATE_INIT_FRAME 362 #define _DELETE_ATTR DELETE_ATTR #define _DELETE_DEREF DELETE_DEREF #define _DELETE_FAST DELETE_FAST #define _DELETE_GLOBAL DELETE_GLOBAL #define _DELETE_NAME DELETE_NAME #define _DELETE_SUBSCR DELETE_SUBSCR -#define _DEOPT 362 +#define _DEOPT 363 #define _DICT_MERGE DICT_MERGE #define _DICT_UPDATE DICT_UPDATE -#define _DO_CALL 363 -#define _DO_CALL_FUNCTION_EX 364 -#define _DO_CALL_KW 365 +#define _DO_CALL 364 +#define _DO_CALL_FUNCTION_EX 365 +#define _DO_CALL_KW 366 #define _END_FOR END_FOR #define _END_SEND END_SEND -#define _ERROR_POP_N 366 +#define _ERROR_POP_N 367 #define _EXIT_INIT_CHECK EXIT_INIT_CHECK -#define _EXPAND_METHOD 367 -#define _EXPAND_METHOD_KW 368 -#define _FATAL_ERROR 369 +#define _EXPAND_METHOD 368 +#define _EXPAND_METHOD_KW 369 +#define _FATAL_ERROR 370 #define _FORMAT_SIMPLE FORMAT_SIMPLE #define _FORMAT_WITH_SPEC FORMAT_WITH_SPEC -#define _FOR_ITER 370 -#define _FOR_ITER_GEN_FRAME 371 -#define _FOR_ITER_TIER_TWO 372 +#define _FOR_ITER 371 +#define _FOR_ITER_GEN_FRAME 372 +#define _FOR_ITER_TIER_TWO 373 #define _GET_AITER GET_AITER #define _GET_ANEXT GET_ANEXT #define _GET_AWAITABLE GET_AWAITABLE #define _GET_ITER GET_ITER #define _GET_LEN GET_LEN #define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER -#define _GUARD_BINARY_OP_EXTEND 373 -#define _GUARD_CALLABLE_STR_1 374 -#define _GUARD_CALLABLE_TUPLE_1 375 -#define _GUARD_CALLABLE_TYPE_1 376 -#define _GUARD_DORV_NO_DICT 377 -#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 378 -#define _GUARD_GLOBALS_VERSION 379 -#define _GUARD_IS_FALSE_POP 380 -#define _GUARD_IS_NONE_POP 381 -#define _GUARD_IS_NOT_NONE_POP 382 -#define _GUARD_IS_TRUE_POP 383 -#define _GUARD_KEYS_VERSION 384 -#define _GUARD_NOS_DICT 385 -#define _GUARD_NOS_FLOAT 386 -#define _GUARD_NOS_INT 387 -#define _GUARD_NOS_LIST 388 -#define _GUARD_NOS_NULL 389 -#define _GUARD_NOS_TUPLE 390 -#define _GUARD_NOS_UNICODE 391 -#define _GUARD_NOT_EXHAUSTED_LIST 392 -#define _GUARD_NOT_EXHAUSTED_RANGE 393 -#define _GUARD_NOT_EXHAUSTED_TUPLE 394 -#define _GUARD_TOS_ANY_SET 395 -#define _GUARD_TOS_DICT 396 -#define _GUARD_TOS_FLOAT 397 -#define _GUARD_TOS_INT 398 -#define _GUARD_TOS_LIST 399 -#define _GUARD_TOS_SLICE 400 -#define _GUARD_TOS_TUPLE 401 -#define _GUARD_TOS_UNICODE 402 -#define _GUARD_TYPE_VERSION 403 -#define _GUARD_TYPE_VERSION_AND_LOCK 404 +#define _GUARD_BINARY_OP_EXTEND 374 +#define _GUARD_CALLABLE_ISINSTANCE 375 +#define _GUARD_CALLABLE_ISINSTANCE_NULL 376 +#define _GUARD_CALLABLE_STR_1 377 +#define _GUARD_CALLABLE_TUPLE_1 378 +#define _GUARD_CALLABLE_TYPE_1 379 +#define _GUARD_DORV_NO_DICT 380 +#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 381 +#define _GUARD_GLOBALS_VERSION 382 +#define _GUARD_IS_FALSE_POP 383 +#define _GUARD_IS_NONE_POP 384 +#define _GUARD_IS_NOT_NONE_POP 385 +#define _GUARD_IS_TRUE_POP 386 +#define _GUARD_KEYS_VERSION 387 +#define _GUARD_NOS_DICT 388 +#define _GUARD_NOS_FLOAT 389 +#define _GUARD_NOS_INT 390 +#define _GUARD_NOS_LIST 391 +#define _GUARD_NOS_NULL 392 +#define _GUARD_NOS_TUPLE 393 +#define _GUARD_NOS_UNICODE 394 +#define _GUARD_NOT_EXHAUSTED_LIST 395 +#define _GUARD_NOT_EXHAUSTED_RANGE 396 +#define _GUARD_NOT_EXHAUSTED_TUPLE 397 +#define _GUARD_TOS_ANY_SET 398 +#define _GUARD_TOS_DICT 399 +#define _GUARD_TOS_FLOAT 400 +#define _GUARD_TOS_INT 401 +#define _GUARD_TOS_LIST 402 +#define _GUARD_TOS_SLICE 403 +#define _GUARD_TOS_TUPLE 404 +#define _GUARD_TOS_UNICODE 405 +#define _GUARD_TYPE_VERSION 406 +#define _GUARD_TYPE_VERSION_AND_LOCK 407 #define _IMPORT_FROM IMPORT_FROM #define _IMPORT_NAME IMPORT_NAME -#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 405 -#define _INIT_CALL_PY_EXACT_ARGS 406 -#define _INIT_CALL_PY_EXACT_ARGS_0 407 -#define _INIT_CALL_PY_EXACT_ARGS_1 408 -#define _INIT_CALL_PY_EXACT_ARGS_2 409 -#define _INIT_CALL_PY_EXACT_ARGS_3 410 -#define _INIT_CALL_PY_EXACT_ARGS_4 411 -#define _INSERT_NULL 412 +#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 408 +#define _INIT_CALL_PY_EXACT_ARGS 409 +#define _INIT_CALL_PY_EXACT_ARGS_0 410 +#define _INIT_CALL_PY_EXACT_ARGS_1 411 +#define _INIT_CALL_PY_EXACT_ARGS_2 412 +#define _INIT_CALL_PY_EXACT_ARGS_3 413 +#define _INIT_CALL_PY_EXACT_ARGS_4 414 +#define _INSERT_NULL 415 #define _INSTRUMENTED_FOR_ITER INSTRUMENTED_FOR_ITER #define _INSTRUMENTED_INSTRUCTION INSTRUMENTED_INSTRUCTION #define _INSTRUMENTED_JUMP_FORWARD INSTRUMENTED_JUMP_FORWARD @@ -170,163 +172,163 @@ extern "C" { #define _INSTRUMENTED_POP_JUMP_IF_NONE INSTRUMENTED_POP_JUMP_IF_NONE #define _INSTRUMENTED_POP_JUMP_IF_NOT_NONE INSTRUMENTED_POP_JUMP_IF_NOT_NONE #define _INSTRUMENTED_POP_JUMP_IF_TRUE INSTRUMENTED_POP_JUMP_IF_TRUE -#define _IS_NONE 413 +#define _IS_NONE 416 #define _IS_OP IS_OP -#define _ITER_CHECK_LIST 414 -#define _ITER_CHECK_RANGE 415 -#define _ITER_CHECK_TUPLE 416 -#define _ITER_JUMP_LIST 417 -#define _ITER_JUMP_RANGE 418 -#define _ITER_JUMP_TUPLE 419 -#define _ITER_NEXT_LIST 420 -#define _ITER_NEXT_LIST_TIER_TWO 421 -#define _ITER_NEXT_RANGE 422 -#define _ITER_NEXT_TUPLE 423 -#define _JUMP_TO_TOP 424 +#define _ITER_CHECK_LIST 417 +#define _ITER_CHECK_RANGE 418 +#define _ITER_CHECK_TUPLE 419 +#define _ITER_JUMP_LIST 420 +#define _ITER_JUMP_RANGE 421 +#define _ITER_JUMP_TUPLE 422 +#define _ITER_NEXT_LIST 423 +#define _ITER_NEXT_LIST_TIER_TWO 424 +#define _ITER_NEXT_RANGE 425 +#define _ITER_NEXT_TUPLE 426 +#define _JUMP_TO_TOP 427 #define _LIST_APPEND LIST_APPEND #define _LIST_EXTEND LIST_EXTEND -#define _LOAD_ATTR 425 -#define _LOAD_ATTR_CLASS 426 +#define _LOAD_ATTR 428 +#define _LOAD_ATTR_CLASS 429 #define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN -#define _LOAD_ATTR_INSTANCE_VALUE 427 -#define _LOAD_ATTR_METHOD_LAZY_DICT 428 -#define _LOAD_ATTR_METHOD_NO_DICT 429 -#define _LOAD_ATTR_METHOD_WITH_VALUES 430 -#define _LOAD_ATTR_MODULE 431 -#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 432 -#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 433 -#define _LOAD_ATTR_PROPERTY_FRAME 434 -#define _LOAD_ATTR_SLOT 435 -#define _LOAD_ATTR_WITH_HINT 436 +#define _LOAD_ATTR_INSTANCE_VALUE 430 +#define _LOAD_ATTR_METHOD_LAZY_DICT 431 +#define _LOAD_ATTR_METHOD_NO_DICT 432 +#define _LOAD_ATTR_METHOD_WITH_VALUES 433 +#define _LOAD_ATTR_MODULE 434 +#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 435 +#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 436 +#define _LOAD_ATTR_PROPERTY_FRAME 437 +#define _LOAD_ATTR_SLOT 438 +#define _LOAD_ATTR_WITH_HINT 439 #define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS -#define _LOAD_BYTECODE 437 +#define _LOAD_BYTECODE 440 #define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT #define _LOAD_CONST LOAD_CONST #define _LOAD_CONST_IMMORTAL LOAD_CONST_IMMORTAL -#define _LOAD_CONST_INLINE 438 -#define _LOAD_CONST_INLINE_BORROW 439 +#define _LOAD_CONST_INLINE 441 +#define _LOAD_CONST_INLINE_BORROW 442 #define _LOAD_CONST_MORTAL LOAD_CONST_MORTAL #define _LOAD_DEREF LOAD_DEREF -#define _LOAD_FAST 440 -#define _LOAD_FAST_0 441 -#define _LOAD_FAST_1 442 -#define _LOAD_FAST_2 443 -#define _LOAD_FAST_3 444 -#define _LOAD_FAST_4 445 -#define _LOAD_FAST_5 446 -#define _LOAD_FAST_6 447 -#define _LOAD_FAST_7 448 +#define _LOAD_FAST 443 +#define _LOAD_FAST_0 444 +#define _LOAD_FAST_1 445 +#define _LOAD_FAST_2 446 +#define _LOAD_FAST_3 447 +#define _LOAD_FAST_4 448 +#define _LOAD_FAST_5 449 +#define _LOAD_FAST_6 450 +#define _LOAD_FAST_7 451 #define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR -#define _LOAD_FAST_BORROW 449 -#define _LOAD_FAST_BORROW_0 450 -#define _LOAD_FAST_BORROW_1 451 -#define _LOAD_FAST_BORROW_2 452 -#define _LOAD_FAST_BORROW_3 453 -#define _LOAD_FAST_BORROW_4 454 -#define _LOAD_FAST_BORROW_5 455 -#define _LOAD_FAST_BORROW_6 456 -#define _LOAD_FAST_BORROW_7 457 +#define _LOAD_FAST_BORROW 452 +#define _LOAD_FAST_BORROW_0 453 +#define _LOAD_FAST_BORROW_1 454 +#define _LOAD_FAST_BORROW_2 455 +#define _LOAD_FAST_BORROW_3 456 +#define _LOAD_FAST_BORROW_4 457 +#define _LOAD_FAST_BORROW_5 458 +#define _LOAD_FAST_BORROW_6 459 +#define _LOAD_FAST_BORROW_7 460 #define _LOAD_FAST_BORROW_LOAD_FAST_BORROW LOAD_FAST_BORROW_LOAD_FAST_BORROW #define _LOAD_FAST_CHECK LOAD_FAST_CHECK #define _LOAD_FAST_LOAD_FAST LOAD_FAST_LOAD_FAST #define _LOAD_FROM_DICT_OR_DEREF LOAD_FROM_DICT_OR_DEREF #define _LOAD_FROM_DICT_OR_GLOBALS LOAD_FROM_DICT_OR_GLOBALS -#define _LOAD_GLOBAL 458 -#define _LOAD_GLOBAL_BUILTINS 459 -#define _LOAD_GLOBAL_MODULE 460 +#define _LOAD_GLOBAL 461 +#define _LOAD_GLOBAL_BUILTINS 462 +#define _LOAD_GLOBAL_MODULE 463 #define _LOAD_LOCALS LOAD_LOCALS #define _LOAD_NAME LOAD_NAME -#define _LOAD_SMALL_INT 461 -#define _LOAD_SMALL_INT_0 462 -#define _LOAD_SMALL_INT_1 463 -#define _LOAD_SMALL_INT_2 464 -#define _LOAD_SMALL_INT_3 465 -#define _LOAD_SPECIAL 466 +#define _LOAD_SMALL_INT 464 +#define _LOAD_SMALL_INT_0 465 +#define _LOAD_SMALL_INT_1 466 +#define _LOAD_SMALL_INT_2 467 +#define _LOAD_SMALL_INT_3 468 +#define _LOAD_SPECIAL 469 #define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR #define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD -#define _MAKE_CALLARGS_A_TUPLE 467 +#define _MAKE_CALLARGS_A_TUPLE 470 #define _MAKE_CELL MAKE_CELL #define _MAKE_FUNCTION MAKE_FUNCTION -#define _MAKE_WARM 468 +#define _MAKE_WARM 471 #define _MAP_ADD MAP_ADD #define _MATCH_CLASS MATCH_CLASS #define _MATCH_KEYS MATCH_KEYS #define _MATCH_MAPPING MATCH_MAPPING #define _MATCH_SEQUENCE MATCH_SEQUENCE -#define _MAYBE_EXPAND_METHOD 469 -#define _MAYBE_EXPAND_METHOD_KW 470 -#define _MONITOR_CALL 471 -#define _MONITOR_CALL_KW 472 -#define _MONITOR_JUMP_BACKWARD 473 -#define _MONITOR_RESUME 474 +#define _MAYBE_EXPAND_METHOD 472 +#define _MAYBE_EXPAND_METHOD_KW 473 +#define _MONITOR_CALL 474 +#define _MONITOR_CALL_KW 475 +#define _MONITOR_JUMP_BACKWARD 476 +#define _MONITOR_RESUME 477 #define _NOP NOP #define _POP_EXCEPT POP_EXCEPT -#define _POP_JUMP_IF_FALSE 475 -#define _POP_JUMP_IF_TRUE 476 +#define _POP_JUMP_IF_FALSE 478 +#define _POP_JUMP_IF_TRUE 479 #define _POP_TOP POP_TOP -#define _POP_TOP_LOAD_CONST_INLINE 477 -#define _POP_TOP_LOAD_CONST_INLINE_BORROW 478 -#define _POP_TWO_LOAD_CONST_INLINE_BORROW 479 +#define _POP_TOP_LOAD_CONST_INLINE 480 +#define _POP_TOP_LOAD_CONST_INLINE_BORROW 481 +#define _POP_TWO_LOAD_CONST_INLINE_BORROW 482 #define _PUSH_EXC_INFO PUSH_EXC_INFO -#define _PUSH_FRAME 480 +#define _PUSH_FRAME 483 #define _PUSH_NULL PUSH_NULL -#define _PUSH_NULL_CONDITIONAL 481 -#define _PY_FRAME_GENERAL 482 -#define _PY_FRAME_KW 483 -#define _QUICKEN_RESUME 484 -#define _REPLACE_WITH_TRUE 485 +#define _PUSH_NULL_CONDITIONAL 484 +#define _PY_FRAME_GENERAL 485 +#define _PY_FRAME_KW 486 +#define _QUICKEN_RESUME 487 +#define _REPLACE_WITH_TRUE 488 #define _RESUME_CHECK RESUME_CHECK #define _RETURN_GENERATOR RETURN_GENERATOR #define _RETURN_VALUE RETURN_VALUE -#define _SAVE_RETURN_OFFSET 486 -#define _SEND 487 -#define _SEND_GEN_FRAME 488 +#define _SAVE_RETURN_OFFSET 489 +#define _SEND 490 +#define _SEND_GEN_FRAME 491 #define _SETUP_ANNOTATIONS SETUP_ANNOTATIONS #define _SET_ADD SET_ADD #define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE #define _SET_UPDATE SET_UPDATE -#define _START_EXECUTOR 489 -#define _STORE_ATTR 490 -#define _STORE_ATTR_INSTANCE_VALUE 491 -#define _STORE_ATTR_SLOT 492 -#define _STORE_ATTR_WITH_HINT 493 +#define _START_EXECUTOR 492 +#define _STORE_ATTR 493 +#define _STORE_ATTR_INSTANCE_VALUE 494 +#define _STORE_ATTR_SLOT 495 +#define _STORE_ATTR_WITH_HINT 496 #define _STORE_DEREF STORE_DEREF -#define _STORE_FAST 494 -#define _STORE_FAST_0 495 -#define _STORE_FAST_1 496 -#define _STORE_FAST_2 497 -#define _STORE_FAST_3 498 -#define _STORE_FAST_4 499 -#define _STORE_FAST_5 500 -#define _STORE_FAST_6 501 -#define _STORE_FAST_7 502 +#define _STORE_FAST 497 +#define _STORE_FAST_0 498 +#define _STORE_FAST_1 499 +#define _STORE_FAST_2 500 +#define _STORE_FAST_3 501 +#define _STORE_FAST_4 502 +#define _STORE_FAST_5 503 +#define _STORE_FAST_6 504 +#define _STORE_FAST_7 505 #define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST #define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST #define _STORE_GLOBAL STORE_GLOBAL #define _STORE_NAME STORE_NAME -#define _STORE_SLICE 503 -#define _STORE_SUBSCR 504 -#define _STORE_SUBSCR_DICT 505 -#define _STORE_SUBSCR_LIST_INT 506 +#define _STORE_SLICE 506 +#define _STORE_SUBSCR 507 +#define _STORE_SUBSCR_DICT 508 +#define _STORE_SUBSCR_LIST_INT 509 #define _SWAP SWAP -#define _TIER2_RESUME_CHECK 507 -#define _TO_BOOL 508 +#define _TIER2_RESUME_CHECK 510 +#define _TO_BOOL 511 #define _TO_BOOL_BOOL TO_BOOL_BOOL #define _TO_BOOL_INT TO_BOOL_INT -#define _TO_BOOL_LIST 509 +#define _TO_BOOL_LIST 512 #define _TO_BOOL_NONE TO_BOOL_NONE -#define _TO_BOOL_STR 510 +#define _TO_BOOL_STR 513 #define _UNARY_INVERT UNARY_INVERT #define _UNARY_NEGATIVE UNARY_NEGATIVE #define _UNARY_NOT UNARY_NOT #define _UNPACK_EX UNPACK_EX -#define _UNPACK_SEQUENCE 511 -#define _UNPACK_SEQUENCE_LIST 512 -#define _UNPACK_SEQUENCE_TUPLE 513 -#define _UNPACK_SEQUENCE_TWO_TUPLE 514 +#define _UNPACK_SEQUENCE 514 +#define _UNPACK_SEQUENCE_LIST 515 +#define _UNPACK_SEQUENCE_TUPLE 516 +#define _UNPACK_SEQUENCE_TWO_TUPLE 517 #define _WITH_EXCEPT_START WITH_EXCEPT_START #define _YIELD_VALUE YIELD_VALUE -#define MAX_UOP_ID 514 +#define MAX_UOP_ID 517 #ifdef __cplusplus } diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index 7304fc6e299807..1b2a87f77b2610 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -261,7 +261,9 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_CALL_BUILTIN_FAST] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_BUILTIN_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_LEN] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, - [_CALL_ISINSTANCE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, + [_GUARD_CALLABLE_ISINSTANCE_NULL] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, + [_GUARD_CALLABLE_ISINSTANCE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, + [_CALL_ISINSTANCE] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_CALL_LIST_APPEND] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_METHOD_DESCRIPTOR_O] = HAS_ARG_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -424,6 +426,8 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_GET_LEN] = "_GET_LEN", [_GET_YIELD_FROM_ITER] = "_GET_YIELD_FROM_ITER", [_GUARD_BINARY_OP_EXTEND] = "_GUARD_BINARY_OP_EXTEND", + [_GUARD_CALLABLE_ISINSTANCE] = "_GUARD_CALLABLE_ISINSTANCE", + [_GUARD_CALLABLE_ISINSTANCE_NULL] = "_GUARD_CALLABLE_ISINSTANCE_NULL", [_GUARD_CALLABLE_STR_1] = "_GUARD_CALLABLE_STR_1", [_GUARD_CALLABLE_TUPLE_1] = "_GUARD_CALLABLE_TUPLE_1", [_GUARD_CALLABLE_TYPE_1] = "_GUARD_CALLABLE_TYPE_1", @@ -1094,6 +1098,10 @@ int _PyUop_num_popped(int opcode, int oparg) return 2 + oparg; case _CALL_LEN: return 2 + oparg; + case _GUARD_CALLABLE_ISINSTANCE_NULL: + return 0; + case _GUARD_CALLABLE_ISINSTANCE: + return 0; case _CALL_ISINSTANCE: return 2 + oparg; case _CALL_LIST_APPEND: diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 7e0c60d5522402..2fe63006cdcb26 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1940,6 +1940,23 @@ def testfunc(n): self.assertNotIn("_COMPARE_OP_INT", uops) self.assertNotIn("_GUARD_IS_TRUE_POP", uops) + def test_call_isinstance_guards_removed(self): + def testfunc(n): + x = 0 + for _ in range(n): + y = isinstance(42, int) + if y: + x += 1 + return x + + res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) + self.assertEqual(res, TIER2_THRESHOLD) + self.assertIsNotNone(ex) + uops = get_opnames(ex) + self.assertIn("_CALL_ISINSTANCE", uops) + self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE_NULL", uops) + self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE", uops) + def global_identity(x): return x diff --git a/Python/bytecodes.c b/Python/bytecodes.c index f145bdef644d0e..2188f2511d050b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4349,31 +4349,43 @@ dummy_func( res = PyStackRef_FromPyObjectSteal(res_o); } - inst(CALL_ISINSTANCE, (unused/1, unused/2, callable, self_or_null, args[oparg] -- res)) { - /* isinstance(o, o2) */ - PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); + op(_GUARD_CALLABLE_ISINSTANCE_NULL, (callable, null, unused[oparg] -- callable, null, unused[oparg])) { + DEOPT_IF(!PyStackRef_IsNull(null)); + } - int total_args = oparg; - _PyStackRef *arguments = args; - if (!PyStackRef_IsNull(self_or_null)) { - arguments--; - total_args++; - } - DEOPT_IF(total_args != 2); + op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { + PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; DEOPT_IF(callable_o != interp->callable_cache.isinstance); + } + + op(_CALL_ISINSTANCE, (callable, null, args[oparg] -- res)) { + /* isinstance(o, o2) */ + assert(oparg == 2); STAT_INC(CALL, hit); - _PyStackRef cls_stackref = arguments[1]; - _PyStackRef inst_stackref = arguments[0]; - int retval = PyObject_IsInstance(PyStackRef_AsPyObjectBorrow(inst_stackref), PyStackRef_AsPyObjectBorrow(cls_stackref)); + PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); + PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); + int retval = PyObject_IsInstance(inst, cls); if (retval < 0) { ERROR_NO_POP(); } + (void)callable; // Silence compiler warnings about unused variables + (void)null; + DEAD(callable); + DEAD(null); + PyStackRef_CLOSE(args[0]); + PyStackRef_CLOSE(args[1]); res = retval ? PyStackRef_True : PyStackRef_False; assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); - DECREF_INPUTS(); } + macro(CALL_ISINSTANCE) = + unused/1 + + unused/2 + + _GUARD_CALLABLE_ISINSTANCE_NULL + + _GUARD_CALLABLE_ISINSTANCE + + _CALL_ISINSTANCE; + // This is secretly a super-instruction inst(CALL_LIST_APPEND, (unused/1, unused/2, callable, self, arg -- )) { assert(oparg == 1); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 70f092e4c6f4be..6b777d3493e618 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5857,58 +5857,61 @@ break; } - case _CALL_ISINSTANCE: { - _PyStackRef *args; - _PyStackRef self_or_null; - _PyStackRef callable; - _PyStackRef res; + case _GUARD_CALLABLE_ISINSTANCE_NULL: { + _PyStackRef null; oparg = CURRENT_OPARG(); - args = &stack_pointer[-oparg]; - self_or_null = stack_pointer[-1 - oparg]; - callable = stack_pointer[-2 - oparg]; - PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); - int total_args = oparg; - _PyStackRef *arguments = args; - if (!PyStackRef_IsNull(self_or_null)) { - arguments--; - total_args++; - } - if (total_args != 2) { + null = stack_pointer[-1 - oparg]; + if (!PyStackRef_IsNull(null)) { UOP_STAT_INC(uopcode, miss); JUMP_TO_JUMP_TARGET(); } + break; + } + + case _GUARD_CALLABLE_ISINSTANCE: { + _PyStackRef callable; + oparg = CURRENT_OPARG(); + callable = stack_pointer[-2 - oparg]; + PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; if (callable_o != interp->callable_cache.isinstance) { UOP_STAT_INC(uopcode, miss); JUMP_TO_JUMP_TARGET(); } + break; + } + + case _CALL_ISINSTANCE: { + _PyStackRef *args; + _PyStackRef null; + _PyStackRef callable; + _PyStackRef res; + oparg = CURRENT_OPARG(); + args = &stack_pointer[-oparg]; + null = stack_pointer[-1 - oparg]; + callable = stack_pointer[-2 - oparg]; + assert(oparg == 2); STAT_INC(CALL, hit); - _PyStackRef cls_stackref = arguments[1]; - _PyStackRef inst_stackref = arguments[0]; + PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); + PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); _PyFrame_SetStackPointer(frame, stack_pointer); - int retval = PyObject_IsInstance(PyStackRef_AsPyObjectBorrow(inst_stackref), PyStackRef_AsPyObjectBorrow(cls_stackref)); + int retval = PyObject_IsInstance(inst, cls); stack_pointer = _PyFrame_GetStackPointer(frame); if (retval < 0) { JUMP_TO_ERROR(); } - res = retval ? PyStackRef_True : PyStackRef_False; - assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); + (void)callable; + (void)null; + stack_pointer += -2 - oparg; + assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); - _PyStackRef tmp = callable; - callable = res; - stack_pointer[-2 - oparg] = callable; - PyStackRef_CLOSE(tmp); - for (int _i = oparg; --_i >= 0;) { - tmp = args[_i]; - args[_i] = PyStackRef_NULL; - PyStackRef_CLOSE(tmp); - } - tmp = self_or_null; - self_or_null = PyStackRef_NULL; - stack_pointer[-1 - oparg] = self_or_null; - PyStackRef_XCLOSE(tmp); + PyStackRef_CLOSE(args[0]); + PyStackRef_CLOSE(args[1]); stack_pointer = _PyFrame_GetStackPointer(frame); - stack_pointer += -1 - oparg; + res = retval ? PyStackRef_True : PyStackRef_False; + assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); + stack_pointer[0] = res; + stack_pointer += 1; assert(WITHIN_STACK_BOUNDS()); break; } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 08b72a092aafdb..23d0401193cafa 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2777,60 +2777,58 @@ next_instr += 4; INSTRUCTION_STATS(CALL_ISINSTANCE); static_assert(INLINE_CACHE_ENTRIES_CALL == 3, "incorrect cache size"); + _PyStackRef null; _PyStackRef callable; - _PyStackRef self_or_null; _PyStackRef *args; _PyStackRef res; /* Skip 1 cache entry */ /* Skip 2 cache entries */ - args = &stack_pointer[-oparg]; - self_or_null = stack_pointer[-1 - oparg]; - callable = stack_pointer[-2 - oparg]; - PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); - int total_args = oparg; - _PyStackRef *arguments = args; - if (!PyStackRef_IsNull(self_or_null)) { - arguments--; - total_args++; - } - if (total_args != 2) { - UPDATE_MISS_STATS(CALL); - assert(_PyOpcode_Deopt[opcode] == (CALL)); - JUMP_TO_PREDICTED(CALL); - } - PyInterpreterState *interp = tstate->interp; - if (callable_o != interp->callable_cache.isinstance) { - UPDATE_MISS_STATS(CALL); - assert(_PyOpcode_Deopt[opcode] == (CALL)); - JUMP_TO_PREDICTED(CALL); + // _GUARD_CALLABLE_ISINSTANCE_NULL + { + null = stack_pointer[-1 - oparg]; + if (!PyStackRef_IsNull(null)) { + UPDATE_MISS_STATS(CALL); + assert(_PyOpcode_Deopt[opcode] == (CALL)); + JUMP_TO_PREDICTED(CALL); + } } - STAT_INC(CALL, hit); - _PyStackRef cls_stackref = arguments[1]; - _PyStackRef inst_stackref = arguments[0]; - _PyFrame_SetStackPointer(frame, stack_pointer); - int retval = PyObject_IsInstance(PyStackRef_AsPyObjectBorrow(inst_stackref), PyStackRef_AsPyObjectBorrow(cls_stackref)); - stack_pointer = _PyFrame_GetStackPointer(frame); - if (retval < 0) { - JUMP_TO_LABEL(error); + // _GUARD_CALLABLE_ISINSTANCE + { + callable = stack_pointer[-2 - oparg]; + PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); + PyInterpreterState *interp = tstate->interp; + if (callable_o != interp->callable_cache.isinstance) { + UPDATE_MISS_STATS(CALL); + assert(_PyOpcode_Deopt[opcode] == (CALL)); + JUMP_TO_PREDICTED(CALL); + } } - res = retval ? PyStackRef_True : PyStackRef_False; - assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); - _PyFrame_SetStackPointer(frame, stack_pointer); - _PyStackRef tmp = callable; - callable = res; - stack_pointer[-2 - oparg] = callable; - PyStackRef_CLOSE(tmp); - for (int _i = oparg; --_i >= 0;) { - tmp = args[_i]; - args[_i] = PyStackRef_NULL; - PyStackRef_CLOSE(tmp); + // _CALL_ISINSTANCE + { + args = &stack_pointer[-oparg]; + assert(oparg == 2); + STAT_INC(CALL, hit); + PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); + PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); + _PyFrame_SetStackPointer(frame, stack_pointer); + int retval = PyObject_IsInstance(inst, cls); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (retval < 0) { + JUMP_TO_LABEL(error); + } + (void)callable; + (void)null; + stack_pointer += -2 - oparg; + assert(WITHIN_STACK_BOUNDS()); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(args[0]); + PyStackRef_CLOSE(args[1]); + stack_pointer = _PyFrame_GetStackPointer(frame); + res = retval ? PyStackRef_True : PyStackRef_False; + assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); } - tmp = self_or_null; - self_or_null = PyStackRef_NULL; - stack_pointer[-1 - oparg] = self_or_null; - PyStackRef_XCLOSE(tmp); - stack_pointer = _PyFrame_GetStackPointer(frame); - stack_pointer += -1 - oparg; + stack_pointer[0] = res; + stack_pointer += 1; assert(WITHIN_STACK_BOUNDS()); DISPATCH(); } diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 567caad22554ea..34aca61f76b122 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -1088,6 +1088,21 @@ dummy_func(void) { res = sym_new_type(ctx, &PyLong_Type); } + op(_GUARD_CALLABLE_ISINSTANCE_NULL, (callable, null, unused[oparg] -- callable, null, unused[oparg])) { + if (sym_is_null(null)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_null(null); + } + + op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { + PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance; + if (sym_get_const(ctx, callable) == isinstance) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_const(callable, isinstance); + } + // END BYTECODES // } diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 3f91f7eefc7bb0..129a7485a7cd93 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -2076,6 +2076,27 @@ break; } + case _GUARD_CALLABLE_ISINSTANCE_NULL: { + JitOptSymbol *null; + null = stack_pointer[-1 - oparg]; + if (sym_is_null(null)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_null(null); + break; + } + + case _GUARD_CALLABLE_ISINSTANCE: { + JitOptSymbol *callable; + callable = stack_pointer[-2 - oparg]; + PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance; + if (sym_get_const(ctx, callable) == isinstance) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_const(callable, isinstance); + break; + } + case _CALL_ISINSTANCE: { JitOptSymbol *res; res = sym_new_not_null(ctx); diff --git a/Python/specialize.c b/Python/specialize.c index 59ec9a4cad6b9c..3d1f682f3c94da 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -2158,7 +2158,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs) if (nargs == 2) { /* isinstance(o1, o2) */ PyInterpreterState *interp = _PyInterpreterState_GET(); - if (callable == interp->callable_cache.isinstance) { + if (callable == interp->callable_cache.isinstance && instr->op.arg == 2) { specialize(instr, CALL_ISINSTANCE); return 0; } From 0ab70a9dc7026a8ee1bf112ac71b29d71de9404c Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 3 May 2025 13:36:07 +0200 Subject: [PATCH 2/8] Add news entry --- .../2025-05-03-13-36-01.gh-issue-131798.U4_QEJ.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-05-03-13-36-01.gh-issue-131798.U4_QEJ.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-03-13-36-01.gh-issue-131798.U4_QEJ.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-03-13-36-01.gh-issue-131798.U4_QEJ.rst new file mode 100644 index 00000000000000..ca8eb999ae5ef0 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-03-13-36-01.gh-issue-131798.U4_QEJ.rst @@ -0,0 +1,2 @@ +Split ``CALL_ISINSTANCE`` into several uops, allowing the JIT to remove some +of them. From 900472adcb3302f4b572cef5257e1bbe53569554 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 3 May 2025 13:48:59 +0200 Subject: [PATCH 3/8] Close all stackrefs --- Python/bytecodes.c | 5 ++--- Python/executor_cases.c.h | 8 ++++++-- Python/generated_cases.c.h | 8 ++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 2188f2511d050b..9c6e7e82816f48 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4369,12 +4369,11 @@ dummy_func( if (retval < 0) { ERROR_NO_POP(); } - (void)callable; // Silence compiler warnings about unused variables - (void)null; - DEAD(callable); + (void)null; // Silence compiler warnings about unused variables DEAD(null); PyStackRef_CLOSE(args[0]); PyStackRef_CLOSE(args[1]); + PyStackRef_CLOSE(callable); res = retval ? PyStackRef_True : PyStackRef_False; assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 6b777d3493e618..15175afeaa5fe3 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5900,14 +5900,18 @@ if (retval < 0) { JUMP_TO_ERROR(); } - (void)callable; (void)null; - stack_pointer += -2 - oparg; + stack_pointer += -1 - oparg; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); PyStackRef_CLOSE(args[0]); PyStackRef_CLOSE(args[1]); stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + assert(WITHIN_STACK_BOUNDS()); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(callable); + stack_pointer = _PyFrame_GetStackPointer(frame); res = retval ? PyStackRef_True : PyStackRef_False; assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); stack_pointer[0] = res; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 23d0401193cafa..a59b9951fcd606 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2816,14 +2816,18 @@ if (retval < 0) { JUMP_TO_LABEL(error); } - (void)callable; (void)null; - stack_pointer += -2 - oparg; + stack_pointer += -1 - oparg; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); PyStackRef_CLOSE(args[0]); PyStackRef_CLOSE(args[1]); stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -1; + assert(WITHIN_STACK_BOUNDS()); + _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(callable); + stack_pointer = _PyFrame_GetStackPointer(frame); res = retval ? PyStackRef_True : PyStackRef_False; assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); } From 6f49dca7d251bd3145d2b7f8c6f907fb1b963208 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 3 May 2025 22:22:28 +0200 Subject: [PATCH 4/8] Rename to _GUARD_THIRD_NULL --- Include/internal/pycore_opcode_metadata.h | 2 +- Include/internal/pycore_uop_ids.h | 44 +++++++++++------------ Include/internal/pycore_uop_metadata.h | 8 ++--- Python/bytecodes.c | 10 +++--- Python/executor_cases.c.h | 21 ++++++----- Python/generated_cases.c.h | 5 +-- Python/optimizer_bytecodes.c | 14 ++++---- Python/optimizer_cases.c.h | 20 +++++------ 8 files changed, 62 insertions(+), 62 deletions(-) diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index 7f6822e1c071cb..de4aef2d24abab 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -1363,7 +1363,7 @@ _PyOpcode_macro_expansion[256] = { [CALL_BUILTIN_O] = { .nuops = 2, .uops = { { _CALL_BUILTIN_O, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC, OPARG_SIMPLE, 3 } } }, [CALL_INTRINSIC_1] = { .nuops = 1, .uops = { { _CALL_INTRINSIC_1, OPARG_SIMPLE, 0 } } }, [CALL_INTRINSIC_2] = { .nuops = 1, .uops = { { _CALL_INTRINSIC_2, OPARG_SIMPLE, 0 } } }, - [CALL_ISINSTANCE] = { .nuops = 3, .uops = { { _GUARD_CALLABLE_ISINSTANCE_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_ISINSTANCE, OPARG_SIMPLE, 3 }, { _CALL_ISINSTANCE, OPARG_SIMPLE, 3 } } }, + [CALL_ISINSTANCE] = { .nuops = 3, .uops = { { _GUARD_THIRD_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_ISINSTANCE, OPARG_SIMPLE, 3 }, { _CALL_ISINSTANCE, OPARG_SIMPLE, 3 } } }, [CALL_KW_BOUND_METHOD] = { .nuops = 6, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 1 }, { _CHECK_METHOD_VERSION_KW, 2, 1 }, { _EXPAND_METHOD_KW, OPARG_SIMPLE, 3 }, { _PY_FRAME_KW, OPARG_SIMPLE, 3 }, { _SAVE_RETURN_OFFSET, OPARG_SAVE_RETURN_OFFSET, 3 }, { _PUSH_FRAME, OPARG_SIMPLE, 3 } } }, [CALL_KW_NON_PY] = { .nuops = 3, .uops = { { _CHECK_IS_NOT_PY_CALLABLE_KW, OPARG_SIMPLE, 3 }, { _CALL_KW_NON_PY, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC, OPARG_SIMPLE, 3 } } }, [CALL_KW_PY] = { .nuops = 5, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 1 }, { _CHECK_FUNCTION_VERSION_KW, 2, 1 }, { _PY_FRAME_KW, OPARG_SIMPLE, 3 }, { _SAVE_RETURN_OFFSET, OPARG_SAVE_RETURN_OFFSET, 3 }, { _PUSH_FRAME, OPARG_SIMPLE, 3 } } }, diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index f90577e0853dde..5abbc5c712fb01 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -121,28 +121,28 @@ extern "C" { #define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER #define _GUARD_BINARY_OP_EXTEND 374 #define _GUARD_CALLABLE_ISINSTANCE 375 -#define _GUARD_CALLABLE_ISINSTANCE_NULL 376 -#define _GUARD_CALLABLE_STR_1 377 -#define _GUARD_CALLABLE_TUPLE_1 378 -#define _GUARD_CALLABLE_TYPE_1 379 -#define _GUARD_DORV_NO_DICT 380 -#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 381 -#define _GUARD_GLOBALS_VERSION 382 -#define _GUARD_IS_FALSE_POP 383 -#define _GUARD_IS_NONE_POP 384 -#define _GUARD_IS_NOT_NONE_POP 385 -#define _GUARD_IS_TRUE_POP 386 -#define _GUARD_KEYS_VERSION 387 -#define _GUARD_NOS_DICT 388 -#define _GUARD_NOS_FLOAT 389 -#define _GUARD_NOS_INT 390 -#define _GUARD_NOS_LIST 391 -#define _GUARD_NOS_NULL 392 -#define _GUARD_NOS_TUPLE 393 -#define _GUARD_NOS_UNICODE 394 -#define _GUARD_NOT_EXHAUSTED_LIST 395 -#define _GUARD_NOT_EXHAUSTED_RANGE 396 -#define _GUARD_NOT_EXHAUSTED_TUPLE 397 +#define _GUARD_CALLABLE_STR_1 376 +#define _GUARD_CALLABLE_TUPLE_1 377 +#define _GUARD_CALLABLE_TYPE_1 378 +#define _GUARD_DORV_NO_DICT 379 +#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 380 +#define _GUARD_GLOBALS_VERSION 381 +#define _GUARD_IS_FALSE_POP 382 +#define _GUARD_IS_NONE_POP 383 +#define _GUARD_IS_NOT_NONE_POP 384 +#define _GUARD_IS_TRUE_POP 385 +#define _GUARD_KEYS_VERSION 386 +#define _GUARD_NOS_DICT 387 +#define _GUARD_NOS_FLOAT 388 +#define _GUARD_NOS_INT 389 +#define _GUARD_NOS_LIST 390 +#define _GUARD_NOS_NULL 391 +#define _GUARD_NOS_TUPLE 392 +#define _GUARD_NOS_UNICODE 393 +#define _GUARD_NOT_EXHAUSTED_LIST 394 +#define _GUARD_NOT_EXHAUSTED_RANGE 395 +#define _GUARD_NOT_EXHAUSTED_TUPLE 396 +#define _GUARD_THIRD_NULL 397 #define _GUARD_TOS_ANY_SET 398 #define _GUARD_TOS_DICT 399 #define _GUARD_TOS_FLOAT 400 diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index 1b2a87f77b2610..f827e35378adf1 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -247,6 +247,7 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_INIT_CALL_PY_EXACT_ARGS] = HAS_ARG_FLAG | HAS_PURE_FLAG, [_PUSH_FRAME] = 0, [_GUARD_NOS_NULL] = HAS_DEOPT_FLAG, + [_GUARD_THIRD_NULL] = HAS_DEOPT_FLAG, [_GUARD_CALLABLE_TYPE_1] = HAS_DEOPT_FLAG, [_CALL_TYPE_1] = HAS_ARG_FLAG | HAS_ESCAPES_FLAG, [_GUARD_CALLABLE_STR_1] = HAS_DEOPT_FLAG, @@ -261,7 +262,6 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_CALL_BUILTIN_FAST] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_BUILTIN_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_LEN] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, - [_GUARD_CALLABLE_ISINSTANCE_NULL] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, [_GUARD_CALLABLE_ISINSTANCE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, [_CALL_ISINSTANCE] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_CALL_LIST_APPEND] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -427,7 +427,6 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_GET_YIELD_FROM_ITER] = "_GET_YIELD_FROM_ITER", [_GUARD_BINARY_OP_EXTEND] = "_GUARD_BINARY_OP_EXTEND", [_GUARD_CALLABLE_ISINSTANCE] = "_GUARD_CALLABLE_ISINSTANCE", - [_GUARD_CALLABLE_ISINSTANCE_NULL] = "_GUARD_CALLABLE_ISINSTANCE_NULL", [_GUARD_CALLABLE_STR_1] = "_GUARD_CALLABLE_STR_1", [_GUARD_CALLABLE_TUPLE_1] = "_GUARD_CALLABLE_TUPLE_1", [_GUARD_CALLABLE_TYPE_1] = "_GUARD_CALLABLE_TYPE_1", @@ -449,6 +448,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_GUARD_NOT_EXHAUSTED_LIST] = "_GUARD_NOT_EXHAUSTED_LIST", [_GUARD_NOT_EXHAUSTED_RANGE] = "_GUARD_NOT_EXHAUSTED_RANGE", [_GUARD_NOT_EXHAUSTED_TUPLE] = "_GUARD_NOT_EXHAUSTED_TUPLE", + [_GUARD_THIRD_NULL] = "_GUARD_THIRD_NULL", [_GUARD_TOS_ANY_SET] = "_GUARD_TOS_ANY_SET", [_GUARD_TOS_DICT] = "_GUARD_TOS_DICT", [_GUARD_TOS_FLOAT] = "_GUARD_TOS_FLOAT", @@ -1070,6 +1070,8 @@ int _PyUop_num_popped(int opcode, int oparg) return 1; case _GUARD_NOS_NULL: return 0; + case _GUARD_THIRD_NULL: + return 0; case _GUARD_CALLABLE_TYPE_1: return 0; case _CALL_TYPE_1: @@ -1098,8 +1100,6 @@ int _PyUop_num_popped(int opcode, int oparg) return 2 + oparg; case _CALL_LEN: return 2 + oparg; - case _GUARD_CALLABLE_ISINSTANCE_NULL: - return 0; case _GUARD_CALLABLE_ISINSTANCE: return 0; case _CALL_ISINSTANCE: diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 9c6e7e82816f48..f00ba124772577 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4033,6 +4033,10 @@ dummy_func( DEOPT_IF(!PyStackRef_IsNull(null)); } + op(_GUARD_THIRD_NULL, (null, unused, unused -- null, unused, unused)) { + DEOPT_IF(!PyStackRef_IsNull(null)); + } + op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused -- callable, unused, unused)) { PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); DEOPT_IF(callable_o != (PyObject *)&PyType_Type); @@ -4349,10 +4353,6 @@ dummy_func( res = PyStackRef_FromPyObjectSteal(res_o); } - op(_GUARD_CALLABLE_ISINSTANCE_NULL, (callable, null, unused[oparg] -- callable, null, unused[oparg])) { - DEOPT_IF(!PyStackRef_IsNull(null)); - } - op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; @@ -4381,7 +4381,7 @@ dummy_func( macro(CALL_ISINSTANCE) = unused/1 + unused/2 + - _GUARD_CALLABLE_ISINSTANCE_NULL + + _GUARD_THIRD_NULL + _GUARD_CALLABLE_ISINSTANCE + _CALL_ISINSTANCE; diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 15175afeaa5fe3..4b583a0fa5b93d 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5276,6 +5276,16 @@ break; } + case _GUARD_THIRD_NULL: { + _PyStackRef null; + null = stack_pointer[-3]; + if (!PyStackRef_IsNull(null)) { + UOP_STAT_INC(uopcode, miss); + JUMP_TO_JUMP_TARGET(); + } + break; + } + case _GUARD_CALLABLE_TYPE_1: { _PyStackRef callable; callable = stack_pointer[-3]; @@ -5857,17 +5867,6 @@ break; } - case _GUARD_CALLABLE_ISINSTANCE_NULL: { - _PyStackRef null; - oparg = CURRENT_OPARG(); - null = stack_pointer[-1 - oparg]; - if (!PyStackRef_IsNull(null)) { - UOP_STAT_INC(uopcode, miss); - JUMP_TO_JUMP_TARGET(); - } - break; - } - case _GUARD_CALLABLE_ISINSTANCE: { _PyStackRef callable; oparg = CURRENT_OPARG(); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index a59b9951fcd606..7abcd615f7bf7d 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2783,9 +2783,9 @@ _PyStackRef res; /* Skip 1 cache entry */ /* Skip 2 cache entries */ - // _GUARD_CALLABLE_ISINSTANCE_NULL + // _GUARD_THIRD_NULL { - null = stack_pointer[-1 - oparg]; + null = stack_pointer[-3]; if (!PyStackRef_IsNull(null)) { UPDATE_MISS_STATS(CALL); assert(_PyOpcode_Deopt[opcode] == (CALL)); @@ -2806,6 +2806,7 @@ // _CALL_ISINSTANCE { args = &stack_pointer[-oparg]; + null = stack_pointer[-1 - oparg]; assert(oparg == 2); STAT_INC(CALL, hit); PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 34aca61f76b122..c94003cba59ab2 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -1063,6 +1063,13 @@ dummy_func(void) { sym_set_null(null); } + op(_GUARD_THIRD_NULL, (null, unused, unused -- null, unused, unused)) { + if (sym_is_null(null)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_null(null); + } + op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused -- callable, unused, unused)) { if (sym_get_const(ctx, callable) == (PyObject *)&PyType_Type) { REPLACE_OP(this_instr, _NOP, 0, 0); @@ -1088,13 +1095,6 @@ dummy_func(void) { res = sym_new_type(ctx, &PyLong_Type); } - op(_GUARD_CALLABLE_ISINSTANCE_NULL, (callable, null, unused[oparg] -- callable, null, unused[oparg])) { - if (sym_is_null(null)) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - sym_set_null(null); - } - op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance; if (sym_get_const(ctx, callable) == isinstance) { diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 129a7485a7cd93..58f770f48620a2 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -1921,6 +1921,16 @@ break; } + case _GUARD_THIRD_NULL: { + JitOptSymbol *null; + null = stack_pointer[-3]; + if (sym_is_null(null)) { + REPLACE_OP(this_instr, _NOP, 0, 0); + } + sym_set_null(null); + break; + } + case _GUARD_CALLABLE_TYPE_1: { JitOptSymbol *callable; callable = stack_pointer[-3]; @@ -2076,16 +2086,6 @@ break; } - case _GUARD_CALLABLE_ISINSTANCE_NULL: { - JitOptSymbol *null; - null = stack_pointer[-1 - oparg]; - if (sym_is_null(null)) { - REPLACE_OP(this_instr, _NOP, 0, 0); - } - sym_set_null(null); - break; - } - case _GUARD_CALLABLE_ISINSTANCE: { JitOptSymbol *callable; callable = stack_pointer[-2 - oparg]; From 8ba53c3db69cf9a640500ab6f2d53d0cd8dc1ace Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 3 May 2025 22:29:11 +0200 Subject: [PATCH 5/8] Unpack args array into separate stack variables --- Include/internal/pycore_opcode_metadata.h | 4 +-- Include/internal/pycore_uop_metadata.h | 6 ++--- Python/bytecodes.c | 15 +++++------ Python/executor_cases.c.h | 31 +++++++++++++---------- Python/generated_cases.c.h | 26 +++++++++++-------- Python/optimizer_bytecodes.c | 2 +- Python/optimizer_cases.c.h | 6 ++--- 7 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h index de4aef2d24abab..ab76652493f602 100644 --- a/Include/internal/pycore_opcode_metadata.h +++ b/Include/internal/pycore_opcode_metadata.h @@ -113,7 +113,7 @@ int _PyOpcode_num_popped(int opcode, int oparg) { case CALL_INTRINSIC_2: return 2; case CALL_ISINSTANCE: - return 2 + oparg; + return 4; case CALL_KW: return 3 + oparg; case CALL_KW_BOUND_METHOD: @@ -1115,7 +1115,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[267] = { [CALL_FUNCTION_EX] = { true, INSTR_FMT_IX, HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, [CALL_INTRINSIC_1] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [CALL_INTRINSIC_2] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, - [CALL_ISINSTANCE] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, + [CALL_ISINSTANCE] = { true, INSTR_FMT_IXC00, HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, [CALL_KW] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG }, [CALL_KW_BOUND_METHOD] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [CALL_KW_NON_PY] = { true, INSTR_FMT_IBC00, HAS_ARG_FLAG | HAS_EVAL_BREAK_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index f827e35378adf1..a33fa8b30e04c1 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -262,8 +262,8 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_CALL_BUILTIN_FAST] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_BUILTIN_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_LEN] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, - [_GUARD_CALLABLE_ISINSTANCE] = HAS_ARG_FLAG | HAS_DEOPT_FLAG, - [_CALL_ISINSTANCE] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, + [_GUARD_CALLABLE_ISINSTANCE] = HAS_DEOPT_FLAG, + [_CALL_ISINSTANCE] = HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_CALL_LIST_APPEND] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_METHOD_DESCRIPTOR_O] = HAS_ARG_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -1103,7 +1103,7 @@ int _PyUop_num_popped(int opcode, int oparg) case _GUARD_CALLABLE_ISINSTANCE: return 0; case _CALL_ISINSTANCE: - return 2 + oparg; + return 4; case _CALL_LIST_APPEND: return 3; case _CALL_METHOD_DESCRIPTOR_O: diff --git a/Python/bytecodes.c b/Python/bytecodes.c index f00ba124772577..9dc8f1141ad683 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4353,26 +4353,25 @@ dummy_func( res = PyStackRef_FromPyObjectSteal(res_o); } - op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { + op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused, unused -- callable, unused, unused, unused)) { PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; DEOPT_IF(callable_o != interp->callable_cache.isinstance); } - op(_CALL_ISINSTANCE, (callable, null, args[oparg] -- res)) { + op(_CALL_ISINSTANCE, (callable, null, inst_, cls -- res)) { /* isinstance(o, o2) */ - assert(oparg == 2); STAT_INC(CALL, hit); - PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); - PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); - int retval = PyObject_IsInstance(inst, cls); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); + int retval = PyObject_IsInstance(inst_o, cls_o); if (retval < 0) { ERROR_NO_POP(); } (void)null; // Silence compiler warnings about unused variables + PyStackRef_CLOSE(cls); + PyStackRef_CLOSE(inst_); DEAD(null); - PyStackRef_CLOSE(args[0]); - PyStackRef_CLOSE(args[1]); PyStackRef_CLOSE(callable); res = retval ? PyStackRef_True : PyStackRef_False; assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL)); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 4b583a0fa5b93d..9999888edfc1b9 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5869,8 +5869,7 @@ case _GUARD_CALLABLE_ISINSTANCE: { _PyStackRef callable; - oparg = CURRENT_OPARG(); - callable = stack_pointer[-2 - oparg]; + callable = stack_pointer[-4]; PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; if (callable_o != interp->callable_cache.isinstance) { @@ -5881,34 +5880,38 @@ } case _CALL_ISINSTANCE: { - _PyStackRef *args; + _PyStackRef cls; + _PyStackRef inst_; _PyStackRef null; _PyStackRef callable; _PyStackRef res; - oparg = CURRENT_OPARG(); - args = &stack_pointer[-oparg]; - null = stack_pointer[-1 - oparg]; - callable = stack_pointer[-2 - oparg]; - assert(oparg == 2); + cls = stack_pointer[-1]; + inst_ = stack_pointer[-2]; + null = stack_pointer[-3]; + callable = stack_pointer[-4]; STAT_INC(CALL, hit); - PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); - PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); _PyFrame_SetStackPointer(frame, stack_pointer); - int retval = PyObject_IsInstance(inst, cls); + int retval = PyObject_IsInstance(inst_o, cls_o); stack_pointer = _PyFrame_GetStackPointer(frame); if (retval < 0) { JUMP_TO_ERROR(); } (void)null; - stack_pointer += -1 - oparg; + stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); - PyStackRef_CLOSE(args[0]); - PyStackRef_CLOSE(args[1]); + PyStackRef_CLOSE(cls); stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(inst_); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -2; + assert(WITHIN_STACK_BOUNDS()); + _PyFrame_SetStackPointer(frame, stack_pointer); PyStackRef_CLOSE(callable); stack_pointer = _PyFrame_GetStackPointer(frame); res = retval ? PyStackRef_True : PyStackRef_False; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 7abcd615f7bf7d..4bdb58a0384bc0 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2779,7 +2779,8 @@ static_assert(INLINE_CACHE_ENTRIES_CALL == 3, "incorrect cache size"); _PyStackRef null; _PyStackRef callable; - _PyStackRef *args; + _PyStackRef inst_; + _PyStackRef cls; _PyStackRef res; /* Skip 1 cache entry */ /* Skip 2 cache entries */ @@ -2794,7 +2795,7 @@ } // _GUARD_CALLABLE_ISINSTANCE { - callable = stack_pointer[-2 - oparg]; + callable = stack_pointer[-4]; PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable); PyInterpreterState *interp = tstate->interp; if (callable_o != interp->callable_cache.isinstance) { @@ -2805,28 +2806,31 @@ } // _CALL_ISINSTANCE { - args = &stack_pointer[-oparg]; - null = stack_pointer[-1 - oparg]; - assert(oparg == 2); + cls = stack_pointer[-1]; + inst_ = stack_pointer[-2]; STAT_INC(CALL, hit); - PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]); - PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); _PyFrame_SetStackPointer(frame, stack_pointer); - int retval = PyObject_IsInstance(inst, cls); + int retval = PyObject_IsInstance(inst_o, cls_o); stack_pointer = _PyFrame_GetStackPointer(frame); if (retval < 0) { JUMP_TO_LABEL(error); } (void)null; - stack_pointer += -1 - oparg; + stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); - PyStackRef_CLOSE(args[0]); - PyStackRef_CLOSE(args[1]); + PyStackRef_CLOSE(cls); stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); + PyStackRef_CLOSE(inst_); + stack_pointer = _PyFrame_GetStackPointer(frame); + stack_pointer += -2; + assert(WITHIN_STACK_BOUNDS()); + _PyFrame_SetStackPointer(frame, stack_pointer); PyStackRef_CLOSE(callable); stack_pointer = _PyFrame_GetStackPointer(frame); res = retval ? PyStackRef_True : PyStackRef_False; diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index c94003cba59ab2..99fd27d3169fd8 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -1095,7 +1095,7 @@ dummy_func(void) { res = sym_new_type(ctx, &PyLong_Type); } - op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) { + op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused, unused -- callable, unused, unused, unused)) { PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance; if (sym_get_const(ctx, callable) == isinstance) { REPLACE_OP(this_instr, _NOP, 0, 0); diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 58f770f48620a2..2523186f727c53 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -2088,7 +2088,7 @@ case _GUARD_CALLABLE_ISINSTANCE: { JitOptSymbol *callable; - callable = stack_pointer[-2 - oparg]; + callable = stack_pointer[-4]; PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance; if (sym_get_const(ctx, callable) == isinstance) { REPLACE_OP(this_instr, _NOP, 0, 0); @@ -2100,8 +2100,8 @@ case _CALL_ISINSTANCE: { JitOptSymbol *res; res = sym_new_not_null(ctx); - stack_pointer[-2 - oparg] = res; - stack_pointer += -1 - oparg; + stack_pointer[-4] = res; + stack_pointer += -3; assert(WITHIN_STACK_BOUNDS()); break; } From 6e1144224065e02bf467b575b26e491e2675d01a Mon Sep 17 00:00:00 2001 From: "Tomas R." Date: Thu, 8 May 2025 18:54:35 +0200 Subject: [PATCH 6/8] Fix tests Co-authored-by: Brandt Bucher --- Lib/test/test_capi/test_opt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 2fe63006cdcb26..767ffffd1bceec 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -1954,7 +1954,7 @@ def testfunc(n): self.assertIsNotNone(ex) uops = get_opnames(ex) self.assertIn("_CALL_ISINSTANCE", uops) - self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE_NULL", uops) + self.assertNotIn("_GUARD_THIRD_NULL", uops) self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE", uops) From be50e24e95b04eb7953c17ef6db21584b2c06a73 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Thu, 8 May 2025 18:56:54 +0200 Subject: [PATCH 7/8] Rename parameter --- Python/bytecodes.c | 6 +++--- Python/executor_cases.c.h | 8 ++++---- Python/generated_cases.c.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 9dc8f1141ad683..215c668e367b8c 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4359,10 +4359,10 @@ dummy_func( DEOPT_IF(callable_o != interp->callable_cache.isinstance); } - op(_CALL_ISINSTANCE, (callable, null, inst_, cls -- res)) { + op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res)) { /* isinstance(o, o2) */ STAT_INC(CALL, hit); - PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance); PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); int retval = PyObject_IsInstance(inst_o, cls_o); if (retval < 0) { @@ -4370,7 +4370,7 @@ dummy_func( } (void)null; // Silence compiler warnings about unused variables PyStackRef_CLOSE(cls); - PyStackRef_CLOSE(inst_); + PyStackRef_CLOSE(instance); DEAD(null); PyStackRef_CLOSE(callable); res = retval ? PyStackRef_True : PyStackRef_False; diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 9999888edfc1b9..fef9384f922e80 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5881,16 +5881,16 @@ case _CALL_ISINSTANCE: { _PyStackRef cls; - _PyStackRef inst_; + _PyStackRef instance; _PyStackRef null; _PyStackRef callable; _PyStackRef res; cls = stack_pointer[-1]; - inst_ = stack_pointer[-2]; + instance = stack_pointer[-2]; null = stack_pointer[-3]; callable = stack_pointer[-4]; STAT_INC(CALL, hit); - PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance); PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); _PyFrame_SetStackPointer(frame, stack_pointer); int retval = PyObject_IsInstance(inst_o, cls_o); @@ -5907,7 +5907,7 @@ stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); - PyStackRef_CLOSE(inst_); + PyStackRef_CLOSE(instance); stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer += -2; assert(WITHIN_STACK_BOUNDS()); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 4bdb58a0384bc0..e456d238367753 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2779,7 +2779,7 @@ static_assert(INLINE_CACHE_ENTRIES_CALL == 3, "incorrect cache size"); _PyStackRef null; _PyStackRef callable; - _PyStackRef inst_; + _PyStackRef instance; _PyStackRef cls; _PyStackRef res; /* Skip 1 cache entry */ @@ -2807,9 +2807,9 @@ // _CALL_ISINSTANCE { cls = stack_pointer[-1]; - inst_ = stack_pointer[-2]; + instance = stack_pointer[-2]; STAT_INC(CALL, hit); - PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_); + PyObject *inst_o = PyStackRef_AsPyObjectBorrow(instance); PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls); _PyFrame_SetStackPointer(frame, stack_pointer); int retval = PyObject_IsInstance(inst_o, cls_o); @@ -2826,7 +2826,7 @@ stack_pointer += -1; assert(WITHIN_STACK_BOUNDS()); _PyFrame_SetStackPointer(frame, stack_pointer); - PyStackRef_CLOSE(inst_); + PyStackRef_CLOSE(instance); stack_pointer = _PyFrame_GetStackPointer(frame); stack_pointer += -2; assert(WITHIN_STACK_BOUNDS()); From b0b31dd03c352f3fe1cf20a35a9e715bb724a333 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Thu, 8 May 2025 19:03:41 +0200 Subject: [PATCH 8/8] Regen cases --- Include/internal/pycore_uop_ids.h | 392 +++++++++++++------------ Include/internal/pycore_uop_metadata.h | 6 +- 2 files changed, 201 insertions(+), 197 deletions(-) diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index d3d2b716e2c997..71a288a3a39179 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -43,125 +43,127 @@ extern "C" { #define _CALL_BUILTIN_O 323 #define _CALL_INTRINSIC_1 CALL_INTRINSIC_1 #define _CALL_INTRINSIC_2 CALL_INTRINSIC_2 -#define _CALL_ISINSTANCE CALL_ISINSTANCE -#define _CALL_KW_NON_PY 324 -#define _CALL_LEN 325 +#define _CALL_ISINSTANCE 324 +#define _CALL_KW_NON_PY 325 +#define _CALL_LEN 326 #define _CALL_LIST_APPEND CALL_LIST_APPEND -#define _CALL_METHOD_DESCRIPTOR_FAST 326 -#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 327 -#define _CALL_METHOD_DESCRIPTOR_NOARGS 328 -#define _CALL_METHOD_DESCRIPTOR_O 329 -#define _CALL_NON_PY_GENERAL 330 -#define _CALL_STR_1 331 -#define _CALL_TUPLE_1 332 -#define _CALL_TYPE_1 333 -#define _CHECK_AND_ALLOCATE_OBJECT 334 -#define _CHECK_ATTR_CLASS 335 -#define _CHECK_ATTR_METHOD_LAZY_DICT 336 -#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 337 +#define _CALL_METHOD_DESCRIPTOR_FAST 327 +#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 328 +#define _CALL_METHOD_DESCRIPTOR_NOARGS 329 +#define _CALL_METHOD_DESCRIPTOR_O 330 +#define _CALL_NON_PY_GENERAL 331 +#define _CALL_STR_1 332 +#define _CALL_TUPLE_1 333 +#define _CALL_TYPE_1 334 +#define _CHECK_AND_ALLOCATE_OBJECT 335 +#define _CHECK_ATTR_CLASS 336 +#define _CHECK_ATTR_METHOD_LAZY_DICT 337 +#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 338 #define _CHECK_EG_MATCH CHECK_EG_MATCH #define _CHECK_EXC_MATCH CHECK_EXC_MATCH -#define _CHECK_FUNCTION 338 -#define _CHECK_FUNCTION_EXACT_ARGS 339 -#define _CHECK_FUNCTION_VERSION 340 -#define _CHECK_FUNCTION_VERSION_INLINE 341 -#define _CHECK_FUNCTION_VERSION_KW 342 -#define _CHECK_IS_NOT_PY_CALLABLE 343 -#define _CHECK_IS_NOT_PY_CALLABLE_KW 344 -#define _CHECK_MANAGED_OBJECT_HAS_VALUES 345 -#define _CHECK_METHOD_VERSION 346 -#define _CHECK_METHOD_VERSION_KW 347 -#define _CHECK_PEP_523 348 -#define _CHECK_PERIODIC 349 -#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 350 -#define _CHECK_RECURSION_REMAINING 351 -#define _CHECK_STACK_SPACE 352 -#define _CHECK_STACK_SPACE_OPERAND 353 -#define _CHECK_VALIDITY 354 -#define _COMPARE_OP 355 -#define _COMPARE_OP_FLOAT 356 -#define _COMPARE_OP_INT 357 -#define _COMPARE_OP_STR 358 -#define _CONTAINS_OP 359 -#define _CONTAINS_OP_DICT 360 -#define _CONTAINS_OP_SET 361 +#define _CHECK_FUNCTION 339 +#define _CHECK_FUNCTION_EXACT_ARGS 340 +#define _CHECK_FUNCTION_VERSION 341 +#define _CHECK_FUNCTION_VERSION_INLINE 342 +#define _CHECK_FUNCTION_VERSION_KW 343 +#define _CHECK_IS_NOT_PY_CALLABLE 344 +#define _CHECK_IS_NOT_PY_CALLABLE_KW 345 +#define _CHECK_MANAGED_OBJECT_HAS_VALUES 346 +#define _CHECK_METHOD_VERSION 347 +#define _CHECK_METHOD_VERSION_KW 348 +#define _CHECK_PEP_523 349 +#define _CHECK_PERIODIC 350 +#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 351 +#define _CHECK_RECURSION_REMAINING 352 +#define _CHECK_STACK_SPACE 353 +#define _CHECK_STACK_SPACE_OPERAND 354 +#define _CHECK_VALIDITY 355 +#define _COMPARE_OP 356 +#define _COMPARE_OP_FLOAT 357 +#define _COMPARE_OP_INT 358 +#define _COMPARE_OP_STR 359 +#define _CONTAINS_OP 360 +#define _CONTAINS_OP_DICT 361 +#define _CONTAINS_OP_SET 362 #define _CONVERT_VALUE CONVERT_VALUE #define _COPY COPY #define _COPY_FREE_VARS COPY_FREE_VARS -#define _CREATE_INIT_FRAME 362 +#define _CREATE_INIT_FRAME 363 #define _DELETE_ATTR DELETE_ATTR #define _DELETE_DEREF DELETE_DEREF #define _DELETE_FAST DELETE_FAST #define _DELETE_GLOBAL DELETE_GLOBAL #define _DELETE_NAME DELETE_NAME #define _DELETE_SUBSCR DELETE_SUBSCR -#define _DEOPT 363 +#define _DEOPT 364 #define _DICT_MERGE DICT_MERGE #define _DICT_UPDATE DICT_UPDATE -#define _DO_CALL 364 -#define _DO_CALL_FUNCTION_EX 365 -#define _DO_CALL_KW 366 +#define _DO_CALL 365 +#define _DO_CALL_FUNCTION_EX 366 +#define _DO_CALL_KW 367 #define _END_FOR END_FOR #define _END_SEND END_SEND -#define _ERROR_POP_N 367 +#define _ERROR_POP_N 368 #define _EXIT_INIT_CHECK EXIT_INIT_CHECK -#define _EXPAND_METHOD 368 -#define _EXPAND_METHOD_KW 369 -#define _FATAL_ERROR 370 +#define _EXPAND_METHOD 369 +#define _EXPAND_METHOD_KW 370 +#define _FATAL_ERROR 371 #define _FORMAT_SIMPLE FORMAT_SIMPLE #define _FORMAT_WITH_SPEC FORMAT_WITH_SPEC -#define _FOR_ITER 371 -#define _FOR_ITER_GEN_FRAME 372 -#define _FOR_ITER_TIER_TWO 373 +#define _FOR_ITER 372 +#define _FOR_ITER_GEN_FRAME 373 +#define _FOR_ITER_TIER_TWO 374 #define _GET_AITER GET_AITER #define _GET_ANEXT GET_ANEXT #define _GET_AWAITABLE GET_AWAITABLE #define _GET_ITER GET_ITER #define _GET_LEN GET_LEN #define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER -#define _GUARD_BINARY_OP_EXTEND 374 -#define _GUARD_CALLABLE_LEN 375 -#define _GUARD_CALLABLE_STR_1 376 -#define _GUARD_CALLABLE_TUPLE_1 377 -#define _GUARD_CALLABLE_TYPE_1 378 -#define _GUARD_DORV_NO_DICT 379 -#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 380 -#define _GUARD_GLOBALS_VERSION 381 -#define _GUARD_IS_FALSE_POP 382 -#define _GUARD_IS_NONE_POP 383 -#define _GUARD_IS_NOT_NONE_POP 384 -#define _GUARD_IS_TRUE_POP 385 -#define _GUARD_KEYS_VERSION 386 -#define _GUARD_NOS_DICT 387 -#define _GUARD_NOS_FLOAT 388 -#define _GUARD_NOS_INT 389 -#define _GUARD_NOS_LIST 390 -#define _GUARD_NOS_NULL 391 -#define _GUARD_NOS_TUPLE 392 -#define _GUARD_NOS_UNICODE 393 -#define _GUARD_NOT_EXHAUSTED_LIST 394 -#define _GUARD_NOT_EXHAUSTED_RANGE 395 -#define _GUARD_NOT_EXHAUSTED_TUPLE 396 -#define _GUARD_TOS_ANY_SET 397 -#define _GUARD_TOS_DICT 398 -#define _GUARD_TOS_FLOAT 399 -#define _GUARD_TOS_INT 400 -#define _GUARD_TOS_LIST 401 -#define _GUARD_TOS_SLICE 402 -#define _GUARD_TOS_TUPLE 403 -#define _GUARD_TOS_UNICODE 404 -#define _GUARD_TYPE_VERSION 405 -#define _GUARD_TYPE_VERSION_AND_LOCK 406 +#define _GUARD_BINARY_OP_EXTEND 375 +#define _GUARD_CALLABLE_ISINSTANCE 376 +#define _GUARD_CALLABLE_LEN 377 +#define _GUARD_CALLABLE_STR_1 378 +#define _GUARD_CALLABLE_TUPLE_1 379 +#define _GUARD_CALLABLE_TYPE_1 380 +#define _GUARD_DORV_NO_DICT 381 +#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 382 +#define _GUARD_GLOBALS_VERSION 383 +#define _GUARD_IS_FALSE_POP 384 +#define _GUARD_IS_NONE_POP 385 +#define _GUARD_IS_NOT_NONE_POP 386 +#define _GUARD_IS_TRUE_POP 387 +#define _GUARD_KEYS_VERSION 388 +#define _GUARD_NOS_DICT 389 +#define _GUARD_NOS_FLOAT 390 +#define _GUARD_NOS_INT 391 +#define _GUARD_NOS_LIST 392 +#define _GUARD_NOS_NULL 393 +#define _GUARD_NOS_TUPLE 394 +#define _GUARD_NOS_UNICODE 395 +#define _GUARD_NOT_EXHAUSTED_LIST 396 +#define _GUARD_NOT_EXHAUSTED_RANGE 397 +#define _GUARD_NOT_EXHAUSTED_TUPLE 398 +#define _GUARD_THIRD_NULL 399 +#define _GUARD_TOS_ANY_SET 400 +#define _GUARD_TOS_DICT 401 +#define _GUARD_TOS_FLOAT 402 +#define _GUARD_TOS_INT 403 +#define _GUARD_TOS_LIST 404 +#define _GUARD_TOS_SLICE 405 +#define _GUARD_TOS_TUPLE 406 +#define _GUARD_TOS_UNICODE 407 +#define _GUARD_TYPE_VERSION 408 +#define _GUARD_TYPE_VERSION_AND_LOCK 409 #define _IMPORT_FROM IMPORT_FROM #define _IMPORT_NAME IMPORT_NAME -#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 407 -#define _INIT_CALL_PY_EXACT_ARGS 408 -#define _INIT_CALL_PY_EXACT_ARGS_0 409 -#define _INIT_CALL_PY_EXACT_ARGS_1 410 -#define _INIT_CALL_PY_EXACT_ARGS_2 411 -#define _INIT_CALL_PY_EXACT_ARGS_3 412 -#define _INIT_CALL_PY_EXACT_ARGS_4 413 -#define _INSERT_NULL 414 +#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 410 +#define _INIT_CALL_PY_EXACT_ARGS 411 +#define _INIT_CALL_PY_EXACT_ARGS_0 412 +#define _INIT_CALL_PY_EXACT_ARGS_1 413 +#define _INIT_CALL_PY_EXACT_ARGS_2 414 +#define _INIT_CALL_PY_EXACT_ARGS_3 415 +#define _INIT_CALL_PY_EXACT_ARGS_4 416 +#define _INSERT_NULL 417 #define _INSTRUMENTED_FOR_ITER INSTRUMENTED_FOR_ITER #define _INSTRUMENTED_INSTRUCTION INSTRUMENTED_INSTRUCTION #define _INSTRUMENTED_JUMP_FORWARD INSTRUMENTED_JUMP_FORWARD @@ -171,163 +173,163 @@ extern "C" { #define _INSTRUMENTED_POP_JUMP_IF_NONE INSTRUMENTED_POP_JUMP_IF_NONE #define _INSTRUMENTED_POP_JUMP_IF_NOT_NONE INSTRUMENTED_POP_JUMP_IF_NOT_NONE #define _INSTRUMENTED_POP_JUMP_IF_TRUE INSTRUMENTED_POP_JUMP_IF_TRUE -#define _IS_NONE 415 +#define _IS_NONE 418 #define _IS_OP IS_OP -#define _ITER_CHECK_LIST 416 -#define _ITER_CHECK_RANGE 417 -#define _ITER_CHECK_TUPLE 418 -#define _ITER_JUMP_LIST 419 -#define _ITER_JUMP_RANGE 420 -#define _ITER_JUMP_TUPLE 421 -#define _ITER_NEXT_LIST 422 -#define _ITER_NEXT_LIST_TIER_TWO 423 -#define _ITER_NEXT_RANGE 424 -#define _ITER_NEXT_TUPLE 425 -#define _JUMP_TO_TOP 426 +#define _ITER_CHECK_LIST 419 +#define _ITER_CHECK_RANGE 420 +#define _ITER_CHECK_TUPLE 421 +#define _ITER_JUMP_LIST 422 +#define _ITER_JUMP_RANGE 423 +#define _ITER_JUMP_TUPLE 424 +#define _ITER_NEXT_LIST 425 +#define _ITER_NEXT_LIST_TIER_TWO 426 +#define _ITER_NEXT_RANGE 427 +#define _ITER_NEXT_TUPLE 428 +#define _JUMP_TO_TOP 429 #define _LIST_APPEND LIST_APPEND #define _LIST_EXTEND LIST_EXTEND -#define _LOAD_ATTR 427 -#define _LOAD_ATTR_CLASS 428 +#define _LOAD_ATTR 430 +#define _LOAD_ATTR_CLASS 431 #define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN -#define _LOAD_ATTR_INSTANCE_VALUE 429 -#define _LOAD_ATTR_METHOD_LAZY_DICT 430 -#define _LOAD_ATTR_METHOD_NO_DICT 431 -#define _LOAD_ATTR_METHOD_WITH_VALUES 432 -#define _LOAD_ATTR_MODULE 433 -#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 434 -#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 435 -#define _LOAD_ATTR_PROPERTY_FRAME 436 -#define _LOAD_ATTR_SLOT 437 -#define _LOAD_ATTR_WITH_HINT 438 +#define _LOAD_ATTR_INSTANCE_VALUE 432 +#define _LOAD_ATTR_METHOD_LAZY_DICT 433 +#define _LOAD_ATTR_METHOD_NO_DICT 434 +#define _LOAD_ATTR_METHOD_WITH_VALUES 435 +#define _LOAD_ATTR_MODULE 436 +#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 437 +#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 438 +#define _LOAD_ATTR_PROPERTY_FRAME 439 +#define _LOAD_ATTR_SLOT 440 +#define _LOAD_ATTR_WITH_HINT 441 #define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS -#define _LOAD_BYTECODE 439 +#define _LOAD_BYTECODE 442 #define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT #define _LOAD_CONST LOAD_CONST #define _LOAD_CONST_IMMORTAL LOAD_CONST_IMMORTAL -#define _LOAD_CONST_INLINE 440 -#define _LOAD_CONST_INLINE_BORROW 441 +#define _LOAD_CONST_INLINE 443 +#define _LOAD_CONST_INLINE_BORROW 444 #define _LOAD_CONST_MORTAL LOAD_CONST_MORTAL #define _LOAD_DEREF LOAD_DEREF -#define _LOAD_FAST 442 -#define _LOAD_FAST_0 443 -#define _LOAD_FAST_1 444 -#define _LOAD_FAST_2 445 -#define _LOAD_FAST_3 446 -#define _LOAD_FAST_4 447 -#define _LOAD_FAST_5 448 -#define _LOAD_FAST_6 449 -#define _LOAD_FAST_7 450 +#define _LOAD_FAST 445 +#define _LOAD_FAST_0 446 +#define _LOAD_FAST_1 447 +#define _LOAD_FAST_2 448 +#define _LOAD_FAST_3 449 +#define _LOAD_FAST_4 450 +#define _LOAD_FAST_5 451 +#define _LOAD_FAST_6 452 +#define _LOAD_FAST_7 453 #define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR -#define _LOAD_FAST_BORROW 451 -#define _LOAD_FAST_BORROW_0 452 -#define _LOAD_FAST_BORROW_1 453 -#define _LOAD_FAST_BORROW_2 454 -#define _LOAD_FAST_BORROW_3 455 -#define _LOAD_FAST_BORROW_4 456 -#define _LOAD_FAST_BORROW_5 457 -#define _LOAD_FAST_BORROW_6 458 -#define _LOAD_FAST_BORROW_7 459 +#define _LOAD_FAST_BORROW 454 +#define _LOAD_FAST_BORROW_0 455 +#define _LOAD_FAST_BORROW_1 456 +#define _LOAD_FAST_BORROW_2 457 +#define _LOAD_FAST_BORROW_3 458 +#define _LOAD_FAST_BORROW_4 459 +#define _LOAD_FAST_BORROW_5 460 +#define _LOAD_FAST_BORROW_6 461 +#define _LOAD_FAST_BORROW_7 462 #define _LOAD_FAST_BORROW_LOAD_FAST_BORROW LOAD_FAST_BORROW_LOAD_FAST_BORROW #define _LOAD_FAST_CHECK LOAD_FAST_CHECK #define _LOAD_FAST_LOAD_FAST LOAD_FAST_LOAD_FAST #define _LOAD_FROM_DICT_OR_DEREF LOAD_FROM_DICT_OR_DEREF #define _LOAD_FROM_DICT_OR_GLOBALS LOAD_FROM_DICT_OR_GLOBALS -#define _LOAD_GLOBAL 460 -#define _LOAD_GLOBAL_BUILTINS 461 -#define _LOAD_GLOBAL_MODULE 462 +#define _LOAD_GLOBAL 463 +#define _LOAD_GLOBAL_BUILTINS 464 +#define _LOAD_GLOBAL_MODULE 465 #define _LOAD_LOCALS LOAD_LOCALS #define _LOAD_NAME LOAD_NAME -#define _LOAD_SMALL_INT 463 -#define _LOAD_SMALL_INT_0 464 -#define _LOAD_SMALL_INT_1 465 -#define _LOAD_SMALL_INT_2 466 -#define _LOAD_SMALL_INT_3 467 -#define _LOAD_SPECIAL 468 +#define _LOAD_SMALL_INT 466 +#define _LOAD_SMALL_INT_0 467 +#define _LOAD_SMALL_INT_1 468 +#define _LOAD_SMALL_INT_2 469 +#define _LOAD_SMALL_INT_3 470 +#define _LOAD_SPECIAL 471 #define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR #define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD -#define _MAKE_CALLARGS_A_TUPLE 469 +#define _MAKE_CALLARGS_A_TUPLE 472 #define _MAKE_CELL MAKE_CELL #define _MAKE_FUNCTION MAKE_FUNCTION -#define _MAKE_WARM 470 +#define _MAKE_WARM 473 #define _MAP_ADD MAP_ADD #define _MATCH_CLASS MATCH_CLASS #define _MATCH_KEYS MATCH_KEYS #define _MATCH_MAPPING MATCH_MAPPING #define _MATCH_SEQUENCE MATCH_SEQUENCE -#define _MAYBE_EXPAND_METHOD 471 -#define _MAYBE_EXPAND_METHOD_KW 472 -#define _MONITOR_CALL 473 -#define _MONITOR_CALL_KW 474 -#define _MONITOR_JUMP_BACKWARD 475 -#define _MONITOR_RESUME 476 +#define _MAYBE_EXPAND_METHOD 474 +#define _MAYBE_EXPAND_METHOD_KW 475 +#define _MONITOR_CALL 476 +#define _MONITOR_CALL_KW 477 +#define _MONITOR_JUMP_BACKWARD 478 +#define _MONITOR_RESUME 479 #define _NOP NOP #define _POP_EXCEPT POP_EXCEPT -#define _POP_JUMP_IF_FALSE 477 -#define _POP_JUMP_IF_TRUE 478 +#define _POP_JUMP_IF_FALSE 480 +#define _POP_JUMP_IF_TRUE 481 #define _POP_TOP POP_TOP -#define _POP_TOP_LOAD_CONST_INLINE 479 -#define _POP_TOP_LOAD_CONST_INLINE_BORROW 480 -#define _POP_TWO_LOAD_CONST_INLINE_BORROW 481 +#define _POP_TOP_LOAD_CONST_INLINE 482 +#define _POP_TOP_LOAD_CONST_INLINE_BORROW 483 +#define _POP_TWO_LOAD_CONST_INLINE_BORROW 484 #define _PUSH_EXC_INFO PUSH_EXC_INFO -#define _PUSH_FRAME 482 +#define _PUSH_FRAME 485 #define _PUSH_NULL PUSH_NULL -#define _PUSH_NULL_CONDITIONAL 483 -#define _PY_FRAME_GENERAL 484 -#define _PY_FRAME_KW 485 -#define _QUICKEN_RESUME 486 -#define _REPLACE_WITH_TRUE 487 +#define _PUSH_NULL_CONDITIONAL 486 +#define _PY_FRAME_GENERAL 487 +#define _PY_FRAME_KW 488 +#define _QUICKEN_RESUME 489 +#define _REPLACE_WITH_TRUE 490 #define _RESUME_CHECK RESUME_CHECK #define _RETURN_GENERATOR RETURN_GENERATOR #define _RETURN_VALUE RETURN_VALUE -#define _SAVE_RETURN_OFFSET 488 -#define _SEND 489 -#define _SEND_GEN_FRAME 490 +#define _SAVE_RETURN_OFFSET 491 +#define _SEND 492 +#define _SEND_GEN_FRAME 493 #define _SETUP_ANNOTATIONS SETUP_ANNOTATIONS #define _SET_ADD SET_ADD #define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE #define _SET_UPDATE SET_UPDATE -#define _START_EXECUTOR 491 -#define _STORE_ATTR 492 -#define _STORE_ATTR_INSTANCE_VALUE 493 -#define _STORE_ATTR_SLOT 494 -#define _STORE_ATTR_WITH_HINT 495 +#define _START_EXECUTOR 494 +#define _STORE_ATTR 495 +#define _STORE_ATTR_INSTANCE_VALUE 496 +#define _STORE_ATTR_SLOT 497 +#define _STORE_ATTR_WITH_HINT 498 #define _STORE_DEREF STORE_DEREF -#define _STORE_FAST 496 -#define _STORE_FAST_0 497 -#define _STORE_FAST_1 498 -#define _STORE_FAST_2 499 -#define _STORE_FAST_3 500 -#define _STORE_FAST_4 501 -#define _STORE_FAST_5 502 -#define _STORE_FAST_6 503 -#define _STORE_FAST_7 504 +#define _STORE_FAST 499 +#define _STORE_FAST_0 500 +#define _STORE_FAST_1 501 +#define _STORE_FAST_2 502 +#define _STORE_FAST_3 503 +#define _STORE_FAST_4 504 +#define _STORE_FAST_5 505 +#define _STORE_FAST_6 506 +#define _STORE_FAST_7 507 #define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST #define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST #define _STORE_GLOBAL STORE_GLOBAL #define _STORE_NAME STORE_NAME -#define _STORE_SLICE 505 -#define _STORE_SUBSCR 506 -#define _STORE_SUBSCR_DICT 507 -#define _STORE_SUBSCR_LIST_INT 508 +#define _STORE_SLICE 508 +#define _STORE_SUBSCR 509 +#define _STORE_SUBSCR_DICT 510 +#define _STORE_SUBSCR_LIST_INT 511 #define _SWAP SWAP -#define _TIER2_RESUME_CHECK 509 -#define _TO_BOOL 510 +#define _TIER2_RESUME_CHECK 512 +#define _TO_BOOL 513 #define _TO_BOOL_BOOL TO_BOOL_BOOL #define _TO_BOOL_INT TO_BOOL_INT -#define _TO_BOOL_LIST 511 +#define _TO_BOOL_LIST 514 #define _TO_BOOL_NONE TO_BOOL_NONE -#define _TO_BOOL_STR 512 +#define _TO_BOOL_STR 515 #define _UNARY_INVERT UNARY_INVERT #define _UNARY_NEGATIVE UNARY_NEGATIVE #define _UNARY_NOT UNARY_NOT #define _UNPACK_EX UNPACK_EX -#define _UNPACK_SEQUENCE 513 -#define _UNPACK_SEQUENCE_LIST 514 -#define _UNPACK_SEQUENCE_TUPLE 515 -#define _UNPACK_SEQUENCE_TWO_TUPLE 516 +#define _UNPACK_SEQUENCE 516 +#define _UNPACK_SEQUENCE_LIST 517 +#define _UNPACK_SEQUENCE_TUPLE 518 +#define _UNPACK_SEQUENCE_TWO_TUPLE 519 #define _WITH_EXCEPT_START WITH_EXCEPT_START #define _YIELD_VALUE YIELD_VALUE -#define MAX_UOP_ID 516 +#define MAX_UOP_ID 519 #ifdef __cplusplus } diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index f6bfff81d2e1ba..88a2e538447034 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -261,7 +261,8 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_CALL_BUILTIN_O] = HAS_ARG_FLAG | HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_BUILTIN_FAST] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CALL_BUILTIN_FAST_WITH_KEYWORDS] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, - [_CALL_LEN] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, + [_GUARD_CALLABLE_LEN] = HAS_DEOPT_FLAG, + [_CALL_LEN] = HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_GUARD_CALLABLE_ISINSTANCE] = HAS_DEOPT_FLAG, [_CALL_ISINSTANCE] = HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG, [_CALL_LIST_APPEND] = HAS_ARG_FLAG | HAS_DEOPT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -427,6 +428,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_GET_YIELD_FROM_ITER] = "_GET_YIELD_FROM_ITER", [_GUARD_BINARY_OP_EXTEND] = "_GUARD_BINARY_OP_EXTEND", [_GUARD_CALLABLE_ISINSTANCE] = "_GUARD_CALLABLE_ISINSTANCE", + [_GUARD_CALLABLE_LEN] = "_GUARD_CALLABLE_LEN", [_GUARD_CALLABLE_STR_1] = "_GUARD_CALLABLE_STR_1", [_GUARD_CALLABLE_TUPLE_1] = "_GUARD_CALLABLE_TUPLE_1", [_GUARD_CALLABLE_TYPE_1] = "_GUARD_CALLABLE_TYPE_1", @@ -1101,7 +1103,7 @@ int _PyUop_num_popped(int opcode, int oparg) case _GUARD_CALLABLE_LEN: return 0; case _CALL_LEN: - return 2 + oparg; + return 3; case _GUARD_CALLABLE_ISINSTANCE: return 0; case _CALL_ISINSTANCE: