Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instruction expected to be numbered

Tags:

llvm

I have a problem with the following LLVM code:

    %0 = load i64* %u
    %1 = load i64* %l
    %2 = icmp sgt i64 %1, %1
    br i1 %2, label %L1, label %L2
L2:
    ret void
    br label %L1
L1:

    %3 = load i64* %l
    %4 = sub i64 %3, 1
    store i64 %4, i64* %i

When running llc, I get the following error:

error: instruction expected to be numbered '%4'
%3 = load i64* %l

But I don't understand why it should be %4 after %2. There are no instruction returning a result between the %2 and %4.

I need to understand this because I am writing an LLVM code generator.

So why is it an error to use %3 here?

like image 827
antoyo Avatar asked Mar 18 '16 21:03

antoyo


1 Answers

Basic blocks share the same numbering as instructions. Because ret is a terminator, you have an unnamed (and unreachable) basic block starting right after it, so your code is equivalent to:

...
L2:
  ret void
%3:
  br label %L1
L1:
...

And that's why it expects the next unnamed thing to be %4.

like image 126
Oak Avatar answered Nov 07 '22 04:11

Oak