LLVM: Instruction does not dominate all uses

筅森魡賤 提交于 2019-12-11 02:48:01

问题


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?


回答1:


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...



来源:https://stackoverflow.com/questions/19832757/llvm-instruction-does-not-dominate-all-uses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!