[LLVMdev] misc questions on opt and bitcode

Eric Christopher echristo at apple.com
Mon Feb 6 13:21:18 PST 2012


Works for me:

[jhereg:~/tmp] echristo% /Volumes/Data/builds/build-llvm/Debug+Asserts/bin/clang -S -emit-llvm foo.cpp
[jhereg:~/tmp] echristo% lli foo.s
testing
[jhereg:~/tmp] echristo% llvm-gcc -S -emit-llvm foo.cpp
[jhereg:~/tmp] echristo% lli foo.s
testing

the first is using top of tree clang. The second is using an llvm-gcc on my OS. What versions are you using?

-eric

On Feb 6, 2012, at 9:10 AM, Arpan Sen <arpansen at gmail.com> wrote:

> Hi Eric, 
> 
> Here's the C code (example.c): 
> include <stdio.h>
> 
> int main()
> {
>   printf("testing\n");
> }
> 
> Here's the LLVM IR (from llvm-gcc): 
>  ModuleID = 'example.c'
> target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
> target triple = "x86_64-apple-darwin11.0"
> 
> @.str = private constant [8 x i8] c"testing\00", align 1 ; <[8 x i8]*> [#uses=1]
> 
> define i32 @main() nounwind ssp {
> entry:
>   %retval = alloca i32                            ; <i32*> [#uses=1]
>   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
>   %0 = call i32 @puts(i8* getelementptr inbounds ([8 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
>   br label %return
> 
> return:                                           ; preds = %entry
>   %retval1 = load i32* %retval                    ; <i32> [#uses=1]
>   ret i32 %retval1
> }
> 
> declare i32 @puts(i8*)
> 
> And when I run llc with this IR I get nothing printed on screen. Not sure if my LLVM revision is corrupted and needs a fresh install. When I ran with the bitcode and lli here's what I get: 
> 42-105-250-151:pastebin Babai$ llvm-gcc example.c -c -emit-llvm -o example.bc
> 42-105-250-151:pastebin Babai$ lli example.bc 
> lli: example.bc: Invalid ALLOCA record
> 
> Pretty confusing. 
> 
> Thanks,
>   Arpan
> 
> 
> On Mon, Feb 6, 2012 at 6:16 AM, Eric Christopher <echristo at apple.com> wrote:
> 
> On Feb 5, 2012, at 11:32 AM, Arpan Sen wrote:
> 
>> For the very simple example below, I get Unknown instruction error from lli and llvm-dis, while llc does not print anything. Not sure what is that I am missing here. My llvm-gcc version is i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
> 
>> 1-39-155-188:pastebin Babai$ llvm-gcc example.c -emit-llvm -c -o example.bc
>> 
>> Any ideas? 
> 
> On which instruction is illegal? Not offhand, but you can use llvm-gcc -S -emit-llvm example.c -o example.ll to get an llvm bitcode file as text and take a look.
> 
> -eric
> 
> 
> 
> 
> -- 
> Regards, 
>    Arpan
> -----------------------------------------------------------------------------------------------------------------
> Reality is merely an illusion, albeit a very persistent one.




More information about the llvm-dev mailing list