Commit 2ec47da
Very WIP: Refactor core inference loops to use less memory
Currently inference uses `O(<number of statements>*<number of slots>)` state
in the core inference loop. This is usually fine, because users don't tend
to write functions that are particularly long. However, MTK does generate
functions that are excessively long and we've observed MTK models that spend
99% of their inference time just allocating and copying this state.
It is possible to get away with significantly smaller state, and this PR is
a first step in that direction, reducing the state to `O(<number of basic blocks>*<number of slots>)`.
Further improvements are possible by making use of slot liveness information
and only storing those slots that are live across a particular basic block.
The core change here is to keep a full set of `slottypes` only at
basic block boundaries rather than at each statement. For statements
in between, the full variable state can be fully recovered by
linearly scanning throughout the basic block, taking note of
slot assignments (together with the SSA type) and NewVarNodes.
The current status of this branch is that the changes appear correct
(no known functional regressions) and significantly improve the MTK
test cases in question (no exact benchmarks here for now, since
the branch still needs a number of fixes before final numbers make
sense), but somewhat regress optimizer quality (which is expected
and just a missing TODO) and bootstrap time (which is not expected
and something I need to dig into).1 parent 65b9be4 commit 2ec47da
File tree
9 files changed
+472
-303
lines changed- base/compiler
- ssair
- test/compiler
9 files changed
+472
-303
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
98 | 103 | | |
99 | 104 | | |
100 | 105 | | |
101 | | - | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
128 | | - | |
129 | | - | |
| 133 | + | |
| 134 | + | |
130 | 135 | | |
131 | 136 | | |
132 | 137 | | |
133 | 138 | | |
134 | 139 | | |
135 | | - | |
136 | 140 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | | - | |
| 149 | + | |
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
148 | 153 | | |
149 | 154 | | |
| 155 | + | |
| 156 | + | |
150 | 157 | | |
151 | | - | |
152 | | - | |
| 158 | + | |
153 | 159 | | |
154 | | - | |
155 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
156 | 163 | | |
157 | 164 | | |
| 165 | + | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
| |||
183 | 192 | | |
184 | 193 | | |
185 | 194 | | |
186 | | - | |
187 | | - | |
| 195 | + | |
| 196 | + | |
188 | 197 | | |
189 | 198 | | |
190 | 199 | | |
| |||
226 | 235 | | |
227 | 236 | | |
228 | 237 | | |
| 238 | + | |
| 239 | + | |
229 | 240 | | |
230 | 241 | | |
231 | 242 | | |
| |||
422 | 433 | | |
423 | 434 | | |
424 | 435 | | |
425 | | - | |
| 436 | + | |
426 | 437 | | |
427 | 438 | | |
428 | 439 | | |
| |||
431 | 442 | | |
432 | 443 | | |
433 | 444 | | |
434 | | - | |
435 | 445 | | |
436 | | - | |
437 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
438 | 454 | | |
439 | 455 | | |
440 | 456 | | |
441 | | - | |
| 457 | + | |
442 | 458 | | |
443 | 459 | | |
444 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | | - | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | | - | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| 137 | + | |
| 138 | + | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
| |||
572 | 575 | | |
573 | 576 | | |
574 | 577 | | |
| 578 | + | |
575 | 579 | | |
576 | 580 | | |
577 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
578 | 601 | | |
579 | 602 | | |
580 | 603 | | |
| |||
589 | 612 | | |
590 | 613 | | |
591 | 614 | | |
592 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
593 | 622 | | |
594 | 623 | | |
595 | 624 | | |
| |||
607 | 636 | | |
608 | 637 | | |
609 | 638 | | |
| 639 | + | |
610 | 640 | | |
611 | 641 | | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | 642 | | |
617 | 643 | | |
618 | 644 | | |
| |||
623 | 649 | | |
624 | 650 | | |
625 | 651 | | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
636 | 657 | | |
637 | | - | |
| 658 | + | |
638 | 659 | | |
639 | 660 | | |
640 | 661 | | |
| |||
796 | 817 | | |
797 | 818 | | |
798 | 819 | | |
| 820 | + | |
799 | 821 | | |
| 822 | + | |
800 | 823 | | |
801 | 824 | | |
802 | 825 | | |
| |||
805 | 828 | | |
806 | 829 | | |
807 | 830 | | |
| 831 | + | |
808 | 832 | | |
809 | 833 | | |
810 | 834 | | |
811 | | - | |
| 835 | + | |
812 | 836 | | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
| 837 | + | |
817 | 838 | | |
| 839 | + | |
818 | 840 | | |
819 | 841 | | |
820 | 842 | | |
| |||
824 | 846 | | |
825 | 847 | | |
826 | 848 | | |
827 | | - | |
| 849 | + | |
| 850 | + | |
828 | 851 | | |
829 | 852 | | |
830 | 853 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 11 | | |
20 | 12 | | |
21 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
739 | | - | |
| 739 | + | |
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
| |||
0 commit comments