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 {

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

      

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

+3


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 ...

+5


source







All Articles