ldc 0.9.1 released

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Wed May 27 13:47:19 PDT 2009


bearophile wrote:
> Christian Kamm:
>> The release 0.9.1 of LDC, the LLVM based compiler for the D programming 
>> language, contains the following major improvements:
> 
> Very good. I'll try this too.
> 
> 
>>    * turn GC allocations to allocas if possible
> 
> Phobos1 of DMD too has alloca, so can this optimization be folded in DMD too?

These optimizations are done on LLVM IR, so unless DMD switches to LLVM they'll 
need to be completely reimplemented for DMD.

This one is only done for certain GC allocations by the way, not all of them. 
The ones currently implemented are:
  * new Struct/int/float/etc.,
  * uninitialized arrays (used for arr1 ~ arr2, for instance),
  * zero-initialized arrays (e.g. new int[N])
  * new Class, unless
    a) it has a destructor,
    b) it has a custom allocator (overloads new), or
    c) it has a custom deallocator (overloads delete).

>>    * simplify or remove certain calls to D runtime functions
> 
> What calls?

Besides the GC calls turned into allocas, these are currently implemented:
  * For "arr.length = N", the runtime call is deleted if
    a) the resulting .ptr is unused,
    b) N == 0, or
    c) both arr.length and N are constant integers, and N <= arr.length.
       I'd like to extend this one to a more general N <= arr.length (i.e. not 
just constant integers), but I'm not quite sure what the best way to implement 
it is yet.

  * For "cast(T[]) some_array", the compiler generates a runtime call to compute 
the new array length. This call will be optimized out if
    a) the old length was 0,
    b) T.sizeof == U.sizeof, where U is the element type of some_array, or
    c) T.sizeof % U.sizeof == 0

  * arr1[] = arr2[] is turned into a memcpy() if alias analysis can prove they 
don't overlap. (Only relevant if assertions or array bounds checks are enabled, 
as they both are by default, otherwise they're turned into memcpy() in the first 
place)

  * Runtime calls that don't do anything but allocate GC memory (and optionally 
initialize it) are deleted if their return value is unused.


More information about the Digitalmars-d-announce mailing list