Question

I'm splitting all Basic Blocks with minimum number of instructions (usually 3-5):

llvm::SplitBlock(BasicBlock, &*BasicBlockiter, Pass);

and trying to get object file from IR

llc -filetype=obj 2.ll

I got the following errors:

Instruction does not dominate all uses!
  %1 = alloca i32
  %mul = load i32* %1
Instruction does not dominate all uses!
  %1 = alloca i32
  %99 = load i32* %1

and

While deleting: i32 %
Use still stuck around after Def is destroyed:  %var = alloca i32
Assertion failed: use_empty() && "Uses remain when a value is destroyed!"

and

error: expected instruction opcode
invoke.cont2:                                     ; preds = %main_block, %invoke
.cont

IR:

  invoke.cont2:                                     ; preds = %main_block, %invoke.cont
  %call4 = invoke i32 @_ZStorSt13_Ios_OpenmodeS_(i32 8, i32 16)
          to label %invoke.cont3 unwind label %lpad1
  store i32 %call4, i32* %var4

I think that after splitting, instructions are located in different basic blocks. If I split the block into 10-15 instructions, all is OK. How can I predict/check and avoid this errors?

Was it helpful?

Solution

In your first version, you had instruction after a terminator instruction, which was incorrect since this instruction is never executed.

In your second version (not mentioned here, please use stackoverflow instead of private emails...) are using %call (in the store inst) before defining it (%call = ...), so clearly your definition does not precede every use... But as I said, the store should not be after the invoke, because invoke is a terminatorinst.

The solution is to put your store in the next basic block (you can create a new one) :

%invoke.cont
  %call = invoke i8* @_ZNKSs5c_strEv(%"class.std::basic_string"* @loadedFile)
          to label %invoke.cont2_before unwind label %lpad1

invoke.cont2_before:                                     ; preds = %invoke.cont
  store i8* %call, i8** %reduced_var
  br label %invoke.cont2

invoke.cont2:                                     ; preds = %main_block, %invoke.cont2_before
  %call4 = invoke i32 @_ZStorSt13_Ios_OpenmodeS_(i32 8, i32 16)
          to label %invoke.cont3_before unwind label %lpad1

etc...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top