Commit c66be28
authored
[clang][bytecode] Allocate IntegralAP and Floating types using an allocator (#144246)
Both `APInt` and `APFloat` will heap-allocate memory themselves using
the system allocator when the size of their data exceeds 64 bits.
This is why clang has `APNumericStorage`, which allocates its memory
using an allocator (via `ASTContext`) instead. Calling `getValue()` on
an ast node like that will then create a new `APInt`/`APFloat` , which
will copy the data (in the `APFloat` case, we even copy it twice).
That's sad but whatever.
In the bytecode interpreter, we have a similar problem. Large integers
and floating-point values are placement-new allocated into the
`InterpStack` (or into the bytecode, which is a `vector<std::byte>`).
When we then later interrupt interpretation, we don't run the destructor
for all items on the stack, which means we leak the memory the
`APInt`/`APFloat` (which backs the `IntegralAP`/`Floating` the
interpreter uses).
Fix this by using an approach similar to the one used in the AST. Add an
allocator to `InterpState`, which is used for temporaries and local
values. Those values will be freed at the end of interpretation. For
global variables, we need to promote the values to global lifetime,
which we do via `InitGlobal` and `FinishInitGlobal` ops.
Interestingly, this results in a slight _improvement_ in compile times:
https://llvm-compile-time-tracker.com/compare.php?from=6bfcdda9b1ddf0900f82f7e30cb5e3253a791d50&to=88d1d899127b408f0fb0f385c2c58e6283195049&stat=instructions:u
(but don't ask me why).
Fixes #1390121 parent 65d590e commit c66be28
File tree
17 files changed
+929
-341
lines changed- clang
- lib/AST/ByteCode
- test/AST/ByteCode
17 files changed
+929
-341
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
751 | | - | |
| 751 | + | |
| 752 | + | |
752 | 753 | | |
753 | 754 | | |
754 | 755 | | |
| |||
4185 | 4186 | | |
4186 | 4187 | | |
4187 | 4188 | | |
4188 | | - | |
4189 | | - | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
4190 | 4193 | | |
4191 | 4194 | | |
4192 | 4195 | | |
| |||
4674 | 4677 | | |
4675 | 4678 | | |
4676 | 4679 | | |
4677 | | - | |
4678 | | - | |
4679 | | - | |
4680 | | - | |
| 4680 | + | |
4681 | 4681 | | |
4682 | 4682 | | |
4683 | 4683 | | |
| |||
4698 | 4698 | | |
4699 | 4699 | | |
4700 | 4700 | | |
4701 | | - | |
4702 | | - | |
4703 | | - | |
4704 | | - | |
4705 | | - | |
4706 | | - | |
4707 | | - | |
4708 | | - | |
4709 | | - | |
4710 | | - | |
4711 | | - | |
4712 | | - | |
4713 | | - | |
4714 | | - | |
4715 | | - | |
4716 | | - | |
4717 | | - | |
4718 | | - | |
4719 | | - | |
4720 | | - | |
4721 | | - | |
4722 | | - | |
4723 | | - | |
4724 | | - | |
4725 | | - | |
4726 | | - | |
4727 | | - | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
4728 | 4704 | | |
4729 | | - | |
| 4705 | + | |
| 4706 | + | |
| 4707 | + | |
| 4708 | + | |
| 4709 | + | |
| 4710 | + | |
| 4711 | + | |
| 4712 | + | |
| 4713 | + | |
| 4714 | + | |
4730 | 4715 | | |
4731 | | - | |
4732 | | - | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
4733 | 4719 | | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
4734 | 4728 | | |
4735 | | - | |
4736 | | - | |
| 4729 | + | |
| 4730 | + | |
4737 | 4731 | | |
4738 | | - | |
4739 | | - | |
4740 | | - | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
4741 | 4736 | | |
4742 | | - | |
| 4737 | + | |
4743 | 4738 | | |
4744 | | - | |
4745 | | - | |
| 4739 | + | |
4746 | 4740 | | |
4747 | 4741 | | |
4748 | 4742 | | |
| |||
4751 | 4745 | | |
4752 | 4746 | | |
4753 | 4747 | | |
4754 | | - | |
4755 | | - | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
4756 | 4752 | | |
4757 | 4753 | | |
4758 | 4754 | | |
| |||
6133 | 6129 | | |
6134 | 6130 | | |
6135 | 6131 | | |
6136 | | - | |
| 6132 | + | |
| 6133 | + | |
6137 | 6134 | | |
| 6135 | + | |
6138 | 6136 | | |
6139 | 6137 | | |
6140 | 6138 | | |
| |||
6176 | 6174 | | |
6177 | 6175 | | |
6178 | 6176 | | |
6179 | | - | |
| 6177 | + | |
| 6178 | + | |
6180 | 6179 | | |
| 6180 | + | |
6181 | 6181 | | |
6182 | 6182 | | |
6183 | 6183 | | |
| |||
6953 | 6953 | | |
6954 | 6954 | | |
6955 | 6955 | | |
| 6956 | + | |
| 6957 | + | |
| 6958 | + | |
| 6959 | + | |
| 6960 | + | |
| 6961 | + | |
| 6962 | + | |
| 6963 | + | |
| 6964 | + | |
| 6965 | + | |
| 6966 | + | |
| 6967 | + | |
| 6968 | + | |
| 6969 | + | |
6956 | 6970 | | |
6957 | 6971 | | |
6958 | 6972 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
394 | 395 | | |
395 | 396 | | |
396 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
71 | 85 | | |
| 86 | + | |
72 | 87 | | |
73 | 88 | | |
74 | | - | |
75 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
76 | 93 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
81 | 103 | | |
82 | 104 | | |
83 | 105 | | |
| |||
0 commit comments