Files
cpython/Include/internal/pycore_uop_ids.h
Ken Jin 4fa80ce74c gh-139109: A new tracing JIT compiler frontend for CPython (GH-140310)
This PR changes the current JIT model from trace projection to trace recording. Benchmarking: better pyperformance (about 1.7% overall) geomean versus current https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251108-3.15.0a1%2B-7e2bc1d-JIT/bm-20251108-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-7e2bc1d-vs-base.svg, 100% faster Richards on the most improved benchmark versus the current JIT. Slowdown of about 10-15% on the worst benchmark versus the current JIT. **Note: the fastest version isn't the one merged, as it relies on fixing bugs in the specializing interpreter, which is left to another PR**. The speedup in the merged version is about 1.1%. https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251112-3.15.0a1%2B-f8a764a-JIT/bm-20251112-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-f8a764a-vs-base.svg

Stats: 50% more uops executed, 30% more traces entered the last time we ran them. It also suggests our trace lengths for a real trace recording JIT are too short, as a lot of trace too long aborts https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20251023-3.15.0a1%2B-eb73378-CLANG%2CJIT/bm-20251023-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-eb73378-pystats-vs-base.md .

This new JIT frontend is already able to record/execute significantly more instructions than the previous JIT frontend. In this PR, we are now able to record through custom dunders, simple object creation, generators, etc. None of these were done by the old JIT frontend. Some custom dunders uops were discovered to be broken as part of this work gh-140277

The optimizer stack space check is disabled, as it's no longer valid to deal with underflow.

Pros:
* Ignoring the generated tracer code as it's automatically created, this is only additional 1k lines of code. The maintenance burden is handled by the DSL and code generator.
* `optimizer.c` is now significantly simpler, as we don't have to do strange things to recover the bytecode from a trace.
* The new JIT frontend is able to handle a lot more control-flow than the old one.
* Tracing is very low overhead. We use the tail calling interpreter/computed goto interpreter to switch between tracing mode and non-tracing mode. I call this mechanism dual dispatch, as we have two dispatch tables dispatching to each other. Specialization is still enabled while tracing.
* Better handling of polymorphism. We leverage the specializing interpreter for this.

Cons:
* (For now) requires tail calling interpreter or computed gotos. This means no Windows JIT for now :(. Not to fret, tail calling is coming soon to Windows though https://github.com/python/cpython/pull/139962

Design:
* After each instruction, the `record_previous_inst` function/label is executed. This does as the name suggests.
* The tracing interpreter lowers bytecode to uops directly so that it can obtain "fresh" values at the point of lowering.
* The tracing version behaves nearly identical to the normal interpreter, in fact it even has specialization! This allows it to run without much of a slowdown when tracing. The actual cost of tracing is only a function call and writes to memory.
* The tracing interpreter uses the specializing interpreter's deopt to naturally form the side exit chains. This allows it to side exit chain effectively, without repeating much code. We force a re-specializing when tracing a deopt.
* The tracing interpreter can even handle goto errors/exceptions, but I chose to disable them for now as it's not tested.
* Because we do not share interpreter dispatch, there is should be no significant slowdown to the original specializing interpreter on tailcall and computed got with JIT disabled. With JIT enabled, there might be a slowdown in the form of the JIT trying to trace.
* Things that could have dynamic instruction pointer effects are guarded on. The guard deopts to a new instruction --- `_DYNAMIC_EXIT`.
2025-11-13 18:08:32 +00:00

371 lines
12 KiB
C
Generated

// This file is generated by Tools/cases_generator/uop_id_generator.py
// from:
// Python/bytecodes.c
// Do not edit!
#ifndef Py_CORE_UOP_IDS_H
#define Py_CORE_UOP_IDS_H
#ifdef __cplusplus
extern "C" {
#endif
#define _EXIT_TRACE 300
#define _SET_IP 301
#define _BINARY_OP 302
#define _BINARY_OP_ADD_FLOAT 303
#define _BINARY_OP_ADD_FLOAT__NO_DECREF_INPUTS 304
#define _BINARY_OP_ADD_INT 305
#define _BINARY_OP_ADD_UNICODE 306
#define _BINARY_OP_EXTEND 307
#define _BINARY_OP_INPLACE_ADD_UNICODE 308
#define _BINARY_OP_MULTIPLY_FLOAT 309
#define _BINARY_OP_MULTIPLY_FLOAT__NO_DECREF_INPUTS 310
#define _BINARY_OP_MULTIPLY_INT 311
#define _BINARY_OP_SUBSCR_CHECK_FUNC 312
#define _BINARY_OP_SUBSCR_DICT 313
#define _BINARY_OP_SUBSCR_INIT_CALL 314
#define _BINARY_OP_SUBSCR_LIST_INT 315
#define _BINARY_OP_SUBSCR_LIST_SLICE 316
#define _BINARY_OP_SUBSCR_STR_INT 317
#define _BINARY_OP_SUBSCR_TUPLE_INT 318
#define _BINARY_OP_SUBTRACT_FLOAT 319
#define _BINARY_OP_SUBTRACT_FLOAT__NO_DECREF_INPUTS 320
#define _BINARY_OP_SUBTRACT_INT 321
#define _BINARY_SLICE 322
#define _BUILD_INTERPOLATION BUILD_INTERPOLATION
#define _BUILD_LIST BUILD_LIST
#define _BUILD_MAP BUILD_MAP
#define _BUILD_SET BUILD_SET
#define _BUILD_SLICE BUILD_SLICE
#define _BUILD_STRING BUILD_STRING
#define _BUILD_TEMPLATE BUILD_TEMPLATE
#define _BUILD_TUPLE BUILD_TUPLE
#define _CALL_BUILTIN_CLASS 323
#define _CALL_BUILTIN_FAST 324
#define _CALL_BUILTIN_FAST_WITH_KEYWORDS 325
#define _CALL_BUILTIN_O 326
#define _CALL_INTRINSIC_1 CALL_INTRINSIC_1
#define _CALL_INTRINSIC_2 CALL_INTRINSIC_2
#define _CALL_ISINSTANCE 327
#define _CALL_KW_NON_PY 328
#define _CALL_LEN 329
#define _CALL_LIST_APPEND 330
#define _CALL_METHOD_DESCRIPTOR_FAST 331
#define _CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 332
#define _CALL_METHOD_DESCRIPTOR_NOARGS 333
#define _CALL_METHOD_DESCRIPTOR_O 334
#define _CALL_NON_PY_GENERAL 335
#define _CALL_STR_1 336
#define _CALL_TUPLE_1 337
#define _CALL_TYPE_1 338
#define _CHECK_AND_ALLOCATE_OBJECT 339
#define _CHECK_ATTR_CLASS 340
#define _CHECK_ATTR_METHOD_LAZY_DICT 341
#define _CHECK_CALL_BOUND_METHOD_EXACT_ARGS 342
#define _CHECK_EG_MATCH CHECK_EG_MATCH
#define _CHECK_EXC_MATCH CHECK_EXC_MATCH
#define _CHECK_FUNCTION_EXACT_ARGS 343
#define _CHECK_FUNCTION_VERSION 344
#define _CHECK_FUNCTION_VERSION_INLINE 345
#define _CHECK_FUNCTION_VERSION_KW 346
#define _CHECK_IS_NOT_PY_CALLABLE 347
#define _CHECK_IS_NOT_PY_CALLABLE_KW 348
#define _CHECK_MANAGED_OBJECT_HAS_VALUES 349
#define _CHECK_METHOD_VERSION 350
#define _CHECK_METHOD_VERSION_KW 351
#define _CHECK_PEP_523 352
#define _CHECK_PERIODIC 353
#define _CHECK_PERIODIC_AT_END 354
#define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 355
#define _CHECK_RECURSION_REMAINING 356
#define _CHECK_STACK_SPACE 357
#define _CHECK_STACK_SPACE_OPERAND 358
#define _CHECK_VALIDITY 359
#define _COLD_DYNAMIC_EXIT 360
#define _COLD_EXIT 361
#define _COMPARE_OP 362
#define _COMPARE_OP_FLOAT 363
#define _COMPARE_OP_INT 364
#define _COMPARE_OP_STR 365
#define _CONTAINS_OP 366
#define _CONTAINS_OP_DICT 367
#define _CONTAINS_OP_SET 368
#define _CONVERT_VALUE CONVERT_VALUE
#define _COPY 369
#define _COPY_1 370
#define _COPY_2 371
#define _COPY_3 372
#define _COPY_FREE_VARS COPY_FREE_VARS
#define _CREATE_INIT_FRAME 373
#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 374
#define _DICT_MERGE DICT_MERGE
#define _DICT_UPDATE DICT_UPDATE
#define _DO_CALL 375
#define _DO_CALL_FUNCTION_EX 376
#define _DO_CALL_KW 377
#define _DYNAMIC_EXIT 378
#define _END_FOR END_FOR
#define _END_SEND END_SEND
#define _ERROR_POP_N 379
#define _EXIT_INIT_CHECK EXIT_INIT_CHECK
#define _EXPAND_METHOD 380
#define _EXPAND_METHOD_KW 381
#define _FATAL_ERROR 382
#define _FORMAT_SIMPLE FORMAT_SIMPLE
#define _FORMAT_WITH_SPEC FORMAT_WITH_SPEC
#define _FOR_ITER 383
#define _FOR_ITER_GEN_FRAME 384
#define _FOR_ITER_TIER_TWO 385
#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 386
#define _GUARD_CALLABLE_ISINSTANCE 387
#define _GUARD_CALLABLE_LEN 388
#define _GUARD_CALLABLE_LIST_APPEND 389
#define _GUARD_CALLABLE_STR_1 390
#define _GUARD_CALLABLE_TUPLE_1 391
#define _GUARD_CALLABLE_TYPE_1 392
#define _GUARD_DORV_NO_DICT 393
#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 394
#define _GUARD_GLOBALS_VERSION 395
#define _GUARD_IP_RETURN_GENERATOR 396
#define _GUARD_IP_RETURN_VALUE 397
#define _GUARD_IP_YIELD_VALUE 398
#define _GUARD_IP__PUSH_FRAME 399
#define _GUARD_IS_FALSE_POP 400
#define _GUARD_IS_NONE_POP 401
#define _GUARD_IS_NOT_NONE_POP 402
#define _GUARD_IS_TRUE_POP 403
#define _GUARD_KEYS_VERSION 404
#define _GUARD_NOS_DICT 405
#define _GUARD_NOS_FLOAT 406
#define _GUARD_NOS_INT 407
#define _GUARD_NOS_LIST 408
#define _GUARD_NOS_NOT_NULL 409
#define _GUARD_NOS_NULL 410
#define _GUARD_NOS_OVERFLOWED 411
#define _GUARD_NOS_TUPLE 412
#define _GUARD_NOS_UNICODE 413
#define _GUARD_NOT_EXHAUSTED_LIST 414
#define _GUARD_NOT_EXHAUSTED_RANGE 415
#define _GUARD_NOT_EXHAUSTED_TUPLE 416
#define _GUARD_THIRD_NULL 417
#define _GUARD_TOS_ANY_SET 418
#define _GUARD_TOS_DICT 419
#define _GUARD_TOS_FLOAT 420
#define _GUARD_TOS_INT 421
#define _GUARD_TOS_LIST 422
#define _GUARD_TOS_OVERFLOWED 423
#define _GUARD_TOS_SLICE 424
#define _GUARD_TOS_TUPLE 425
#define _GUARD_TOS_UNICODE 426
#define _GUARD_TYPE_VERSION 427
#define _GUARD_TYPE_VERSION_AND_LOCK 428
#define _HANDLE_PENDING_AND_DEOPT 429
#define _IMPORT_FROM IMPORT_FROM
#define _IMPORT_NAME IMPORT_NAME
#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 430
#define _INIT_CALL_PY_EXACT_ARGS 431
#define _INIT_CALL_PY_EXACT_ARGS_0 432
#define _INIT_CALL_PY_EXACT_ARGS_1 433
#define _INIT_CALL_PY_EXACT_ARGS_2 434
#define _INIT_CALL_PY_EXACT_ARGS_3 435
#define _INIT_CALL_PY_EXACT_ARGS_4 436
#define _INSERT_NULL 437
#define _INSTRUMENTED_FOR_ITER INSTRUMENTED_FOR_ITER
#define _INSTRUMENTED_INSTRUCTION INSTRUMENTED_INSTRUCTION
#define _INSTRUMENTED_JUMP_FORWARD INSTRUMENTED_JUMP_FORWARD
#define _INSTRUMENTED_LINE INSTRUMENTED_LINE
#define _INSTRUMENTED_NOT_TAKEN INSTRUMENTED_NOT_TAKEN
#define _INSTRUMENTED_POP_JUMP_IF_FALSE INSTRUMENTED_POP_JUMP_IF_FALSE
#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 438
#define _IS_OP IS_OP
#define _ITER_CHECK_LIST 439
#define _ITER_CHECK_RANGE 440
#define _ITER_CHECK_TUPLE 441
#define _ITER_JUMP_LIST 442
#define _ITER_JUMP_RANGE 443
#define _ITER_JUMP_TUPLE 444
#define _ITER_NEXT_LIST 445
#define _ITER_NEXT_LIST_TIER_TWO 446
#define _ITER_NEXT_RANGE 447
#define _ITER_NEXT_TUPLE 448
#define _JUMP_BACKWARD_NO_INTERRUPT JUMP_BACKWARD_NO_INTERRUPT
#define _JUMP_TO_TOP 449
#define _LIST_APPEND LIST_APPEND
#define _LIST_EXTEND LIST_EXTEND
#define _LOAD_ATTR 450
#define _LOAD_ATTR_CLASS 451
#define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
#define _LOAD_ATTR_INSTANCE_VALUE 452
#define _LOAD_ATTR_METHOD_LAZY_DICT 453
#define _LOAD_ATTR_METHOD_NO_DICT 454
#define _LOAD_ATTR_METHOD_WITH_VALUES 455
#define _LOAD_ATTR_MODULE 456
#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 457
#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 458
#define _LOAD_ATTR_PROPERTY_FRAME 459
#define _LOAD_ATTR_SLOT 460
#define _LOAD_ATTR_WITH_HINT 461
#define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS
#define _LOAD_BYTECODE 462
#define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT
#define _LOAD_CONST LOAD_CONST
#define _LOAD_CONST_INLINE 463
#define _LOAD_CONST_INLINE_BORROW 464
#define _LOAD_CONST_UNDER_INLINE 465
#define _LOAD_CONST_UNDER_INLINE_BORROW 466
#define _LOAD_DEREF LOAD_DEREF
#define _LOAD_FAST 467
#define _LOAD_FAST_0 468
#define _LOAD_FAST_1 469
#define _LOAD_FAST_2 470
#define _LOAD_FAST_3 471
#define _LOAD_FAST_4 472
#define _LOAD_FAST_5 473
#define _LOAD_FAST_6 474
#define _LOAD_FAST_7 475
#define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR
#define _LOAD_FAST_BORROW 476
#define _LOAD_FAST_BORROW_0 477
#define _LOAD_FAST_BORROW_1 478
#define _LOAD_FAST_BORROW_2 479
#define _LOAD_FAST_BORROW_3 480
#define _LOAD_FAST_BORROW_4 481
#define _LOAD_FAST_BORROW_5 482
#define _LOAD_FAST_BORROW_6 483
#define _LOAD_FAST_BORROW_7 484
#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 485
#define _LOAD_GLOBAL_BUILTINS 486
#define _LOAD_GLOBAL_MODULE 487
#define _LOAD_LOCALS LOAD_LOCALS
#define _LOAD_NAME LOAD_NAME
#define _LOAD_SMALL_INT 488
#define _LOAD_SMALL_INT_0 489
#define _LOAD_SMALL_INT_1 490
#define _LOAD_SMALL_INT_2 491
#define _LOAD_SMALL_INT_3 492
#define _LOAD_SPECIAL 493
#define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR
#define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD
#define _MAKE_CALLARGS_A_TUPLE 494
#define _MAKE_CELL MAKE_CELL
#define _MAKE_FUNCTION MAKE_FUNCTION
#define _MAKE_WARM 495
#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 496
#define _MAYBE_EXPAND_METHOD_KW 497
#define _MONITOR_CALL 498
#define _MONITOR_CALL_KW 499
#define _MONITOR_JUMP_BACKWARD 500
#define _MONITOR_RESUME 501
#define _NOP NOP
#define _POP_CALL 502
#define _POP_CALL_LOAD_CONST_INLINE_BORROW 503
#define _POP_CALL_ONE 504
#define _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW 505
#define _POP_CALL_TWO 506
#define _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW 507
#define _POP_EXCEPT POP_EXCEPT
#define _POP_ITER POP_ITER
#define _POP_JUMP_IF_FALSE 508
#define _POP_JUMP_IF_TRUE 509
#define _POP_TOP POP_TOP
#define _POP_TOP_FLOAT 510
#define _POP_TOP_INT 511
#define _POP_TOP_LOAD_CONST_INLINE 512
#define _POP_TOP_LOAD_CONST_INLINE_BORROW 513
#define _POP_TOP_NOP 514
#define _POP_TOP_UNICODE 515
#define _POP_TWO 516
#define _POP_TWO_LOAD_CONST_INLINE_BORROW 517
#define _PUSH_EXC_INFO PUSH_EXC_INFO
#define _PUSH_FRAME 518
#define _PUSH_NULL PUSH_NULL
#define _PUSH_NULL_CONDITIONAL 519
#define _PY_FRAME_GENERAL 520
#define _PY_FRAME_KW 521
#define _QUICKEN_RESUME 522
#define _REPLACE_WITH_TRUE 523
#define _RESUME_CHECK RESUME_CHECK
#define _RETURN_GENERATOR RETURN_GENERATOR
#define _RETURN_VALUE RETURN_VALUE
#define _SAVE_RETURN_OFFSET 524
#define _SEND 525
#define _SEND_GEN_FRAME 526
#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 527
#define _STORE_ATTR 528
#define _STORE_ATTR_INSTANCE_VALUE 529
#define _STORE_ATTR_SLOT 530
#define _STORE_ATTR_WITH_HINT 531
#define _STORE_DEREF STORE_DEREF
#define _STORE_FAST 532
#define _STORE_FAST_0 533
#define _STORE_FAST_1 534
#define _STORE_FAST_2 535
#define _STORE_FAST_3 536
#define _STORE_FAST_4 537
#define _STORE_FAST_5 538
#define _STORE_FAST_6 539
#define _STORE_FAST_7 540
#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 541
#define _STORE_SUBSCR 542
#define _STORE_SUBSCR_DICT 543
#define _STORE_SUBSCR_LIST_INT 544
#define _SWAP 545
#define _SWAP_2 546
#define _SWAP_3 547
#define _TIER2_RESUME_CHECK 548
#define _TO_BOOL 549
#define _TO_BOOL_BOOL TO_BOOL_BOOL
#define _TO_BOOL_INT TO_BOOL_INT
#define _TO_BOOL_LIST 550
#define _TO_BOOL_NONE TO_BOOL_NONE
#define _TO_BOOL_STR 551
#define _UNARY_INVERT UNARY_INVERT
#define _UNARY_NEGATIVE UNARY_NEGATIVE
#define _UNARY_NOT UNARY_NOT
#define _UNPACK_EX UNPACK_EX
#define _UNPACK_SEQUENCE 552
#define _UNPACK_SEQUENCE_LIST 553
#define _UNPACK_SEQUENCE_TUPLE 554
#define _UNPACK_SEQUENCE_TWO_TUPLE 555
#define _WITH_EXCEPT_START WITH_EXCEPT_START
#define _YIELD_VALUE YIELD_VALUE
#define MAX_UOP_ID 555
#ifdef __cplusplus
}
#endif
#endif /* !Py_CORE_UOP_IDS_H */