2

I'm trying to run a program from the LLVM bitcode generated by my compiler, but when I run the lli command it returns an error

lli-3.6: test2.ll:9:1: error: expected instruction opcode

When I use the lli with the .ll generated by clang -S -emit-llvm it works. There are many optimizations in this code, though. I tried to insert some of them manually, but it didn't work.

My problem is that I don't know if the structure of my code is correct, or if it is just missing something particular for the interpreter to work properly. Originally, I tried to use the JIT in the code, but it was giving me more errors with the libraries and the documention was not helpful.

My llvm bitcode is the following:

%struct.test = type { i32, i32 }

define internal void @test_program() {
entry:
  %a = alloca i32
  store i32 5, i32* %a
  call void @printf(i32 3)
  %bar = alloca %struct.test
}

define internal void @f(i32 %x) {
entry:
  %b = alloca i32
  %mul = mul i32 6, 2
  %add = add i32 %mul, 3
  %add1 = add i32 10, %add
  store i32 %add1, i32* %b
  %tmp_eq = icmp eq i32* %b, i32 25
  br i1 %tmp_eq, label %cond_true, label %cond_false

cond_true:                                        ; preds = %entry
  store i32 40, i32* %b

cond_false:                                       ; preds = %entry
  store i32 50, i32* %b
}

declare void @printf() 

1 Answer 1

3

The LLVM IR file you provided is malformed - it's missing terminator instructions on its basic blocks (except on %entry in @f). It looks like you have a bug in your custom optimizations.

Sign up to request clarification or add additional context in comments.

2 Comments

First, thanks! I know it is another error what I am asking here in the comments, but it's throwing an error now about expected value token. I already changed to both of values be i32 with the following lines: %0 = load i32* %b and %tmp_eq = icmp eq i32 %2, i32 25 but it still not working. Do you know what I could do?
@rennomarcus if it's a separate question, please ask it separately :-) (and include the entire snippet which is giving you trouble)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.