[LLVMdev] Runtime optimization of C++ code with virtual functions

Chris Lattner sabre at nondot.org
Mon Jun 18 22:43:39 PDT 2007


On Sat, 16 Jun 2007, [ISO-8859-1] Stéphane Letz wrote:
> At runtime after a graph is created, one could imagine optimizing by
> resolving call to "virtual  Compute" and possibly get a more
> efficient Compute method for the entire graph, so that we could write:
>
> DSP* graph = new PAR_DSP(new SEQ_DDSP(new CONCRETE_DSP(), new
> CONCRETE_DSP()), new CONCRETE_DSP());
>
> graph->Optimize();
>
> graph->Compute(512, in, out); possibly a lot of time.
>
> Is there any possible method using LLVM that would help in this case?

LLVM won't help in this case.  However, I'd strongly recommend dropping 
the virtual functions and using template instantiation to get this.  That 
way you'd do something like:

   PAR_DSP<SEQ_DDSP<CONCRETE_DSP, CONCRETE_DSP>, CONCRETE_DSP> X;
   X->Compute(512, in, out);

This will be efficient even when statically compiled.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/


More information about the llvm-dev mailing list