www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Switch to list all druntime calls?

reply "bearophile" <bearophileHUGS lycos.com> writes:
Instead (or in addition) of this dmd compiler switch:

-vgc           list all hidden gc allocations

Isn't it more useful a compiler switch like "-noruntime" (similar 
to the switch of the ldc2 compiler) meant to list the lines of 
code where are implicit calls to runtime funcitions?

Bye,
bearophile
May 20 2014
next sibling parent reply "Meta" <jared771 gmail.com> writes:
On Tuesday, 20 May 2014 at 10:39:32 UTC, bearophile wrote:
 Instead (or in addition) of this dmd compiler switch:

 -vgc           list all hidden gc allocations

 Isn't it more useful a compiler switch like "-noruntime" 
 (similar to the switch of the ldc2 compiler) meant to list the 
 lines of code where are implicit calls to runtime funcitions?

 Bye,
 bearophile
I think I remember Adam Ruppe mentioning somewhere that you can use a custom object.d and omit the Druntime functions, and the linker will complain about them at link-time where they're used. That more or less does the trick, doesn't it?
May 20 2014
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Meta:

 I think I remember Adam Ruppe mentioning somewhere that you can 
 use a custom object.d and omit the Druntime functions, and the 
 linker will complain about them at link-time where they're 
 used. That more or less does the trick, doesn't it?
Then why is -vgc includes among the dmd switches? Bye, bearophile
May 20 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 20 May 2014 at 15:53:51 UTC, Meta wrote:
 That more or less does the trick, doesn't it?
Yeah, it will work, but it isn't as convenient as a compiler helper thingy because pulling a function out of object.d can be a pain and the linker error isn't as easy to read as a compiler error (no code line number for example).
May 20 2014
prev sibling parent reply "David Nadlinger" <code klickverbot.at> writes:
On Tuesday, 20 May 2014 at 10:39:32 UTC, bearophile wrote:
 Instead (or in addition) of this dmd compiler switch:

 -vgc           list all hidden gc allocations

 Isn't it more useful a compiler switch like "-noruntime" 
 (similar to the switch of the ldc2 compiler) meant to list the 
 lines of code where are implicit calls to runtime funcitions?
No. There are quite a few runtime functions which don't in fact allocate. -vgc is a tool to help in avoiding GC allocations, not all druntime dependencies. I'd suspect that the answer to the question about the "more useful" behavior depends entirely on your use case. David
May 20 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
David Nadlinger:

 There are quite a few runtime functions which don't in fact 
 allocate.
Finding them is the point of a "-noruntime" switch. Now for just the ones that allocate we have nogc. Bye, bearophile
May 20 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
This shows one purpose of the ldc2 -noruntime switch. A simple 
test program:


void foo(ref int[10] data) {
     data[0 .. 3] = 5;
     data[7 .. 9] = 10;
}
void main() {}


dmd compiles it to:

_D5test53fooFKG10iZv:
L0:     push    EAX
         push    3
         push    5
         push    EAX
         call    near ptr __memset32
         push    2
         push    0Ah
         mov EAX,014h[ESP]
         lea ECX,01Ch[EAX]
         push    ECX
         call    near ptr __memset32
         add ESP,018h
         pop EAX
         ret


ldc2 is smarter and removes the calls to memset, generating kind 
of optimal 32 bit code:

__D5test53fooFKG10iZv:
     movl    $5, (%eax)
     movl    $5, 4(%eax)
     movl    $5, 8(%eax)
     movl    $10, 28(%eax)
     movl    $10, 32(%eax)
     ret

If you call such function many times you see a significant run 
time difference between the two compilations.

A switch like -noruntime helps find the unwanted cases where the 
compiler you are using doesn't remove some run time call.

Bye,
bearophile
May 21 2014