[LLVMdev] how to get the llvm IR from C source code?

Devang Patel dpatel at apple.com
Mon Jan 5 08:31:04 PST 2009


On Dec 24, 2008, at 8:53 PM, Nick Lewycky wrote:

> Keun Soo Yim wrote:
>>
>> Please run…
>>
>> $ llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc
>>
>> $ llvm-dis < hello.bc > hello.ll
>>
>> The first command is to generate a byte code
>>
>> and second is to translate the bytecode to a readable form.
>>
> llvm-gcc can emit the textual form directly too:
>
> llvm-gcc -O2 -emit-llvm hello.c -S -o hello.ll
> llvm-gcc -O2 -emit-llvm hello.c -S -o -
>
> the latter will print it to standard out.

BTW,  -O2 or any other optimization options can be omitted here if you  
intend to get raw (unoptimized) IR.
-
Devang







More information about the llvm-dev mailing list