Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.6k
Commit74334f1
committed
Very WIP: 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 parent94ddc17 commit74334f1
File tree
13 files changed
+267
-55
lines changed- base
- compiler
- ssair
- src
- test/compiler
13 files changed
+267
-55
lines changedLines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1590 | 1590 |
| |
1591 | 1591 |
| |
1592 | 1592 |
| |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1593 | 1603 |
| |
1594 | 1604 |
| |
1595 | 1605 |
| |
| |||
1607 | 1617 |
| |
1608 | 1618 |
| |
1609 | 1619 |
| |
| 1620 | + | |
| 1621 | + | |
1610 | 1622 |
| |
1611 | 1623 |
| |
1612 | 1624 |
| |
|
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 |
| |
| |||
543 | 546 |
| |
544 | 547 |
| |
545 | 548 |
| |
546 |
| - | |
| 549 | + | |
547 | 550 |
| |
548 | 551 |
| |
549 | 552 |
| |
|
Lines changed: 58 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
874 | 874 |
| |
875 | 875 |
| |
876 | 876 |
| |
877 |
| - | |
| 877 | + | |
| 878 | + | |
878 | 879 |
| |
879 | 880 |
| |
880 | 881 |
| |
| |||
908 | 909 |
| |
909 | 910 |
| |
910 | 911 |
| |
911 |
| - | |
| 912 | + | |
912 | 913 |
| |
913 | 914 |
| |
914 | 915 |
| |
| |||
1206 | 1207 |
| |
1207 | 1208 |
| |
1208 | 1209 |
| |
1209 |
| - | |
| 1210 | + | |
1210 | 1211 |
| |
1211 | 1212 |
| |
1212 | 1213 |
| |
| |||
1226 | 1227 |
| |
1227 | 1228 |
| |
1228 | 1229 |
| |
1229 |
| - | |
1230 |
| - | |
1231 |
| - | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
1232 | 1234 |
| |
1233 | 1235 |
| |
1234 | 1236 |
| |
| |||
1245 | 1247 |
| |
1246 | 1248 |
| |
1247 | 1249 |
| |
1248 |
| - | |
| 1250 | + | |
1249 | 1251 |
| |
1250 | 1252 |
| |
1251 | 1253 |
| |
| |||
1255 | 1257 |
| |
1256 | 1258 |
| |
1257 | 1259 |
| |
1258 |
| - | |
1259 |
| - | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
1260 | 1272 |
| |
1261 | 1273 |
| |
1262 | 1274 |
| |
| |||
1308 | 1320 |
| |
1309 | 1321 |
| |
1310 | 1322 |
| |
1311 |
| - | |
| 1323 | + | |
| 1324 | + | |
1312 | 1325 |
| |
1313 | 1326 |
| |
1314 | 1327 |
| |
1315 | 1328 |
| |
1316 | 1329 |
| |
1317 | 1330 |
| |
1318 |
| - | |
| 1331 | + | |
1319 | 1332 |
| |
1320 | 1333 |
| |
1321 | 1334 |
| |
| |||
1430 | 1443 |
| |
1431 | 1444 |
| |
1432 | 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 | + | |
1433 | 1480 |
| |
1434 | 1481 |
| |
1435 | 1482 |
| |
|
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)