c++ - Partial evaluation/specialization with LLVM-gcc or gcc -


i interestent in (partial) compile-time evaluation c/c++ (not template parameters in c++). lets consider following case (taken [1]):

double mypower(double x, int n) {   int i;   double ret = x;   (i = 1; < n; i++) {     ret *= x;   }   return ret; } 

then call function somewhere in code with:

mypower(x,3); // y varies time,  

then compiler optimize (e.g. loop unrolling). used function use benefit optimization (tested creating specialized function manually). presentation [1] descibes process function searched , replaced specialised version of function. seems work. not seem universal, code needs written functions should replaced.

the presentation seems 2008, not find substantial more information in source. has improved since then? prefer kind of automatism, same function possibly controlled attribute syntax (e.g. __attribute__(peval)...). further same work object-oriented code, creating specialized classes different objects ([2] seems suggest not possible).

additionally, specialization not work constants found in code. thinking program compiled llvm ir (bytecode) following:

  1. running programm during initialization phase in interpreter, during initialization phase program read configuration file. after initialization interpreter stopped.

  2. some variables (including member variables) fixed point on. extract these variables (e.g. marked attribute during compilation).

  3. create specialized functions , classes. clone these bytecode.

  4. run jit create native machine code.

this lot ask , few computation intensive programs benifit such optimization. people must working on that. don't know right search terms feed google.

note: please don't suggest template classes non-type parameters or manual specialization, that. prefer compiler doing work me.

links:

[1] presentation how partial evaluate in llvm

[2] forum message partial evaluation

this largely in arena of interprocedural optimizations. llvm has few of them, in particular ip constant propagation if used mypower(x, 3) @ of call sites in translation unit. describe possible, hasn't been done yet. improving ipcp pass you'd want doing - having clone , specialize function @ particular call site. could, if have enough translation units, cause pretty large code bloat though why people haven't looked doing it.

this have more use @ lto level when can @ of calls in program.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -