[LLVMdev] Partial evaluation and LLVM (2) (Chris Lattner)

Stéphane Letz letz at grame.fr
Sun Jun 17 01:20:17 PDT 2007


>
> Message: 2
> Date: Fri, 15 Jun 2007 12:16:32 -0700 (PDT)
> From: Chris Lattner <sabre at nondot.org>
> Subject: Re: [LLVMdev] Partial evaluation and LLVM (2)
> To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu>
> Message-ID: <Pine.LNX.4.62.0706151213090.7416 at nondot.org>
> Content-Type: text/plain; charset="x-unknown"
>
> On Fri, 15 Jun 2007, [ISO-8859-1] St?phane Letz wrote:
>> Thanks, this works.
>
> Great.
>
>> Would it be possible to specialize a function that has some "free"
>> variables, more precisely a method in a class that use the value of
>> some of the object instance fields? Or does the function to
>> specialize has to be closed in some way?
>
> Yes.
>
> The solution I've found is to use llvm global variables.  Consider:
>
>
> extern int specializevar;
>
> void genericfunc() {
>    if (specializevar == 42)
>      blah();
> }
>
> The steps become:
>
> 1. Clone genericfunc (specializing based on arguments if you like).
> 2. Give specializevar an initializer for the value you want to  
> specialize
> on.  Mark it constant.
> 3. Run instcombine and other xforms on genericfunc.  Instcombine will
> forward substitute loads from the global into the constant values.
> 4. JIT the result etc.
> 5. Mark specializevar non-constant, remove the initializer.
>
> -Chris
>
>
>

Thanks, it works with the example you gave, but how is this method  
supposed to work with a C++ method considering the object fields it  
uses as "free" variables?
These object fields are not global variables of the module?

Thanks

Stephane Letz






More information about the llvm-dev mailing list