LLVM中的别名分析 [英] Alias Analysis in LLVM
问题描述
我试图找到存储指令的指针操作数和函数参数之间的别名。这是代码,
I am trying to find the alias between a store instruction's pointer operand and function arguments. This is the code,
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredTransitive<AliasAnalysis>();
AU.addPreserved<AliasAnalysis>();
}
virtual bool runOnFunction(Function &F) {
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
for(Function::iterator i=F.begin();i!=F.end();++i){
for(BasicBlock::iterator j=i->begin();j!=i->end();++j)
{
if(dyn_cast<StoreInst>(j)){
const StoreInst *SI=dyn_cast<StoreInst>(j);
AliasAnalysis::Location LocA = AA.getLocation(SI);
const Value *si_v= SI->getPointerOperand();
for(Function::arg_iterator k=F.arg_begin(); k!=F.arg_end();++k)
{
Value *v=dyn_cast<Value>(k);
AliasAnalysis::Location loc=AliasAnalysis::Location(v);
AliasAnalysis::AliasResult ar=AA.alias(LocA,loc);
switch(ar)
{
case 0:errs()<< "NoAlias\n";
break;
///< No dependencies.
case 1:errs()<<"MayAlias\n"; ///< Anything goes
break;
case 2: errs()<<"PartialAlias\n";///< Pointers differ, but pointees overlap.
break;
case 3: errs()<<"MustAlias\n";
}
}
}
return true;
}
};
}
但我得到MayAlias结果,即使存储指令的指针操作数不引用函数参数。逻辑有什么问题吗?在LLVM源代码中是否有任何包含类似代码的文件。感谢:)
But I get MayAlias result even if the store instruction's pointer operand is not referencing the function argument. Is there something wrong with the logic? Are there any files in the LLVM source code that contain code to do something similar. Thanks:)
推荐答案
AA组的默认别名分析方法是basicaa,总是返回可能别名。尝试指定一个AA方法(--globalsmodref-aa,-scev-aa,..)而不是让选择使用默认值。
The default alias analysis method from the AA group is basicaa, which always return "may alias". Try specifying an AA method (--globalsmodref-aa, -scev-aa,..) instead of letting opt use the default.
像这样:opt -globalsmodref -aa -your_pass ...
Something like this: opt -globalsmodref-aa -your_pass ...
这篇关于LLVM中的别名分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!