LDC 1.18.0-beta1

Ivan Butygin ivan.butygin at gmail.com
Mon Sep 23 19:40:13 UTC 2019


On Monday, 23 September 2019 at 12:22:47 UTC, Martin Tschierschke 
wrote:

> Can you please give (again?) a link or a more detailed 
> description of the JIT, explaining some use cases?

https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.dynamicCompile.29

@dynamicCompile attribute allow you to delay final function 
optimization to runtime. You mark any function (virtual functions 
and lambdas are also supported) with @dynamicCompile and then 
call compileDynamicCode during runtime to finally optimize and 
compile function to native code, using host processor instruction 
set.

There is also jit bind which works much like c++ bind but also 
non-placeholder params are treated and optimized as constants by 
optimizer.

@dynamicCompileEmit int foo(int a, int b, int c, bool flag)
{
   if (flag)
   {
     // this check and code will be removed by optimizer
     ...
   }
   return a + b + c; // this will be optimized to 40 + c
}

auto f = bind(&foo, 30, 10, placeholder, false);
int delegate(int) d = f.toDelegate();

compileDynamicCode(...);

assert(f(2) == 42);
assert(d(2) == 42);


https://github.com/ldc-developers/ldc/blob/v1.18.0-beta1/runtime/jit-rt/d/ldc/dynamic_compile.d


More information about the Digitalmars-d-announce mailing list