PR7959: Handle negative scales in GEPs correctly in BasicAA for non-64-bit
[oota-llvm.git] / lib / Analysis / TypeBasedAliasAnalysis.cpp
index cab266b7f1dd53afedd3b09e4d5e4bc0bc1f785e..7069a178cb08d35d73af8a9bcd68b378e019f84b 100644 (file)
@@ -44,7 +44,7 @@ namespace {
 
   public:
     TBAANode() : Node(0) {}
-    explicit TBAANode(MDNode *N) : Node(N) {}
+    explicit TBAANode(const MDNode *N) : Node(N) {}
 
     /// getNode - Get the MDNode for this TBAANode.
     const MDNode *getNode() const { return Node; }
@@ -82,23 +82,22 @@ namespace {
                                  public AliasAnalysis {
   public:
     static char ID; // Class identification, replacement for typeinfo
-    TypeBasedAliasAnalysis() : ImmutablePass(&ID) {}
+    TypeBasedAliasAnalysis() : ImmutablePass(ID) {}
 
     /// getAdjustedAnalysisPointer - This method is used when a pass implements
     /// an analysis interface through multiple inheritance.  If needed, it
     /// should override this to adjust the this pointer as needed for the
     /// specified pass info.
-    virtual void *getAdjustedAnalysisPointer(const PassInfo *PI) {
-      if (PI->isPassID(&AliasAnalysis::ID))
+    virtual void *getAdjustedAnalysisPointer(const void *PI) {
+      if (PI == &AliasAnalysis::ID)
         return (AliasAnalysis*)this;
       return this;
     }
 
   private:
     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
-    virtual AliasResult alias(const Value *V1, unsigned V1Size,
-                              const Value *V2, unsigned V2Size);
-    virtual bool pointsToConstantMemory(const Value *P);
+    virtual AliasResult alias(const Location &LocA, const Location &LocB);
+    virtual bool pointsToConstantMemory(const Location &Loc);
   };
 }  // End of anonymous namespace
 
@@ -118,23 +117,13 @@ TypeBasedAliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
 }
 
 AliasAnalysis::AliasResult
-TypeBasedAliasAnalysis::alias(const Value *A, unsigned ASize,
-                              const Value *B, unsigned BSize) {
-  // Currently, metadata can only be attached to Instructions.
-  const Instruction *AI = dyn_cast<Instruction>(A);
-  if (!AI) return MayAlias;
-  const Instruction *BI = dyn_cast<Instruction>(B);
-  if (!BI) return MayAlias;
-
+TypeBasedAliasAnalysis::alias(const Location &LocA,
+                              const Location &LocB) {
   // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must
   // be conservative.
-  MDNode *AM =
-    AI->getMetadata(AI->getParent()->getParent()->getParent()
-                      ->getMDKindID("tbaa"));
+  const MDNode *AM = LocA.TBAATag;
   if (!AM) return MayAlias;
-  MDNode *BM =
-    AI->getMetadata(BI->getParent()->getParent()->getParent()
-                      ->getMDKindID("tbaa"));
+  const MDNode *BM = LocB.TBAATag;
   if (!BM) return MayAlias;
 
   // Keep track of the root node for A and B.
@@ -175,14 +164,8 @@ TypeBasedAliasAnalysis::alias(const Value *A, unsigned ASize,
   return MayAlias;
 }
 
-bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Value *P) {
-  // Currently, metadata can only be attached to Instructions.
-  const Instruction *I = dyn_cast<Instruction>(P);
-  if (!I) return false;
-
-  MDNode *M =
-    I->getMetadata(I->getParent()->getParent()->getParent()
-                    ->getMDKindID("tbaa"));
+bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Location &Loc) {
+  const MDNode *M = Loc.TBAATag;
   if (!M) return false;
 
   // If this is an "immutable" type, we can assume the pointer is pointing