DMD and GDC are unnecessarily using heap allocations for closures
deadalnix
deadalnix at gmail.com
Mon May 30 20:11:47 UTC 2022
On Monday, 30 May 2022 at 10:34:18 UTC, Iain Buclaw wrote:
> On Monday, 30 May 2022 at 10:24:12 UTC, Siarhei Siamashka wrote:
>> Not sure if anything can be done about GDC. Iain does not seem
>> to appreciate reports of this kind in GCC bugzilla and I don't
>> want to annoy him unnecessarily.
>
> Since when have I said that? Maybe I'm missing a context. :-)
>
> IMO the DMD front-end should be fixed to not tell GDC and LDC
> to allocate a closure in the first place, then LDC wouldn't
> have the need for a custom pass to revert the GC allocations.
It still would benefit from it. All the other transformation that
LLVM will apply to the code are likely to uncover opportunities
to revert GC allocations. For instance:
```d
auto foo() {
return new Object();
}
void bar() {
foo();
}
```
Nothing in the code "as this" allow you to remove the allocation,
but once foo is inlined in bar, then the object can be allocated
on stack (and then optimized away :P).
Maybe this is trivial enough so that it could realistically be
done in the front end, but I think this makes the point well
enough: optimizations often do uncover other optimization
opportunities.
More information about the Digitalmars-d
mailing list