user1479589
user1479589

Reputation: 315

LLVM IR limitations

I am looking to generate LLVM-IR code from C code and was wondering how well is the IR generation for functions in:

stdio.h, string.h, stdlib.h and generally the standard memory based functions such as malloc, calloc, since I have not been able to find most of the common functions in:

http://llvm.org/docs/LangRef.html and was wondering about the limitations of this representation and whether I might be required to add my own intrinsics just to deal with standard/most popular c functions.

I am looking to change the code at runtime, so was wondering which kind of approach will give me the most flexibility eg: Manipulate the code at AST level instead.

Thanks

Upvotes: 2

Views: 2008

Answers (1)

Eli Bendersky
Eli Bendersky

Reputation: 273456

Emitting LLVM IR from C is exactly what the industrial-strength compiler Clang does. I suggest running Clang on small snippets of C code with -emit-llvm (details in this document: http://clang.llvm.org/get_started.html) and observing the resulting IR.

You can even do this in your browser: http://ellcc.org/demo/index.cgi

That will allow you to see how builtins like memcpy are handled and any other similar doubts.

Note that neither LLVM nor Clang carry a full C library with them, but they can be used to compile an existing one. newlib is a popular portable C library designed specifically for being built on various new platforms. PNaCl, for example, uses it to build C/C++ code into portable executables - it compiles newlib with the user's code together into a single LLVM IR module.

Upvotes: 7

Related Questions