gpt4 book ai didi

LLVM "Instruction does not dominate all uses"- 插入新指令

转载 作者:行者123 更新时间:2023-12-02 17:34:59 24 4
gpt4 key购买 nike

使用 llvm pass 插入指令时出现以下错误:

Instruction does not dominate all uses!
%add = add nsw i32 10, 2
%cmp3 = icmp ne i32 %a.01, %add
Broken module found, compilation aborted!

我在一个 bitcode 文件中有源代码,其片段是:

if.then:                                          ; preds = %entry
%add = add nsw i32 10, 2
br label %if.end
if.else: ; preds = %entry
%sub = sub nsw i32 10, 2
br label %if.end
if.end: ; preds = %if.else, %if.then
%a.0 = phi i32 [ %add, %if.then ], [ %sub, %if.else ]
%a.01 = call i32 @tauInt32Ty(i32 %a.0) ; line A
%add3 = add nsw i32 %a.01, 2
%add4 = add nsw i32 %a.01, 3
%call5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([7 x i8]* @.str2, i32 0, i32 0), i32 %add3, i32 %add4)

我想在“A 行”之后插入一条新指令:

%cmp3 = icmp ne i32 %a.01, %add

我写了一个函数 pass,其执行此任务的代码片段是:

for (Function::iterator bb = F.begin(), e = F.end(); bb != e; ++bb) {
for (BasicBlock::iterator i = bb->begin(), e = bb->end(); i != e; ++i) {
std::string str;
if(isa<CallInst>(i))// || true) {
BasicBlock::iterator next_it = i;
next_it++;
Instruction* next = dyn_cast<Instruction>(&*next_it);
CallInst* ci = dyn_cast<CallInst>(&*i);
Function* ff = ci->getCalledFunction();
str = ff->getName();
errs()<<"> "<<str<<"\n";
if(!str.compare("tauInt32Ty")) {
hotPathSSA1::varVersionWithPathsSet::iterator start = tauArguments[&*ci].begin();
hotPathSSA1::varVersionWithPathsSet::iterator end = tauArguments[&*ci].end();
Value* specArgs = start->second; // specArgs points to %add
ICmpInst* int1_cmp_56 = new ICmpInst(next, ICmpInst::ICMP_NE, ci, specArgs, "cmp3");
}
}
}
}

最佳答案

jet 我没有遇到过这样的问题,但我认为你的问题是if 语句。 %add 属于 if.then BasicBlock,它不能从 if.end block 访问。这就是为什么 phi 指令“选择”可用 %add%sub 的原因。因此,您必须将 IcmpInst 的 %a.0 作为参数,而不是 %add

关于LLVM "Instruction does not dominate all uses"- 插入新指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27817331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com