diff options
| author | Andrew Lenharth <andrewl@lenharth.org> | 2006-11-14 05:21:04 +0000 | 
|---|---|---|
| committer | Andrew Lenharth <andrewl@lenharth.org> | 2006-11-14 05:21:04 +0000 | 
| commit | 0ad1e3845b5dcef05a5e3f11dd67296ef8244a69 (patch) | |
| tree | 92aee50a8bbdd31af399ff721c88776485db8b0f | |
| parent | 1b89a7bcc15aed000d79495a2d0666c6ce5b7afb (diff) | |
| download | bcm5719-llvm-0ad1e3845b5dcef05a5e3f11dd67296ef8244a69.tar.gz bcm5719-llvm-0ad1e3845b5dcef05a5e3f11dd67296ef8244a69.zip  | |
A shim over other AA impls to catch incorrect uses
llvm-svn: 31724
| -rw-r--r-- | llvm/include/llvm/Analysis/Passes.h | 6 | ||||
| -rw-r--r-- | llvm/include/llvm/LinkAllPasses.h | 1 | ||||
| -rw-r--r-- | llvm/lib/Analysis/AliasDebugger.cpp | 125 | 
3 files changed, 132 insertions, 0 deletions
diff --git a/llvm/include/llvm/Analysis/Passes.h b/llvm/include/llvm/Analysis/Passes.h index 0b485746c8c..854128e1f96 100644 --- a/llvm/include/llvm/Analysis/Passes.h +++ b/llvm/include/llvm/Analysis/Passes.h @@ -30,6 +30,12 @@ namespace llvm {    //===--------------------------------------------------------------------===//    // +  // createAliasDebugger - This pass helps debug clients of AA +  // +  Pass *createAliasDebugger(); + +  //===--------------------------------------------------------------------===// +  //    // createAliasAnalysisCounterPass - This pass counts alias queries and how the    // alias analysis implementation responds.    // diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 0ef16ec8960..6e6a5d425a7 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -45,6 +45,7 @@ namespace {        (void) llvm::createAAEvalPass();        (void) llvm::createAggressiveDCEPass();        (void) llvm::createAliasAnalysisCounterPass(); +      (void) llvm::createAliasDebugger();        (void) llvm::createAndersensPass();        (void) llvm::createArgumentPromotionPass();        (void) llvm::createBasicAliasAnalysisPass(); diff --git a/llvm/lib/Analysis/AliasDebugger.cpp b/llvm/lib/Analysis/AliasDebugger.cpp new file mode 100644 index 00000000000..ddbb7bde4ca --- /dev/null +++ b/llvm/lib/Analysis/AliasDebugger.cpp @@ -0,0 +1,125 @@ +//===- AliasDebugger.cpp - Simple Alias Analysis Use Checker --------------===// +// +//                     The LLVM Compiler Infrastructure +// +// This file was developed by Andrew Lenharth and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This simple pass checks alias analysis users to ensure that if they +// create a new value, they do not query AA without informing it of the value. +// It acts as a shim over any other AA pass you want. +// +// Yes keeping track of every value in the program is expensive, but this is  +// a debugging pass. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/Passes.h" +#include "llvm/Module.h" +#include "llvm/Pass.h" +#include "llvm/Instructions.h" +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Analysis/AliasAnalysis.h" +#include <set> +using namespace llvm; + +namespace { +   +  class AliasDebugger : public ModulePass, public AliasAnalysis { + +    //What we do is simple.  Keep track of every value the AA could +    //know about, and verify that queries are one of those. +    //A query to a value that didn't exist when the AA was created +    //means someone forgot to update the AA when creating new values + +    std::set<const Value*> Vals; +     +  public: +    bool runOnModule(Module &M) { +      InitializeAliasAnalysis(this);                 // set up super class + +      for(Module::global_iterator I = M.global_begin(), +            E = M.global_end(); I != E; ++I) +        Vals.insert(&*I); + +      for(Module::iterator I = M.begin(), +            E = M.end(); I != E; ++I){ +        Vals.insert(&*I); +        if(!I->isExternal()) { +          for (Function::arg_iterator AI = I->arg_begin(), AE = I->arg_end(); +               AI != AE; ++AI)  +            Vals.insert(&*AI);      +          for (Function::const_iterator FI = I->begin(), FE = I->end(); +               FI != FE; ++FI)  +            for (BasicBlock::const_iterator BI = FI->begin(), BE = FI->end(); +                 BI != BE; ++BI) +              Vals.insert(&*BI); +        } +         +      } +      return false; +    } + +    virtual void getAnalysisUsage(AnalysisUsage &AU) const { +      AliasAnalysis::getAnalysisUsage(AU); +      AU.setPreservesAll();                         // Does not transform code +    } + +    //------------------------------------------------ +    // Implement the AliasAnalysis API +    // +    AliasResult alias(const Value *V1, unsigned V1Size, +                      const Value *V2, unsigned V2Size) { +      assert(Vals.find(V1) != Vals.end() && "Never seen value in AA before"); +      assert(Vals.find(V2) != Vals.end() && "Never seen value in AA before");     +      return AliasAnalysis::alias(V1, V1Size, V2, V2Size); +    } + +    ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) { +      assert(Vals.find(P) != Vals.end() && "Never seen value in AA before"); +      return AliasAnalysis::getModRefInfo(CS, P, Size); +    } + +    ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) { +      return AliasAnalysis::getModRefInfo(CS1,CS2); +    } +     +    void getMustAliases(Value *P, std::vector<Value*> &RetVals) { +      assert(Vals.find(P) != Vals.end() && "Never seen value in AA before"); +      return AliasAnalysis::getMustAliases(P, RetVals); +    } + +    bool pointsToConstantMemory(const Value *P) { +      assert(Vals.find(P) != Vals.end() && "Never seen value in AA before"); +      return AliasAnalysis::pointsToConstantMemory(P); +    } + +    /// getModRefBehavior - Return the behavior of the specified function if +    /// called from the specified call site.  The call site may be null in which +    /// case the most generic behavior of this function should be returned. +    virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS, +                                         std::vector<PointerAccessInfo> *Info) { +      assert(Vals.find(F) != Vals.end() && "Never seen value in AA before"); +      return AliasAnalysis::getModRefBehavior(F, CS, Info); +    } + +    virtual void deleteValue(Value *V) { +      assert(Vals.find(V) != Vals.end() && "Never seen value in AA before"); +      AliasAnalysis::deleteValue(V); +    } +    virtual void copyValue(Value *From, Value *To) { +      Vals.insert(To); +      AliasAnalysis::copyValue(From, To); +    } + +  }; + +  RegisterPass<AliasDebugger> X("debug-aa", "AA use debugger"); +  RegisterAnalysisGroup<AliasAnalysis> Y(X); +} + +Pass *llvm::createAliasDebugger() { return new AliasDebugger(); } +  | 

