1
votes

I've seen one post on here about the "use of instruction is not an instruction" error, and I'm running into a similar issue, but without a good reason.

I'm using moe (https://llvm.moe/ocaml/Llvm.html) to write LLVM to build a compiler and my issue basically comes down to 3 lines:

let pointer = L.build_alloca float_t ("reg") builder in      L.dump_value(pointer);
  let test = L.build_store (L.const_float float_t 32.3) pointer builder      in L.dump_value(test);
   let loaded = L.build_load pointer ("reg") builder  in L.     dump_value(loaded);

what I'm doing here is basically using alloc to get some space in memory, then storing the value of 32.3 to that space, and trying to load it back into the place I allocated in memory.

LLVM wise, it looks pretty good, as, after the dump_module, output, I get something like this:

align 8  %reg = alloca double, align 8 
store double 3.230000e+01, double* %reg, align 8
%x13 = load double, double* %reg, align 8

which should be exactly what I want -- I even tested this out by writing up a similar C program and it does something very similar to this in LLVM.

However, when I run my program I get the following error:

Use of instruction is not an instruction!
 %x13 = load double, double* %reg, align 8

which really doesn't seem to make sense. I check out the error a bit more, and it seems like it's caused by a few lines in the LLVM source code:

     if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
       Assert(Used->getParent() != nullptr,
              "Instruction referencing"
              " instruction not embedded in a basic block!",
              &I, Used);
     else {
       CheckFailed("Use of instruction is not an instruction!", U);
       return;
     }
   }

which seem to imply it happens if the instructions don't have a parent, but I'm not sure why that would be the case.

Any help here would be very much appreciated!

1
What is %x12? Can you dump it?arrowd
ah yeah sorry about that, forgot to paste in, should be "%reg", not %x12 -- edited postEvan
To debug this, break into debugger, get to the failing assertion and run U.getUser()->dump(). The problem is not with %reg operand, but with a user of %x13.arrowd
What @arrowd says here is precisely what I too would do.arnt

1 Answers

3
votes

LLVM has constants and instructions. Constants are things such as 12, but also functions and global variables (which have constant addresses). Instructions are things that involve some sort of action.

Constants can use constants (for example, a constant's initialiser can reference other constants). Instructions can use constants (for example, you can store to a global variable). Instructions can use instructions (for example, you can load from an address which is the result of an instruction).

But constants cannot use instructions.

When the code that asserts looks at %x13 = load double, double* %reg, the User variable points to the the operand (%reg) and the operand's parent is the load instruction. I don't know what it points to when it asserts, but whatever ->getParent() returns isn't an instruction, and whatever is being used is one.