DONT_BUILD_RELINKED is gone and implied by BUILD_ARCHIVE now
[oota-llvm.git] / lib / Analysis / IPA / Andersens.cpp
index 146c88aaebd1f464d121113bab7ec24ea52c8813..c33a3254aa7b13825fb46c2373008607ff44d5d5 100644 (file)
@@ -1,10 +1,10 @@
 //===- Andersens.cpp - Andersen's Interprocedural Alias Analysis ----------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This file defines a very simple implementation of Andersen's interprocedural
@@ -43,8 +43,8 @@
 //
 // Future Improvements:
 //   This implementation of Andersen's algorithm is extremely slow.  To make it
-//   scale reasonably well, the inclusion constraints could be sorted (easy), 
-//   offline variable substitution would be a huge win (straight-forward), and 
+//   scale reasonably well, the inclusion constraints could be sorted (easy),
+//   offline variable substitution would be a huge win (straight-forward), and
 //   online cycle elimination (trickier) might help as well.
 //
 //===----------------------------------------------------------------------===//
@@ -137,7 +137,7 @@ namespace {
     std::map<Value*, unsigned> ValueNodes;
 
     /// ObjectNodes - This map contains entries for each memory object in the
-    /// program: globals, alloca's and mallocs.  
+    /// program: globals, alloca's and mallocs.
     std::map<Value*, unsigned> ObjectNodes;
 
     /// ReturnNodes - This map contains an entry for each function in the
@@ -161,7 +161,7 @@ namespace {
       Constraint(ConstraintType Ty, Node *D, Node *S)
         : Type(Ty), Dest(D), Src(S) {}
     };
-    
+
     /// Constraints - This vector contains a list of all of the constraints
     /// identified by the program.
     std::vector<Constraint> Constraints;
@@ -193,7 +193,7 @@ namespace {
       NullPtr      = 1,
       NullObject   = 2,
     };
-    
+
   public:
     bool runOnModule(Module &M) {
       InitializeAliasAnalysis(this);
@@ -209,7 +209,7 @@ namespace {
       ReturnNodes.clear();
       VarargNodes.clear();
       EscapingInternalFunctions.clear();
-      std::vector<Constraint>().swap(Constraints);      
+      std::vector<Constraint>().swap(Constraints);
       return false;
     }
 
@@ -232,7 +232,7 @@ namespace {
 
     //------------------------------------------------
     // Implement the AliasAnalysis API
-    //  
+    //
     AliasResult alias(const Value *V1, unsigned V1Size,
                       const Value *V2, unsigned V2Size);
     ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
@@ -265,7 +265,7 @@ namespace {
       }
       return &GraphNodes[I->second];
     }
-    
+
     /// getObject - Return the node corresponding to the memory object for the
     /// specified global or allocation instruction.
     Node *getObject(Value *V) {
@@ -330,7 +330,6 @@ namespace {
     void visitCastInst(CastInst &CI);
     void visitSetCondInst(SetCondInst &SCI) {} // NOOP!
     void visitSelectInst(SelectInst &SI);
-    void visitVANext(VANextInst &I);
     void visitVAArg(VAArgInst &I);
     void visitInstruction(Instruction &I);
   };
@@ -374,19 +373,12 @@ Andersens::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
       Node *N1 = getNode(P);
       bool PointsToUniversalSet = false;
 
-      for (Node::iterator NI = N1->begin(), E = N1->end(); NI != E; ++NI) {
-        Node *PN = *NI;
-        if (PN->begin() == PN->end())
-          continue;  // P doesn't point to anything.
-        // Get the first pointee.
-        Node *FirstPointee = *PN->begin();
-        if (FirstPointee == &GraphNodes[UniversalSet]) {
-          PointsToUniversalSet = true;
-          break;
-        }
-      }
+      if (N1->begin() == N1->end())
+        return NoModRef;  // P doesn't point to anything.
 
-      if (!PointsToUniversalSet)
+      // Get the first pointee.
+      Node *FirstPointee = *N1->begin();
+      if (FirstPointee != &GraphNodes[UniversalSet])
         return NoModRef;  // P doesn't point to the universal set.
     }
 
@@ -422,7 +414,7 @@ void Andersens::getMustAliases(Value *P, std::vector<Value*> &RetVals) {
       }
     }
   }
-  
+
   AliasAnalysis::getMustAliases(P, RetVals);
 }
 
@@ -579,7 +571,7 @@ void Andersens::AddGlobalInitializerConstraints(Node *N, Constant *C) {
   if (C->getType()->isFirstClassType()) {
     if (isa<PointerType>(C->getType()))
       N->copyFrom(getNodeForConstantPointer(C));
-                                       
+
   } else if (C->isNullValue()) {
     N->addPointerTo(&GraphNodes[NullObject]);
     return;
@@ -614,7 +606,7 @@ bool Andersens::AddConstraintsForExternalCall(CallSite CS, Function *F) {
       F->getName() == "atol" || F->getName() == "atoll" ||
       F->getName() == "remove" || F->getName() == "unlink" ||
       F->getName() == "rename" || F->getName() == "memcmp" ||
-      F->getName() == "llvm.memset" || 
+      F->getName() == "llvm.memset" ||
       F->getName() == "strcmp" || F->getName() == "strncmp" ||
       F->getName() == "execl" || F->getName() == "execlp" ||
       F->getName() == "execle" || F->getName() == "execv" ||
@@ -710,7 +702,7 @@ void Andersens::CollectConstraints(Module &M) {
                                        &GraphNodes[UniversalSet]));
     }
   }
-  
+
   for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
     // Make the function address point to the function object.
     getNodeValue(*F)->addPointerTo(getObject(F)->setValue(F));
@@ -847,6 +839,8 @@ void Andersens::visitCastInst(CastInst &CI) {
 #if 0
       Constraints.push_back(Constraint(Constraint::Copy, getNodeValue(CI),
                                        &GraphNodes[UniversalSet]));
+#else
+      getNodeValue(CI);
 #endif
     }
   } else if (isa<PointerType>(Op->getType())) {
@@ -855,6 +849,8 @@ void Andersens::visitCastInst(CastInst &CI) {
     Constraints.push_back(Constraint(Constraint::Copy,
                                      &GraphNodes[UniversalSet],
                                      getNode(CI.getOperand(0))));
+#else
+    getNode(CI.getOperand(0));
 #endif
   }
 }
@@ -870,10 +866,6 @@ void Andersens::visitSelectInst(SelectInst &SI) {
   }
 }
 
-void Andersens::visitVANext(VANextInst &I) {
-  // FIXME: Implement
-  assert(0 && "vanext not handled yet!");
-}
 void Andersens::visitVAArg(VAArgInst &I) {
   assert(0 && "vaarg not handled yet!");
 }
@@ -905,7 +897,7 @@ void Andersens::AddConstraintsForCall(CallSite CS, Function *F) {
                                      &GraphNodes[UniversalSet],
                                      getReturnNode(F)));
   }
-  
+
   Function::arg_iterator AI = F->arg_begin(), AE = F->arg_end();
   CallSite::arg_iterator ArgI = CS.arg_begin(), ArgE = CS.arg_end();
   for (; AI != AE && ArgI != ArgE; ++AI, ++ArgI)
@@ -923,7 +915,7 @@ void Andersens::AddConstraintsForCall(CallSite CS, Function *F) {
                                        &GraphNodes[UniversalSet],
                                        getNode(*ArgI)));
     }
-  
+
   // Copy all pointers passed through the varargs section to the varargs node.
   if (F->getFunctionType()->isVarArg())
     for (; ArgI != ArgE; ++ArgI)