Parsing Aliases in LLVM

I am trying to find an alias between the store instruction pointer operand and the function arguments. This is the code,

virtual void getAnalysisUsage(AnalysisUsage &AU) const {


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

                    case 0:errs()<<  "NoAlias\n";
                    ///< No dependencies.
                    case 1:errs()<<"MayAlias\n";    ///< Anything goes
                    case 2: errs()<<"PartialAlias\n";///< Pointers differ, but pointees overlap.

                    case 3: errs()<<"MustAlias\n";

   return true;


But I get the MayAlias ​​result even though the store instruction pointer operand does not reference the function argument. Is there something wrong with the logic? Are there files in the LLVM source code containing code to do something like this. Thank:)


source to share

1 answer

The default alias parsing method from group AA is basicaa, which always returns "may alias". Try specifying the AA method (-globalsmodref-aa, -scev-aa, ..) instead of letting opt use the default.

Something like this: opt -globalsmodref-aa-you_pass ...



All Articles