2015-01-07 48 views
2

同時使用LLVM通插入指令我收到以下錯誤:LLVM「指令不稱霸所有用途」 - 插入新的指令

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

我有一個位碼文件,其片段是源代碼:

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) 

我要 「行」,這是後插入一個新的指令:

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

我已經寫了一個功能通過,其代碼片段執行此任務是:

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

回答

4

我沒有遇到過這樣的問題jet,但我認爲你的問題是if語句。 %addif.then BasicBlock,它不可從if.end塊訪問。這就是爲什麼phi指令「選擇」哪個值可用%add%sub。所以你必須把%a.0作爲你的IcmpInst作爲參數而不是%add