[LLVMdev] Code template for creating an llvm module from scratch

62 views
Skip to first unread message

Zhoulai

unread,
Apr 18, 2015, 11:48:06 PM4/18/15
to llv...@cs.uiuc.edu
Hi, 

I have been looking for code examples to create an LLVM module from scratch.

The LLVM API is certainly well-documented but may still looks daunting for some. I have googled, and the only found document on this subject (of creating an llvm module from scratch): 


should be outdated, given that llvm API evolves at each release.  Are you aware of   a similar, more recent version of the linked ressource? For information, what I need to do is roughly something like this:

1. create a new module m
2. create a new function f 
3. clone the body of an existing function g from a file
4. put some special instructions into f, and call g at the end of f
5. put both f and g into m
6. return an llvm IR code derived from m.

I learned how to handle #4 by writing an LLVM pass (thanks to the ‘hello world’ example at http://llvm.org/docs/WritingAnLLVMPass.html), but have always had difficulties in finding template code for doing  #1~#3 and #5.  Any resource? Thanks for your help.

Zhoulai

David Blaikie

unread,
Apr 19, 2015, 12:21:18 AM4/19/15
to Zhoulai, LLVM Developers Mailing List
On Sat, Apr 18, 2015 at 8:45 PM, Zhoulai <zel...@gmail.com> wrote:
> Hi,
>
> I have been looking for code examples to create an LLVM module from scratch.
>
> The LLVM API is certainly well-documented but may still looks daunting for
> some. I have googled, and the only found document on this subject (of
> creating an llvm module from scratch):
>
> http://llvm.org/releases/2.6/docs/tutorial/JITTutorial1.html

I guess this may've been the precursor to the Kaleidoscope tutorial
series that's generally kept up-to-date these days:
http://llvm.org/docs/tutorial/

>
> should be outdated, given that llvm API evolves at each release. Are you
> aware of a similar, more recent version of the linked ressource? For
> information, what I need to do is roughly something like this:
>
> 1. create a new module m
> 2. create a new function f
> 3. clone the body of an existing function g from a file
> 4. put some special instructions into f, and call g at the end of f
> 5. put both f and g into m
> 6. return an llvm IR code derived from m.
>
> I learned how to handle #4 by writing an LLVM pass (thanks to the ‘hello
> world’ example at http://llvm.org/docs/WritingAnLLVMPass.html), but have
> always had difficulties in finding template code for doing #1~#3 and #5.
> Any resource? Thanks for your help.
>
> Zhoulai
>

> _______________________________________________
> LLVM Developers mailing list
> LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Reply all
Reply to author
Forward
0 new messages