Stéphane Letz
2007-Jun-16 07:51 UTC
[LLVMdev] Strategy to compile for LLVM IR (Chris Lattner)
> > Message: 3 > Date: Fri, 15 Jun 2007 12:24:52 -0700 (PDT) > From: Chris Lattner <sabre at nondot.org> > Subject: Re: [LLVMdev] Strategy to compile for LLVM IR > To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu> > Message-ID: <Pine.LNX.4.62.0706151218030.7416 at nondot.org> > Content-Type: text/plain; charset="x-unknown" > > On Fri, 15 Jun 2007, [ISO-8859-1] St?phane Letz wrote: >> We have a compiler for the Faust language (faust.grame.fr) that >> currently compiles a C++ class which implements a DSP plug-in with >> several methods. > > ok > >> Our strategy to compile LLVM IR instead is the following: >> >> - use the current Faust ==> C++ compiler to compile a "empty" plug-in >> that we use as a template C++ class. >> >> - compile this template C++ class using "llvm-g++ -emit-llvm -c " >> to get a bytecode file template.bc > > Ok. > >> - use "llvm2cpp template.bc" to get a template.bc.cpp of C++ code >> the Faust ==> LLVM IR new backend will have to execute to produce >> the correct bytecode. >> >> - take this template.bc.cpp code as the "constant" part of the Faust >> ==> LLVM IR backend and add everything needed to produce the >> "variable" part (that one corresponding to what the real Faust plug- >> in will do) > >> Is there any more common and simple method to achieve the same >> result? or any other advice? > > Here's a better way. Consider a simple C template like this: > > void the_template(int X, int Y) { > if (X == 123) > hole1(Y, X*Y); > > int *Ptr; > for (...) > hole2(Ptr); > } > > The template can do whatever you want obviously. I assume that > there are > various pieces that need to be filled in, e.g. the body of a loop. > In you > C template code, just put simple function calls to external functions > (named hole1/hole2 in this example). > > At runtime, load the IR for the code above (either from the .bc > file, or > statically linked into your app with llvm2cpp). Then do the > following: > > 1. Create new internal LLVM functions that will be used to fill in the > holes in the template. > 2. Clone the template code, specializing it based on globals or > arguments, > or whatever else you want. > 3. Iterate through the cloned code looking for calls to hole*. > Change the > callinst to call into the new LLVM function you created with #1. > 4. After you iterate through and update the calls, use the > InlineFunction > routine in llvm/Transforms/Utils/Cloning.h to inline the calls > to the > static functions you built in #1. > > The end result is happy specialized code, but in a nice and > maintainable > form. > > -Chris > >Thanks, I will need also to compile new fields in the result C++ class, thus i need a way to get an access on the class struct field part. I see something like: std::vector<const Type*>StructTy_struct_mydsp_fields; StructTy_struct_mydsp_fields.push_back(StructTy_struct_dsp); StructType* StructTy_struct_mydsp = StructType::get (StructTy_struct_mydsp_fields, /*isPacked=*/false); mod->addTypeName("struct.mydsp", StructTy_struct_mydsp); in the generated llvm2cpp code, i guess it is possible then to iterate through the cloned code looking for the object with "struct.mydsp" name and get the associated field struct so that to later do something like : StructTy_struct_mydsp_fields.push_back (Type::FloatTy); to add new fields? Thanks Stephane Letz -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070616/b62ccc29/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Strategy to compile for LLVM IR
- [LLVMdev] Partial evaluation and LLVM (2) (Chris Lattner)
- [LLVMdev] jit DLLs (Chris Lattner)
- [LLVMdev] Congratulations: First-Time SIGPLAN Award to Apple's Chris Lattner for Developing Popular LLVM Infrastructure with Applications in Commercial, Research, Teaching, and Open Source Projects
- MCJIT with LLVM >= 5.0 on Windows 64