Take CallGraph out of the CFG namespace. It has nothing to do with CFGs
authorChris Lattner <sabre@nondot.org>
Wed, 6 Mar 2002 17:16:43 +0000 (17:16 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 6 Mar 2002 17:16:43 +0000 (17:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1820 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/CallGraph.h
lib/Analysis/IPA/CallGraph.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/Transforms/IPO/MutateStructTypes.cpp

index cc6d023d6dd2a1864bc29bbfebded5cfe248b6dd..a2494654c5d01961c0a8be46dd941d00abbae4f1 100644 (file)
@@ -21,8 +21,6 @@
 class Method;
 class Module;
 
-namespace cfg {
-
 class CallGraph;
 class CallGraphNode {
   Method *Meth;
@@ -141,41 +139,39 @@ private:   // Implementation of CallGraph construction
   void addToCallGraph(Method *M);
 };
 
-}  // end namespace cfg
-
 
 
 
 // Provide graph traits for tranversing call graphs using standard graph
 // traversals.
-template <> struct GraphTraits<cfg::CallGraphNode*> {
-  typedef cfg::CallGraphNode NodeType;
+template <> struct GraphTraits<CallGraphNode*> {
+  typedef CallGraphNode NodeType;
   typedef NodeType::iterator ChildIteratorType;
 
-  static NodeType *getEntryNode(cfg::CallGraphNode *CGN) { return CGN; }
+  static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
   static inline ChildIteratorType child_begin(NodeType *N) { return N->begin();}
   static inline ChildIteratorType child_end  (NodeType *N) { return N->end(); }
 };
 
-template <> struct GraphTraits<const cfg::CallGraphNode*> {
-  typedef const cfg::CallGraphNode NodeType;
+template <> struct GraphTraits<const CallGraphNode*> {
+  typedef const CallGraphNode NodeType;
   typedef NodeType::const_iterator ChildIteratorType;
 
-  static NodeType *getEntryNode(const cfg::CallGraphNode *CGN) { return CGN; }
+  static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
   static inline ChildIteratorType child_begin(NodeType *N) { return N->begin();}
   static inline ChildIteratorType child_end  (NodeType *N) { return N->end(); }
 };
 
 
-template<> struct GraphTraits<cfg::CallGraph*> :
-  public GraphTraits<cfg::CallGraphNode*> {
-  static NodeType *getEntryNode(cfg::CallGraph *CGN) {
+template<> struct GraphTraits<CallGraph*> :
+  public GraphTraits<CallGraphNode*> {
+  static NodeType *getEntryNode(CallGraph *CGN) {
     return CGN->getRoot();
   }
 };
-template<> struct GraphTraits<const cfg::CallGraph*> :
-  public GraphTraits<const cfg::CallGraphNode*> {
-  static NodeType *getEntryNode(const cfg::CallGraph *CGN) {
+template<> struct GraphTraits<const CallGraph*> :
+  public GraphTraits<const CallGraphNode*> {
+  static NodeType *getEntryNode(const CallGraph *CGN) {
     return CGN->getRoot();
   }
 };
@@ -185,6 +181,6 @@ template<> struct GraphTraits<const cfg::CallGraph*> :
 // Note that this uses the call graph only if one is provided.
 // It does not build the call graph.
 // 
-bool isLeafMethod(const Method* method, const cfg::CallGraph *callGraph = 0);
+bool isLeafMethod(const Method* method, const CallGraph *callGraph = 0);
 
 #endif
index 04b8c2d6bc8d4aa8d7bbeb0c3feb8660913b6921..713c181fbccd7298c5ca0cf2b623c0123051457e 100644 (file)
 #include "Support/STLExtras.h"
 #include <algorithm>
 
-AnalysisID cfg::CallGraph::ID(AnalysisID::create<cfg::CallGraph>());
-//AnalysisID cfg::CallGraph::ID(AnalysisID::template AnalysisID<cfg::CallGraph>());
+AnalysisID CallGraph::ID(AnalysisID::create<CallGraph>());
+//AnalysisID CallGraph::ID(AnalysisID::template AnalysisID<CallGraph>());
 
 // getNodeFor - Return the node for the specified method or create one if it
 // does not already exist.
 //
-cfg::CallGraphNode *cfg::CallGraph::getNodeFor(Method *M) {
+CallGraphNode *CallGraph::getNodeFor(Method *M) {
   iterator I = MethodMap.find(M);
   if (I != MethodMap.end()) return I->second;
 
@@ -40,7 +40,7 @@ cfg::CallGraphNode *cfg::CallGraph::getNodeFor(Method *M) {
 // addToCallGraph - Add a method to the call graph, and link the node to all of
 // the methods that it calls.
 //
-void cfg::CallGraph::addToCallGraph(Method *M) {
+void CallGraph::addToCallGraph(Method *M) {
   CallGraphNode *Node = getNodeFor(M);
 
   // If this method has external linkage, 
@@ -56,7 +56,7 @@ void cfg::CallGraph::addToCallGraph(Method *M) {
   }
 }
 
-bool cfg::CallGraph::run(Module *TheModule) {
+bool CallGraph::run(Module *TheModule) {
   destroy();
 
   Mod = TheModule;
@@ -70,7 +70,7 @@ bool cfg::CallGraph::run(Module *TheModule) {
   return false;
 }
 
-void cfg::CallGraph::destroy() {
+void CallGraph::destroy() {
   for (MethodMapTy::iterator I = MethodMap.begin(), E = MethodMap.end();
        I != E; ++I) {
     delete I->second;
@@ -79,7 +79,7 @@ void cfg::CallGraph::destroy() {
 }
 
 
-void cfg::WriteToOutput(const CallGraphNode *CGN, std::ostream &o) {
+void WriteToOutput(const CallGraphNode *CGN, std::ostream &o) {
   if (CGN->getMethod())
     o << "Call graph node for method: '" << CGN->getMethod()->getName() <<"'\n";
   else
@@ -90,7 +90,7 @@ void cfg::WriteToOutput(const CallGraphNode *CGN, std::ostream &o) {
   o << "\n";
 }
 
-void cfg::WriteToOutput(const CallGraph &CG, std::ostream &o) {
+void WriteToOutput(const CallGraph &CG, std::ostream &o) {
   WriteToOutput(CG.getRoot(), o);
   for (CallGraph::const_iterator I = CG.begin(), E = CG.end(); I != E; ++I)
     o << I->second;
@@ -104,7 +104,7 @@ void cfg::WriteToOutput(const CallGraph &CG, std::ostream &o) {
 // Methods to keep a call graph up to date with a method that has been
 // modified
 //
-void cfg::CallGraph::addMethodToModule(Method *Meth) {
+void CallGraph::addMethodToModule(Method *Meth) {
   assert(0 && "not implemented");
   abort();
 }
@@ -115,7 +115,7 @@ void cfg::CallGraph::addMethodToModule(Method *Meth) {
 // methods (ie, there are no edges in it's CGN).  The easiest way to do this
 // is to dropAllReferences before calling this.
 //
-Method *cfg::CallGraph::removeMethodFromModule(CallGraphNode *CGN) {
+Method *CallGraph::removeMethodFromModule(CallGraphNode *CGN) {
   assert(CGN->CalledMethods.empty() && "Cannot remove method from call graph"
         " if it references other methods!");
   Method *M = CGN->getMethod();  // Get the method for the call graph node
@@ -132,9 +132,9 @@ Method *cfg::CallGraph::removeMethodFromModule(CallGraphNode *CGN) {
 // Note that this uses the call graph only if one is provided.
 // It does not build the call graph.
 // 
-bool IsLeafMethod(const Method* M, const cfg::CallGraph* CG) {
+bool IsLeafMethod(const Method* M, const CallGraph* CG) {
   if (CG) {
-    const cfg::CallGraphNode *cgn = (*CG)[M];
+    const CallGraphNode *cgn = (*CG)[M];
     return (cgn->begin() == cgn->end());
   }
 
index 454f6014e6dbd43a90f5a89b0ad704dd93dbaa8c..ea23dbedda12006972417a9075a402b21fda5280 100644 (file)
 #include "Support/DepthFirstIterator.h"
 #include <set>
 
-static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph &CallGraph) {
+static bool RemoveUnreachableMethods(Module *M, CallGraph &CallGraph) {
   // Calculate which methods are reachable from the external methods in the call
   // graph.
   //
-  std::set<cfg::CallGraphNode*> ReachableNodes(df_begin(&CallGraph),
-                                               df_end(&CallGraph));
+  std::set<CallGraphNode*> ReachableNodes(df_begin(&CallGraph),
+                                          df_end(&CallGraph));
 
   // Loop over the methods in the module twice.  The first time is used to drop
   // references that methods have to each other before they are deleted.  The
   // second pass removes the methods that need to be removed.
   //
-  std::vector<cfg::CallGraphNode*> MethodsToDelete;   // Track unused methods
+  std::vector<CallGraphNode*> MethodsToDelete;   // Track unused methods
   for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
-    cfg::CallGraphNode *N = CallGraph[*I];
+    CallGraphNode *N = CallGraph[*I];
     if (!ReachableNodes.count(N)) {              // Not reachable??
       (*I)->dropAllReferences();
       N->removeAllCalledMethods();
@@ -39,7 +39,7 @@ static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph &CallGraph) {
   // Unreachables methods have been found and should have no references to them,
   // delete them now.
   //
-  for (std::vector<cfg::CallGraphNode*>::iterator I = MethodsToDelete.begin(),
+  for (std::vector<CallGraphNode*>::iterator I = MethodsToDelete.begin(),
         E = MethodsToDelete.end(); I != E; ++I)
     delete CallGraph.removeMethodFromModule(*I);
 
@@ -52,7 +52,7 @@ namespace {
     // the specified callgraph to reflect the changes.
     //
     bool run(Module *M) {
-      return RemoveUnreachableMethods(M, getAnalysis<cfg::CallGraph>());
+      return RemoveUnreachableMethods(M, getAnalysis<CallGraph>());
     }
 
     // getAnalysisUsageInfo - This function works on the call graph of a module.
@@ -62,9 +62,9 @@ namespace {
     virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
                                       Pass::AnalysisSet &Destroyed,
                                       Pass::AnalysisSet &Provided) {
-      Required.push_back(cfg::CallGraph::ID);
+      Required.push_back(CallGraph::ID);
       // FIXME: This should update the callgraph, not destroy it!
-      Destroyed.push_back(cfg::CallGraph::ID);
+      Destroyed.push_back(CallGraph::ID);
     }
   };
 }
index 77109330c4ecd9c9449d93a42bf376c2a9fcf2ce..c67a2e006d29baaebea82c876b7825d55208834a 100644 (file)
@@ -531,5 +531,5 @@ void MutateStructTypes::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
                                              Pass::AnalysisSet &Provided) {
   Destroyed.push_back(FindUsedTypes::ID);
   Destroyed.push_back(FindUnsafePointerTypes::ID);
-  Destroyed.push_back(cfg::CallGraph::ID);
+  Destroyed.push_back(CallGraph::ID);
 }