Commit 722ab96
committed
JIT: Implement hot-cold code splitting for improved icache locality
Split JIT stencil code into hot and cold sections to improve instruction
cache performance. Hot code (common execution paths) is laid out
contiguously across all uops in a trace, while cold code (error handling,
rare branches) is placed after all hot code.
Changes:
- _optimizers.py: Physically reorder basic blocks so hot blocks come
first, cold blocks last. Insert _JIT_COLD_START symbol at boundary.
Add _make_jump() to each arch-specific optimizer for inserting
explicit jumps when hot->cold fallthrough edges are broken.
- _stencils.py: Track cold_offset in StencilGroup. Add hot_code_size()
and cold_code_size() methods. Extract cold offset from _JIT_COLD_START
symbol in object files.
- _writer.py: Split emit functions to handle hot and cold code bodies
separately, with adjusted hole patching for cold code offsets. Update
StencilGroup C struct to include hot_code_size and cold_code_size.
- _targets.py: Call extract_cold_offset() during stencil build.
- jit.c: New memory layout [hot code|cold code|trampolines|data].
Update _PyJIT_Compile and compile_shim to use split layout.
https://claude.ai/code/session_01QteUqrt8X8Ssxhei1kX2TH1 parent 300de1e commit 722ab96
File tree
5 files changed
+213
-43
lines changed- Python
- Tools/jit
5 files changed
+213
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
645 | | - | |
| 645 | + | |
| 646 | + | |
646 | 647 | | |
647 | 648 | | |
648 | 649 | | |
649 | 650 | | |
650 | 651 | | |
651 | | - | |
652 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
653 | 655 | | |
654 | 656 | | |
655 | 657 | | |
656 | 658 | | |
657 | 659 | | |
658 | | - | |
| 660 | + | |
| 661 | + | |
659 | 662 | | |
660 | 663 | | |
661 | 664 | | |
| 665 | + | |
662 | 666 | | |
663 | 667 | | |
664 | 668 | | |
| |||
684 | 688 | | |
685 | 689 | | |
686 | 690 | | |
687 | | - | |
| 691 | + | |
688 | 692 | | |
689 | 693 | | |
690 | 694 | | |
691 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
692 | 699 | | |
| 700 | + | |
693 | 701 | | |
694 | 702 | | |
695 | 703 | | |
696 | 704 | | |
697 | 705 | | |
698 | 706 | | |
699 | 707 | | |
700 | | - | |
701 | | - | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
702 | 711 | | |
703 | 712 | | |
704 | 713 | | |
705 | 714 | | |
706 | | - | |
707 | | - | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
708 | 718 | | |
709 | | - | |
| 719 | + | |
| 720 | + | |
710 | 721 | | |
711 | 722 | | |
712 | 723 | | |
| |||
728 | 739 | | |
729 | 740 | | |
730 | 741 | | |
731 | | - | |
| 742 | + | |
| 743 | + | |
732 | 744 | | |
733 | 745 | | |
734 | 746 | | |
735 | | - | |
| 747 | + | |
| 748 | + | |
736 | 749 | | |
737 | 750 | | |
738 | 751 | | |
| 752 | + | |
739 | 753 | | |
740 | 754 | | |
741 | 755 | | |
| |||
747 | 761 | | |
748 | 762 | | |
749 | 763 | | |
| 764 | + | |
750 | 765 | | |
751 | 766 | | |
752 | 767 | | |
753 | 768 | | |
754 | 769 | | |
755 | 770 | | |
756 | 771 | | |
757 | | - | |
758 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
759 | 775 | | |
760 | | - | |
| 776 | + | |
| 777 | + | |
761 | 778 | | |
762 | 779 | | |
763 | 780 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
313 | 379 | | |
314 | 380 | | |
315 | 381 | | |
| |||
563 | 629 | | |
564 | 630 | | |
565 | 631 | | |
| 632 | + | |
566 | 633 | | |
567 | 634 | | |
568 | 635 | | |
| |||
580 | 647 | | |
581 | 648 | | |
582 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
583 | 653 | | |
584 | 654 | | |
585 | 655 | | |
| |||
644 | 714 | | |
645 | 715 | | |
646 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
647 | 720 | | |
648 | 721 | | |
649 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| |||
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
268 | 279 | | |
269 | 280 | | |
270 | 281 | | |
| |||
420 | 431 | | |
421 | 432 | | |
422 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
423 | 446 | | |
424 | 447 | | |
425 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
426 | 454 | | |
427 | 455 | | |
428 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| |||
0 commit comments