LLVM“指令并不主导所有使用". -插入新指令 [英] LLVM "Instruction does not dominate all uses" - Inserting new Instruction

查看:200
本文介绍了LLVM“指令并不主导所有使用". -插入新指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting the following error while inserting an instruction using an 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!

我将源代码保存在一个位代码文件中,其片段为:

I have the source code in a bitcode file whose snippet is:

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行"之后插入一条新指令,即:

I want to insert a new instruction after "line A" which is :

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

我已经编写了一个函数传递,该函数传递的代码片段完成以下任务:

And I have written a function pass whose snippet of the code which does this task is :

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");
            }
        }
    }
}

推荐答案

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

I have not encountered such a problem jet but I think your problem is the if statement. %add belonges to the if.then BasicBlock and it is not accessable from the if.end block. This is why the phi instruction "chooses" which value is available %add or %sub. So you have to take %a.0 for your IcmpInst as argument not %add.

这篇关于LLVM“指令并不主导所有使用". -插入新指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆