Inline optimization

Michelle Long HappyDance321 at gmail.com
Wed Feb 27 02:07:40 UTC 2019


On Tuesday, 26 February 2019 at 14:30:58 UTC, Dennis wrote:
> On Tuesday, 26 February 2019 at 02:43:36 UTC, Michelle Long 
> wrote:
>> Given a function such as a computation that would benefit from 
>> running at full speed, is it possible to optimize only that 
>> function rather than the full program?
>>
>> That is, compile with debug but optimize specific code:
>>
>> pragma(optimize, "O3")
>> auto fastAdd(A,B)
>
> GCC has such a pragma, but as far as I know D compilers don't. 
> The closest thing I found was the optimization strategy 
> attribute in LDC:
> https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.optStrategy.28.22strategy.22.29.29
>
> But it seems you can only disable, not enable optimizations 
> with that.
>
> What you can do in any case is put the performance critical 
> code in a separate compilation unit (i.e. its own file) and 
> compile that with optimizations and link it with the rest of 
> the program compiled without optimizations. With a makefile 
> that shouldn't be hard, though for expressing that in Dub I'm 
> afraid you have to put it in its own sub package with an 
> optimization flag in the 'dflags' attribute.

That's a lot of trouble...

Surely it would be very simple for the compiler to do this... it 
has the flag inside and so when it is parsing a function it 
either runs an optimizer on it or not... given the command line 
options. But it could make this dynamic and modify it based on 
pragma.... seems like it would be much simpler to modify the 
compiler to do this?


More information about the Digitalmars-d mailing list