[LLVMdev] Alias analysis result

borya043 borya.043 at gmail.com
Wed Mar 7 20:17:54 PST 2012


That's the reason I have defined getAnalysisUsage method. Isn't that the
right way to do it?

borya043 wrote:
> 
> Hello everyone,
> 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;
>     }
> };
> }
> 
> 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:)
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 

-- 
View this message in context: http://old.nabble.com/Alias-analysis-result-tp33458451p33462761.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list