Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.6k
Commit67ec007
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 parent37dd084 commit67ec007
File tree
17 files changed
+447
-99
lines changed- base
- compiler
- ssair
- src
- test/compiler
17 files changed
+447
-99
lines changedLines changed: 28 additions & 4 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 | + | |
| 1601 | + | |
1592 | 1602 |
| |
1593 | 1603 |
| |
1594 | 1604 |
| |
| |||
1603 | 1613 |
| |
1604 | 1614 |
| |
1605 | 1615 |
| |
| 1616 | + | |
| 1617 | + | |
1606 | 1618 |
| |
1607 | 1619 |
| |
1608 | 1620 |
| |
| |||
1998 | 2010 |
| |
1999 | 2011 |
| |
2000 | 2012 |
| |
2001 |
| - | |
| 2013 | + | |
| 2014 | + | |
2002 | 2015 |
| |
2003 | 2016 |
| |
2004 | 2017 |
| |
| |||
2089 | 2102 |
| |
2090 | 2103 |
| |
2091 | 2104 |
| |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
2092 | 2118 |
| |
2093 | 2119 |
| |
2094 | 2120 |
| |
| |||
2321 | 2347 |
| |
2322 | 2348 |
| |
2323 | 2349 |
| |
2324 |
| - | |
2325 |
| - | |
2326 |
| - | |
| 2350 | + | |
2327 | 2351 |
| |
2328 | 2352 |
| |
2329 | 2353 |
| |
|
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 |
| |
| |||
542 | 545 |
| |
543 | 546 |
| |
544 | 547 |
| |
545 |
| - | |
| 548 | + | |
546 | 549 |
| |
547 | 550 |
| |
548 | 551 |
| |
|
Lines changed: 100 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
306 | 306 |
| |
307 | 307 |
| |
308 | 308 |
| |
309 |
| - | |
310 |
| - | |
311 |
| - | |
312 |
| - | |
313 |
| - | |
314 |
| - | |
315 |
| - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
316 | 313 |
| |
317 | 314 |
| |
318 |
| - | |
319 | 315 |
| |
320 |
| - | |
321 | 316 |
| |
322 |
| - | |
323 |
| - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
324 | 320 |
| |
325 | 321 |
| |
326 | 322 |
| |
| |||
339 | 335 |
| |
340 | 336 |
| |
341 | 337 |
| |
342 |
| - | |
343 |
| - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
344 | 357 |
| |
345 | 358 |
| |
346 | 359 |
| |
| |||
847 | 860 |
| |
848 | 861 |
| |
849 | 862 |
| |
850 |
| - | |
851 |
| - | |
852 |
| - | |
853 |
| - | |
854 | 863 |
| |
855 |
| - | |
| 864 | + | |
856 | 865 |
| |
857 | 866 |
| |
858 | 867 |
| |
| |||
874 | 883 |
| |
875 | 884 |
| |
876 | 885 |
| |
877 |
| - | |
| 886 | + | |
| 887 | + | |
878 | 888 |
| |
879 | 889 |
| |
880 | 890 |
| |
| |||
908 | 918 |
| |
909 | 919 |
| |
910 | 920 |
| |
911 |
| - | |
| 921 | + | |
912 | 922 |
| |
913 | 923 |
| |
914 | 924 |
| |
915 | 925 |
| |
916 | 926 |
| |
917 | 927 |
| |
918 | 928 |
| |
919 |
| - | |
920 |
| - | |
921 |
| - | |
922 |
| - | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
923 | 933 |
| |
924 |
| - | |
925 |
| - | |
926 |
| - | |
| 934 | + | |
| 935 | + | |
927 | 936 |
| |
| 937 | + | |
928 | 938 |
| |
929 | 939 |
| |
930 | 940 |
| |
| |||
1206 | 1216 |
| |
1207 | 1217 |
| |
1208 | 1218 |
| |
1209 |
| - | |
| 1219 | + | |
1210 | 1220 |
| |
1211 | 1221 |
| |
1212 | 1222 |
| |
| |||
1223 | 1233 |
| |
1224 | 1234 |
| |
1225 | 1235 |
| |
1226 |
| - | |
1227 |
| - | |
1228 |
| - | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1229 | 1240 |
| |
1230 | 1241 |
| |
1231 | 1242 |
| |
| |||
1242 | 1253 |
| |
1243 | 1254 |
| |
1244 | 1255 |
| |
1245 |
| - | |
| 1256 | + | |
1246 | 1257 |
| |
1247 | 1258 |
| |
1248 | 1259 |
| |
| |||
1252 | 1263 |
| |
1253 | 1264 |
| |
1254 | 1265 |
| |
1255 |
| - | |
1256 |
| - | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
1257 | 1278 |
| |
1258 | 1279 |
| |
1259 | 1280 |
| |
| |||
1305 | 1326 |
| |
1306 | 1327 |
| |
1307 | 1328 |
| |
1308 |
| - | |
| 1329 | + | |
| 1330 | + | |
1309 | 1331 |
| |
1310 | 1332 |
| |
1311 | 1333 |
| |
1312 | 1334 |
| |
1313 | 1335 |
| |
1314 | 1336 |
| |
1315 |
| - | |
| 1337 | + | |
1316 | 1338 |
| |
1317 | 1339 |
| |
1318 | 1340 |
| |
| |||
1427 | 1449 |
| |
1428 | 1450 |
| |
1429 | 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 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
1430 | 1494 |
| |
1431 | 1495 |
| |
1432 | 1496 |
| |
|
Lines changed: 30 additions & 30 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
166 | 166 |
| |
167 | 167 |
| |
168 | 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 |
| - | |
197 |
| - | |
198 |
| - | |
199 | 169 |
| |
200 | 170 |
| |
201 | 171 |
| |
| |||
295 | 265 |
| |
296 | 266 |
| |
297 | 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 | + | |
| 296 | + | |
| 297 | + | |
298 | 298 |
| |
299 | 299 |
| |
300 | 300 |
| |
|
0 commit comments
Comments
(0)