Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.6k
Commitda04e84
committed
Eager finalizer insertion
This is a variant of the eager-finalization idea(e.g. as seen in#44056), but with a focus on the mechanismof finalizer insertion, since I need a similar pass downstream.Integration of EscapeAnalysis is left to#44056.My motivation for this change is somewhat different. In particular,I want to be able to insert finalize call such that I cansubsequently SROA the mutable object. This requires a coupledesign points that are more stringent than the pass from#44056,so I decided to prototype them as an independent PR. The primarythings I need here that are not seen in#44056 are:- The ability to forgo finalizer registration with the runtime entirely (requires additional legality analyis)- The ability to inline the registered finalizer at the deallocation point (to enable subsequent SROA)To this end, adding a finalizer is promoted to a builtinthat is recognized by inference and inlining (such that inferencecan produce an inferred version of the finalizer for inlining).The current status is that this fixes the minimal example I wantedto have work, but does not yet extend to the motivating case I had.Nevertheless, I felt that this was a good checkpoint to synchronizewith other efforts along these lines.Currently working demo:```julia> const total_deallocations = Ref{Int}(0)Base.RefValue{Int64}(0)julia> mutable struct DoAlloc function DoAlloc() this = new() Core._add_finalizer(this, function(this) global total_deallocations[] += 1 end) return this end endjulia> function foo() for i = 1:1000 DoAlloc() end endfoo (generic function with 1 method)julia> @code_llvm foo(); @ REPL[3]:1 within `foo`define void @julia_foo_111() #0 {top: %.promoted = load i64, i64* inttoptr (i64 140370001753968 to i64*), align 16; @ REPL[3]:2 within `foo` %0 = add i64 %.promoted, 1000; @ REPL[3] within `foo` store i64 %0, i64* inttoptr (i64 140370001753968 to i64*), align 16; @ REPL[3]:4 within `foo` ret void}```1 parent6f8860c commitda04e84
File tree
9 files changed
+382
-78
lines changed- base/compiler
- ssair
- src
- test/compiler
9 files changed
+382
-78
lines changedLines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1589 | 1589 |
| |
1590 | 1590 |
| |
1591 | 1591 |
| |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
1592 | 1601 |
| |
1593 | 1602 |
| |
1594 | 1603 |
| |
| |||
1603 | 1612 |
| |
1604 | 1613 |
| |
1605 | 1614 |
| |
| 1615 | + | |
| 1616 | + | |
1606 | 1617 |
| |
1607 | 1618 |
| |
1608 | 1619 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 |
| |
31 | 34 |
| |
32 | 35 |
| |
| |||
564 | 567 |
| |
565 | 568 |
| |
566 | 569 |
| |
567 |
| - | |
| 570 | + | |
568 | 571 |
| |
569 | 572 |
| |
570 | 573 |
| |
|
Lines changed: 98 additions & 35 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
308 | 308 |
| |
309 | 309 |
| |
310 | 310 |
| |
311 |
| - | |
312 |
| - | |
313 |
| - | |
314 |
| - | |
315 |
| - | |
316 |
| - | |
317 |
| - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
318 | 315 |
| |
319 | 316 |
| |
320 |
| - | |
321 | 317 |
| |
322 |
| - | |
323 | 318 |
| |
324 |
| - | |
325 |
| - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
326 | 322 |
| |
327 | 323 |
| |
328 | 324 |
| |
| |||
341 | 337 |
| |
342 | 338 |
| |
343 | 339 |
| |
344 |
| - | |
345 |
| - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
346 | 359 |
| |
347 | 360 |
| |
348 | 361 |
| |
| |||
839 | 852 |
| |
840 | 853 |
| |
841 | 854 |
| |
842 |
| - | |
| 855 | + | |
843 | 856 |
| |
844 | 857 |
| |
845 | 858 |
| |
| |||
861 | 874 |
| |
862 | 875 |
| |
863 | 876 |
| |
864 |
| - | |
| 877 | + | |
| 878 | + | |
865 | 879 |
| |
866 | 880 |
| |
867 | 881 |
| |
| |||
895 | 909 |
| |
896 | 910 |
| |
897 | 911 |
| |
898 |
| - | |
| 912 | + | |
899 | 913 |
| |
900 | 914 |
| |
901 | 915 |
| |
| |||
904 | 918 |
| |
905 | 919 |
| |
906 | 920 |
| |
907 |
| - | |
908 |
| - | |
909 |
| - | |
910 |
| - | |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
915 |
| - | |
916 |
| - | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
917 | 924 |
| |
| 925 | + | |
| 926 | + | |
918 | 927 |
| |
919 | 928 |
| |
920 | 929 |
| |
| |||
1196 | 1205 |
| |
1197 | 1206 |
| |
1198 | 1207 |
| |
1199 |
| - | |
| 1208 | + | |
1200 | 1209 |
| |
1201 | 1210 |
| |
1202 | 1211 |
| |
| |||
1213 | 1222 |
| |
1214 | 1223 |
| |
1215 | 1224 |
| |
1216 |
| - | |
1217 |
| - | |
1218 |
| - | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
1219 | 1229 |
| |
1220 | 1230 |
| |
1221 | 1231 |
| |
| |||
1232 | 1242 |
| |
1233 | 1243 |
| |
1234 | 1244 |
| |
1235 |
| - | |
| 1245 | + | |
1236 | 1246 |
| |
1237 | 1247 |
| |
1238 | 1248 |
| |
| |||
1242 | 1252 |
| |
1243 | 1253 |
| |
1244 | 1254 |
| |
1245 |
| - | |
1246 |
| - | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1247 | 1267 |
| |
1248 | 1268 |
| |
1249 | 1269 |
| |
| |||
1299 | 1319 |
| |
1300 | 1320 |
| |
1301 | 1321 |
| |
1302 |
| - | |
| 1322 | + | |
| 1323 | + | |
1303 | 1324 |
| |
1304 | 1325 |
| |
1305 | 1326 |
| |
1306 | 1327 |
| |
1307 | 1328 |
| |
1308 | 1329 |
| |
1309 |
| - | |
| 1330 | + | |
1310 | 1331 |
| |
1311 | 1332 |
| |
1312 | 1333 |
| |
| |||
1419 | 1440 |
| |
1420 | 1441 |
| |
1421 | 1442 |
| |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
1422 | 1485 |
| |
1423 | 1486 |
| |
1424 | 1487 |
| |
|
Lines changed: 30 additions & 30 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
163 | 163 |
| |
164 | 164 |
| |
165 | 165 |
| |
166 |
| - | |
167 |
| - | |
168 |
| - | |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 |
| - | |
186 |
| - | |
187 |
| - | |
188 |
| - | |
189 |
| - | |
190 |
| - | |
191 |
| - | |
192 |
| - | |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 | 166 |
| |
197 | 167 |
| |
198 | 168 |
| |
| |||
292 | 262 |
| |
293 | 263 |
| |
294 | 264 |
| |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
295 | 295 |
| |
296 | 296 |
| |
297 | 297 |
| |
|
0 commit comments
Comments
(0)