2012-03-12 4 views
1

基本ブロックでは、命令で使用されているすべての値を検索したい、同じ基本ブロック内で計算されていない。
例、上記の例で
前の基本ブロックで計算された基本ブロック内の値を見つけよう

for.body5: 
    %i.015 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ] 
    %add1 = add nsw i32 %2, %i.015 
    %arrayidx = getelementptr inbounds [100 x i32]* %b, i32 0, i32 %i.015 
    store i32 %add1, i32* %arrayidx, align 4, !tbaa !0 
    %arrayidx2 = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %i.015 
    store i32 %add1, i32* %arrayidx2, align 4, !tbaa !0 
    %inc = add nsw i32 %i.015, 1 
    %cmp = icmp slt i32 %inc, %3 
    br i1 %cmp, label %for.body, label %for.cond3.preheader 

iを取得する必要があり、宣言および/または他のbasicblocksに割り当てられ

%2 
    %b 
    %a 
    %3 


私に方法を提案してください。
ありがとうございます。

答えて

2

こんにちは、私はこれをテストしたhaventは、私はこのようなものだろう:

vector<Value*> values; 
BasicBlock::iterator it; 
User::op_iterator it; 

// Iterate over all of the instructions in the Block 
for (it=block->begin(); it++; it != block->end()){ 

    // Iterate over the operands used by an instruction. 'op_begin' Defined in llvm::User class. 
    for (operand_it=it->op_begin(); operand_it++; operand_it != it->op_end()){ 

     // Could this if else statement be reduced? 
     // If this operand is an argument it was not defined in the block. 
     if (isa<Argument>(operand_it)){ 
      values.push_back(operand_it); 
     } 
     // Otherwize, it could be a constant value or ... 
     else if (!isa<Instruction>(operand_it)){ 
      continue; 
     } 
     // Check if the parent of the instruction is not the block in question. 
     else if (((Instruction*)operand_it)->getParent() != block){ 
      values.push_back(operand_it); 
     } 

    } 

} 
関連する問題