问题描述
我正在用最少的指令数(通常是3-5个)拆分所有基本块:
I'm splitting all Basic Blocks with minimum number of instructions (usually 3-5):
llvm::SplitBlock(BasicBlock, &*BasicBlockiter, Pass);
并尝试从IR获取目标文件
and trying to get object file from IR
llc -filetype=obj 2.ll
我遇到以下错误:
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
和
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!"
和
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
我认为拆分之后,指令位于不同的基本块中.如果我将代码块分成10-15条指令,则一切正常.如何预测/检查并避免这种错误?
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?
推荐答案
在您的第一个版本中,您在终止符指令之后有一条指令,这是不正确的,因为该指令从不执行.
In your first version, you had instruction after a terminator instruction, which was incorrect since this instruction is never executed.
在您的第二个版本中(此处未提及,请使用stackoverflow而不是私人电子邮件...)在定义它之前(在store inst中)使用%call(%call = ...),因此显然您的定义确实不在每次使用之前...但是正如我所说,存储区不应该在调用之后,因为调用是一个terminatorinst.
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
等...
这篇关于LLVM:指令并非主导所有用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!