dmd codegen improvements

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 19 12:00:38 PDT 2015


On Wednesday, 19 August 2015 at 18:47:21 UTC, Paulo Pinto wrote:
> On Wednesday, 19 August 2015 at 18:41:07 UTC, Walter Bright 
> wrote:
>> On 8/19/2015 11:03 AM, Jacob Carlborg wrote:
>>> Not sure how the compilers behave in this case but what about 
>>> devirtualization?
>>> Since I think most developers compile their D programs with 
>>> all files at once
>>> there should be pretty good opportunities to do 
>>> devirtualization.
>>
>> It's true that if generating an exe, the compiler can mark 
>> leaf classes as final and get devirtualization. (Of course, 
>> you can manually add 'final' to classes.)
>>
>> It's one way D can generate faster code than C++.
>
> C++ also has final and if I am not mistaken both LLVM and 
> Visual C++ do devirtualization, not sure about other compilers.

GCC is much better than LLVM at this. This is an active area of 
work in both compiler right now.

Note that combined with PGO, you can do some very nice 
speculative devirtualization.

D has a problem here: template are duck typed. That means the 
compiler can't know what possible instantiations may be done, 
especially when shared object are in the party. This is one area 
where stronger typing for metaprogramming is a win.


More information about the Digitalmars-d mailing list