www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Inlined functions and their original bodies - bloat

reply Cecil Ward <cecil cecilward.com> writes:
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
next sibling parent reply Cecil Ward <cecil cecilward.com> writes:
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
parent Adam D Ruppe <destructionator gmail.com> writes:
On Sunday, 9 July 2023 at 18:05:48 UTC, Cecil Ward wrote:
 This is with full -O3 optimisation
try -fvisibility=hidden -release sux btw
Jul 09 2023
prev sibling parent kinke <noone nowhere.com> writes:
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