digitalmars.D.learn - Inlined functions and their original bodies - bloat
- Cecil Ward (10/10) Jul 09 2023 I have a program where the various routines are all marked
- Cecil Ward (3/14) Jul 09 2023 This is with full -O3 optimisation and -release / -frelease for
- Adam D Ruppe (3/4) Jul 09 2023 try -fvisibility=hidden
- kinke (7/7) Jul 10 2023 The 'bloat' is usually gotten rid of by the linker if really
I have a program where the various routines are all marked pragma( inline, true ). The compiler obeys this but the LDC and GDC compilers still compile the function bodies even though the bodies are not needed as they are supposed to be ‘private’ to the module, explicitly marked as such, hoping that that is like static in C. There are no pointers to the routines, so no need for the bodies because of any indirect calls. Is there a way to control this code bloat in LDC / GDC ? Using the godbolt compiler explorer with LDC and GDC I can indeed see that the code is being inlined. Does this count as a compiler performance-type bug?
Jul 09 2023
On Sunday, 9 July 2023 at 18:04:13 UTC, Cecil Ward wrote:I have a program where the various routines are all marked pragma( inline, true ). The compiler obeys this but the LDC and GDC compilers still compile the function bodies even though the bodies are not needed as they are supposed to be ‘private’ to the module, explicitly marked as such, hoping that that is like static in C. There are no pointers to the routines, so no need for the bodies because of any indirect calls. Is there a way to control this code bloat in LDC / GDC ? Using the godbolt compiler explorer with LDC and GDC I can indeed see that the code is being inlined. Does this count as a compiler performance-type bug?This is with full -O3 optimisation and -release / -frelease for LDC and GDC respectively.
Jul 09 2023
On Sunday, 9 July 2023 at 18:05:48 UTC, Cecil Ward wrote:This is with full -O3 optimisationtry -fvisibility=hidden -release sux btw
Jul 09 2023
The 'bloat' is usually gotten rid of by the linker if really unreferenced in the binary being linked. There's a little trick to make sure the function is *always* inlined, across modules too, allowing to suppress the then guaranteed unused function symbol - converting it to a function literal. See https://github.com/ldc-developers/ldc/issues/2968#issuecomment-1628615699.
Jul 10 2023