Llvm 在basicblock中查找在以前的basicblock中计算的值
在basicblock中,我希望找到指令中使用的所有值,这些值不是在同一basicblock中计算的。Llvm 在basicblock中查找在以前的basicblock中计算的值,llvm,Llvm,在basicblock中,我希望找到指令中使用的所有值,这些值不是在同一basicblock中计算的。 例如, 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 %
例如,
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
在上面的例子中,我应该得到
%2
%b
%a
%3
在其他基本块中声明和/或分配。请给我推荐一种方法。
提前谢谢 嗨,我还没有测试过,但我会这样做:
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);
}
}
}
向量值;
基本块::迭代器;
User::op_迭代器it;
//迭代块中的所有指令
对于(it=block->begin();it++;it!=block->end()){
//迭代指令使用的操作数。llvm::User类中定义的“op_begin”。
对于(操作数_it=it->op_begin();操作数_it++;操作数_it!=it->op_end()){
//这个if-else语句可以减少吗?
//如果此操作数是参数,则未在块中定义。
if(isa(操作数_-it)){
值。推回(操作数);
}
//否则,它可能是一个常量值或。。。
else如果(!isa(操作数_it)){
继续;
}
//检查指令的父级是否不是有问题的块。
else if(((指令*)操作数)->getParent()!=块){
值。推回(操作数);
}
}
}