In the TD pass, don't iterate over the scalar map to find the globals, iterate over
[oota-llvm.git] / lib / Analysis / DataStructure / DSCallSiteIterator.h
index 62a1515f92183947c666a795382a0cdea417917c..df9f36908aeb8163b79742e6643751866317a496 100644 (file)
@@ -1,4 +1,11 @@
 //===- DSCallSiteIterator.h - Iterator for DSGraph call sites ---*- C++ -*-===//
+// 
+//                     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 implements an iterator for complete call sites in DSGraphs.  This
 // code can either iterator over the normal call list or the aux calls list, and
@@ -12,6 +19,8 @@
 #include "llvm/Analysis/DSGraph.h"
 #include "llvm/Function.h"
 
+namespace llvm {
+
 struct DSCallSiteIterator {
   // FCs are the edges out of the current node are the call site targets...
   const std::vector<DSCallSite> *FCs;
@@ -28,13 +37,26 @@ struct DSCallSiteIterator {
     CallSite = FCs->size(); CallSiteEntry = 0;
   }
 
+  static bool isVAHackFn(const Function *F) {
+    return F->getName() == "printf"  || F->getName() == "sscanf" ||
+      F->getName() == "fprintf" || F->getName() == "open" ||
+      F->getName() == "sprintf" || F->getName() == "fputs" ||
+      F->getName() == "fscanf";
+  }
+
+  // isUnresolvableFunction - Return true if this is an unresolvable
+  // external function.  A direct or indirect call to this cannot be resolved.
+  // 
+  static bool isUnresolvableFunc(const Function* callee) {
+    return callee->isExternal() && !isVAHackFn(callee);
+  } 
+
   void advanceToValidCallee() {
     while (CallSite < FCs->size()) {
       if ((*FCs)[CallSite].isDirectCall()) {
         if (CallSiteEntry == 0 &&        // direct call only has one target...
-            (!(*FCs)[CallSite].getCalleeFunc()->isExternal() ||
-             isVAHackFn((*FCs)[CallSite].getCalleeFunc()))) // If not external
-          return;
+            ! isUnresolvableFunc((*FCs)[CallSite].getCalleeFunc()))
+          return;                       // and not an unresolvable external func
       } else {
         DSNode *CalleeNode = (*FCs)[CallSite].getCalleeNode();
         if (CallSiteEntry || isCompleteNode(CalleeNode)) {
@@ -50,14 +72,6 @@ struct DSCallSiteIterator {
       ++CallSite;
     }
   }
-
-  static bool isVAHackFn(const Function *F) {
-    return F->getName() == "printf"  || F->getName() == "sscanf" ||
-      F->getName() == "fprintf" || F->getName() == "open" ||
-      F->getName() == "sprintf" || F->getName() == "fputs" ||
-      F->getName() == "fscanf" || F->getName() == "bzero" ||
-      F->getName() == "memset";
-  }
   
   // isCompleteNode - Return true if we know all of the targets of this node,
   // and if the call sites are not external.
@@ -66,9 +80,8 @@ struct DSCallSiteIterator {
     if (N->isIncomplete()) return false;
     const std::vector<GlobalValue*> &Callees = N->getGlobals();
     for (unsigned i = 0, e = Callees.size(); i != e; ++i)
-      if (Callees[i]->isExternal())
-        if (!isVAHackFn(cast<Function>(Callees[i])))
-          return false;  // External function found...
+      if (isUnresolvableFunc(cast<Function>(Callees[i])))
+        return false;               // Unresolvable external function found...
     return true;  // otherwise ok
   }
 
@@ -118,4 +131,6 @@ public:
   }
 };
 
+} // End llvm namespace
+
 #endif