diff options
| author | Dan Gohman <gohman@apple.com> | 2010-10-20 22:11:14 +0000 | 
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2010-10-20 22:11:14 +0000 | 
| commit | a2ab75bc8d96a00c64bc268f614889cf4e871f51 (patch) | |
| tree | 9e5ea614f788a175657af87cbc6cf47a784c8d90 /llvm/lib/Analysis | |
| parent | 55a028680c71beec46f9c8e6d7081f8f38391a1b (diff) | |
| download | bcm5719-llvm-a2ab75bc8d96a00c64bc268f614889cf4e871f51.tar.gz bcm5719-llvm-a2ab75bc8d96a00c64bc268f614889cf4e871f51.zip | |
Factor out the main aliasing check into a separate function.
llvm-svn: 116958
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp | 63 | 
1 files changed, 39 insertions, 24 deletions
| diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp index 787db7351aa..5994ffd702f 100644 --- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp +++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp @@ -103,6 +103,8 @@ namespace {        return this;      } +    bool Aliases(const MDNode *A, const MDNode *B) const; +    private:      virtual void getAnalysisUsage(AnalysisUsage &AU) const;      virtual AliasResult alias(const Location &LocA, const Location &LocB); @@ -125,27 +127,19 @@ TypeBasedAliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {    AliasAnalysis::getAnalysisUsage(AU);  } -AliasAnalysis::AliasResult -TypeBasedAliasAnalysis::alias(const Location &LocA, -                              const Location &LocB) { -  if (!EnableTBAA) -    return AliasAnalysis::alias(LocA, LocB); - -  // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must -  // be conservative. -  const MDNode *AM = LocA.TBAATag; -  if (!AM) return AliasAnalysis::alias(LocA, LocB); -  const MDNode *BM = LocB.TBAATag; -  if (!BM) return AliasAnalysis::alias(LocA, LocB); - +/// Aliases - Test whether the type represented by A may alias the +/// type represented by B. +bool +TypeBasedAliasAnalysis::Aliases(const MDNode *A, +                                const MDNode *B) const {    // Keep track of the root node for A and B.    TBAANode RootA, RootB;    // Climb the tree from A to see if we reach B. -  for (TBAANode T(AM); ; ) { -    if (T.getNode() == BM) +  for (TBAANode T(A); ; ) { +    if (T.getNode() == B)        // B is an ancestor of A. -      return AliasAnalysis::alias(LocA, LocB); +      return true;      RootA = T;      T = T.getParent(); @@ -154,10 +148,10 @@ TypeBasedAliasAnalysis::alias(const Location &LocA,    }    // Climb the tree from B to see if we reach A. -  for (TBAANode T(BM); ; ) { -    if (T.getNode() == AM) +  for (TBAANode T(B); ; ) { +    if (T.getNode() == A)        // A is an ancestor of B. -      return AliasAnalysis::alias(LocA, LocB); +      return true;      RootB = T;      T = T.getParent(); @@ -167,13 +161,34 @@ TypeBasedAliasAnalysis::alias(const Location &LocA,    // Neither node is an ancestor of the other. -  // If they have the same root, then we've proved there's no alias. -  if (RootA.getNode() == RootB.getNode()) -    return NoAlias; -    // If they have different roots, they're part of different potentially    // unrelated type systems, so we must be conservative. -  return AliasAnalysis::alias(LocA, LocB); +  if (RootA.getNode() != RootB.getNode()) +    return true; + +  // If they have the same root, then we've proved there's no alias. +  return false; +} + +AliasAnalysis::AliasResult +TypeBasedAliasAnalysis::alias(const Location &LocA, +                              const Location &LocB) { +  if (!EnableTBAA) +    return AliasAnalysis::alias(LocA, LocB); + +  // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must +  // be conservative. +  const MDNode *AM = LocA.TBAATag; +  if (!AM) return AliasAnalysis::alias(LocA, LocB); +  const MDNode *BM = LocB.TBAATag; +  if (!BM) return AliasAnalysis::alias(LocA, LocB); + +  // If they may alias, chain to the next AliasAnalysis. +  if (Aliases(AM, BM)) +    return AliasAnalysis::alias(LocA, LocB); + +  // Otherwise return a definitive result. +  return NoAlias;  }  bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Location &Loc) { | 

