www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Dlang dynamic compilation

reply Ivan Butygin <ivan.butygin gmail.com> writes:
Hi all
Here is my small project - ability to move some code optimization 
and generation to runtime.
Any function can be marked with special attribute and llvm 
bitcode for it will saved in binary.
Then during runtime it will be optimized and compiled (and it can 
use best available cpu instructions).

 runtimeCompile void bar()
{
     ...
}

...

// Somewhere in main
rtCompileProcess(settings); // Compile
bar();

Another feature - ability to create "runtime compiletime 
variables" - you can set them during runtime and then they will 
be treated as constants during optimization and codegeneration.

 runtimeCompile __gshared int var;
 runtimeCompile void bar()
{
     // var is treated as constant in generated code and subject 
to constant propagation, loop unrolling, etc
     foreach(int i; 0..var)
     {
     }

     if(var == 42) // This block will be removed comletely if var 
is not 42
     {
     }
}

// Somewhere in main
var = 42;
rtCompileProcess(settings); // Compile
bar();

var = 13; // To see changed value in runtime compiled code 
recompilation is required
rtCompileProcess(settings); // Compile
bar();

This is an early prototype and mostly untested but simple 
examples work.

Hacked ldc sources are here:
https://github.com/Hardcode84/ldc/tree/runtime_compile
Nov 21 2016
next sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 21 November 2016 at 18:59:17 UTC, Ivan Butygin wrote:
 Hacked ldc sources are here:
 https://github.com/Hardcode84/ldc/tree/runtime_compile
This could be used to accelerate genetic algorithms at run-time.
Nov 22 2016
parent Faux Amis <faux amis.com> writes:
On 2016-11-22 12:51, Nordlöw wrote:
 On Monday, 21 November 2016 at 18:59:17 UTC, Ivan Butygin wrote:
 Hacked ldc sources are here:
 https://github.com/Hardcode84/ldc/tree/runtime_compile
This could be used to accelerate genetic algorithms at run-time.
https://en.wikipedia.org/wiki/Genetic_algorithm ;)
Nov 22 2016
prev sibling parent Minty Fresh <mint fresh.com> writes:
On Monday, 21 November 2016 at 18:59:17 UTC, Ivan Butygin wrote:
 Hacked ldc sources are here:
 https://github.com/Hardcode84/ldc/tree/runtime_compile
Very cool. Although runtimeCompile does peeve me, as it seems unnecessarily verbose (being longer than any other attribute, I think). I'd have gone with rtc or similar so as not to clutter function and variable declarations, but those are just my thoughts on language readability.
Nov 22 2016