Remove trailing whitespace
[oota-llvm.git] / lib / Analysis / DataStructure / EquivClassGraphs.cpp
index 02b7fb7d824aa8c59c7471f598fc803ed5bce35c..e9b324aed64c1764f49a41402d20371e620a3dce 100644 (file)
@@ -1,10 +1,10 @@
 //===- EquivClassGraphs.cpp - Merge equiv-class graphs & inline bottom-up -===//
-// 
+//
 //                     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 pass is the same as the complete bottom-up graphs, but
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "ECGraphs"
-#include "llvm/Analysis/DataStructure/EquivClassGraphs.h"
+#include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Analysis/DataStructure/DSGraph.h"
-#include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/ADT/SCCIterator.h"
@@ -51,12 +50,12 @@ static void CheckAllGraphs(Module *M, GT &ECGraphs) {
 
       DSGraph::NodeMapTy GlobalsGraphNodeMapping;
       G.computeGToGGMapping(GlobalsGraphNodeMapping);
-    } 
+    }
 }
 #endif
 
 // getSomeCalleeForCallSite - Return any one callee function at a call site.
-// 
+//
 Function *EquivClassGraphs::getSomeCalleeForCallSite(const CallSite &CS) const{
   Function *thisFunc = CS.getCaller();
   assert(thisFunc && "getSomeCalleeForCallSite(): Not a valid call site?");
@@ -72,9 +71,10 @@ Function *EquivClassGraphs::getSomeCalleeForCallSite(const CallSite &CS) const{
 //
 bool EquivClassGraphs::runOnModule(Module &M) {
   CBU = &getAnalysis<CompleteBUDataStructures>();
+  GlobalECs = CBU->getGlobalECs();
   DEBUG(CheckAllGraphs(&M, *CBU));
 
-  GlobalsGraph = new DSGraph(CBU->getGlobalsGraph());
+  GlobalsGraph = new DSGraph(CBU->getGlobalsGraph(), GlobalECs);
   GlobalsGraph->setPrintAuxCalls();
 
   ActualCallees = CBU->getActualCallees();
@@ -94,7 +94,7 @@ bool EquivClassGraphs::runOnModule(Module &M) {
   } else {
     std::cerr << "Fold Graphs: No 'main' function found!\n";
   }
-  
+
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isExternal())
       processSCC(getOrCreateGraph(*I), Stack, NextID, ValMap);
@@ -110,7 +110,7 @@ bool EquivClassGraphs::runOnModule(Module &M) {
   if (MainFunc && !MainFunc->isExternal()) {
     DSGraph &MainGraph = getOrCreateGraph(*MainFunc);
     const DSGraph &GG = *MainGraph.getGlobalsGraph();
-    ReachabilityCloner RC(MainGraph, GG, 
+    ReachabilityCloner RC(MainGraph, GG,
                           DSGraph::DontCloneCallNodes |
                           DSGraph::DontCloneAuxCallNodes);
 
@@ -121,7 +121,7 @@ bool EquivClassGraphs::runOnModule(Module &M) {
         RC.getClonedNH(GG.getNodeForValue(*I));
 
     MainGraph.maskIncompleteMarkers();
-    MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs | 
+    MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs |
                                   DSGraph::IgnoreGlobals);
   }
 
@@ -158,7 +158,7 @@ bool EquivClassGraphs::runOnModule(Module &M) {
 //
 void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
   const ActualCalleesTy& AC = CBU->getActualCallees();
-  
+
   // Loop over all of the indirect calls in the program.  If a call site can
   // call multiple different functions, we need to unify all of the callees into
   // the same equivalence class.
@@ -204,7 +204,7 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
     // equivalence class.  More precisely, if F is in the class, and G(F) is
     // its graph, then we include all other functions that are also in G(F).
     // Currently, that is just the functions in the same call-graph-SCC as F.
-    // 
+    //
     DSGraph& funcDSGraph = CBU->getDSGraph(*I->second);
     for (DSGraph::retnodes_iterator RI = funcDSGraph.retnodes_begin(),
            RE = funcDSGraph.retnodes_end(); RI != RE; ++RI)
@@ -242,24 +242,24 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
     DSGraph &MergedG = getOrCreateGraph(*LF);
 
     // Record the argument nodes for use in merging later below.
-    std::vector<DSNodeHandle> ArgNodes;  
+    std::vector<DSNodeHandle> ArgNodes;
 
     for (Function::arg_iterator AI = LF->arg_begin(), E = LF->arg_end();
          AI != E; ++AI)
       if (DS::isPointerType(AI->getType()))
         ArgNodes.push_back(MergedG.getNodeForValue(AI));
-      
+
     // Merge in the graphs of all other functions in this equiv. class.  Note
     // that two or more functions may have the same graph, and it only needs
     // to be merged in once.
     std::set<DSGraph*> GraphsMerged;
     GraphsMerged.insert(&CBU->getDSGraph(*LF));
-    
+
     for (++SI; SI != FuncECs.member_end(); ++SI) {
       Function *F = *SI;
       DSGraph *&FG = DSInfo[F];
-      
-      DSGraph &CBUGraph = CBU->getDSGraph(*F); 
+
+      DSGraph &CBUGraph = CBU->getDSGraph(*F);
       if (GraphsMerged.insert(&CBUGraph).second) {
         // Record the "folded" graph for the function.
         for (DSGraph::retnodes_iterator I = CBUGraph.retnodes_begin(),
@@ -267,18 +267,14 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
           assert(DSInfo[I->first] == 0 && "Graph already exists for Fn!");
           DSInfo[I->first] = &MergedG;
         }
-        
+
         // Clone this member of the equivalence class into MergedG.
-        {
-          DSGraph::NodeMapTy NodeMap;    
-          MergedG.cloneInto(CBUGraph, MergedG.getScalarMap(),
-                            MergedG.getReturnNodes(), NodeMap, 0);
-        }
+        MergedG.cloneInto(CBUGraph);
       }
-      
+
       // Merge the return nodes of all functions together.
       MergedG.getReturnNodes()[LF].mergeWith(MergedG.getReturnNodes()[F]);
-      
+
       // Merge the function arguments with all argument nodes found so far.
       // If there are extra function args, add them to the vector of argNodes
       Function::arg_iterator AI2 = F->arg_begin(), AI2end = F->arg_end();
@@ -286,7 +282,7 @@ void EquivClassGraphs::buildIndirectFunctionSets(Module &M) {
            arg != numArgs && AI2 != AI2end; ++AI2, ++arg)
         if (DS::isPointerType(AI2->getType()))
           ArgNodes[arg].mergeWith(MergedG.getNodeForValue(AI2));
-      
+
       for ( ; AI2 != AI2end; ++AI2)
         if (DS::isPointerType(AI2->getType()))
           ArgNodes.push_back(MergedG.getNodeForValue(AI2));
@@ -305,7 +301,7 @@ DSGraph &EquivClassGraphs::getOrCreateGraph(Function &F) {
   DSGraph &CBUGraph = CBU->getDSGraph(F);
 
   // Copy the CBU graph...
-  Graph = new DSGraph(CBUGraph);           // updates the map via reference
+  Graph = new DSGraph(CBUGraph, GlobalECs);   // updates the map via reference
   Graph->setGlobalsGraph(&getGlobalsGraph());
   Graph->setPrintAuxCalls();
 
@@ -323,7 +319,7 @@ DSGraph &EquivClassGraphs::getOrCreateGraph(Function &F) {
 
 
 unsigned EquivClassGraphs::
-processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack, unsigned &NextID, 
+processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack, unsigned &NextID,
            std::map<DSGraph*, unsigned> &ValMap) {
   std::map<DSGraph*, unsigned>::iterator It = ValMap.lower_bound(&FG);
   if (It != ValMap.end() && It->first == &FG)
@@ -342,8 +338,8 @@ processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack, unsigned &NextID,
     Instruction *Call = CI->getCallSite().getInstruction();
 
     // Loop over all of the actually called functions...
-    ActualCalleesTy::const_iterator I, E;
-    for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I)
+    for (callee_iterator I = callee_begin(Call), E = callee_end(Call);
+         I != E; ++I)
       if (!I->second->isExternal()) {
         // Process the callee as necessary.
         unsigned M = processSCC(getOrCreateGraph(*I->second),
@@ -364,14 +360,13 @@ processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack, unsigned &NextID,
 
     // If the SCC found is not the same as those found in CBU, make sure to
     // merge the graphs as appropriate.
-    DSGraph::NodeMapTy NodeMap;
-    FG.cloneInto(*NG, FG.getScalarMap(), FG.getReturnNodes(), NodeMap);
+    FG.cloneInto(*NG);
 
     // Update the DSInfo map and delete the old graph...
     for (DSGraph::retnodes_iterator I = NG->retnodes_begin();
          I != NG->retnodes_end(); ++I)
       DSInfo[I->first] = &FG;
-    
+
     // Remove NG from the ValMap since the pointer may get recycled.
     ValMap.erase(NG);
     delete NG;
@@ -409,17 +404,16 @@ void EquivClassGraphs::processGraph(DSGraph &G) {
 
     assert(calls.insert(TheCall).second &&
            "Call instruction occurs multiple times in graph??");
-    
+
     if (CS.getRetVal().isNull() && CS.getNumPtrArgs() == 0)
       continue;
 
     // Inline the common callee graph into the current graph, if the callee
     // graph has not changed.  Note that all callees should have the same
     // graph so we only need to do this once.
-    // 
+    //
     DSGraph* CalleeGraph = NULL;
-    ActualCalleesTy::const_iterator I, E;
-    tie(I, E) = getActualCallees().equal_range(TheCall);
+    callee_iterator I = callee_begin(TheCall), E = callee_end(TheCall);
     unsigned TNum, Num;
 
     // Loop over all potential callees to find the first non-external callee.
@@ -430,17 +424,17 @@ void EquivClassGraphs::processGraph(DSGraph &G) {
     // Now check if the graph has changed and if so, clone and inline it.
     if (I != E) {
       Function *CalleeFunc = I->second;
-      
+
       // Merge the callee's graph into this graph, if not already the same.
       // Callees in the same equivalence class (which subsumes those
       // in the same SCCs) have the same graph.  Note that all recursion
       // including self-recursion have been folded in the equiv classes.
-      // 
+      //
       CalleeGraph = &getOrCreateGraph(*CalleeFunc);
       if (CalleeGraph != &G) {
         ++NumFoldGraphInlines;
         G.mergeInGraph(CS, *CalleeFunc, *CalleeGraph,
-                       DSGraph::KeepModRefBits | DSGraph::StripAllocaBit |
+                       DSGraph::StripAllocaBit |
                        DSGraph::DontCloneCallNodes |
                        DSGraph::DontCloneAuxCallNodes);
         DEBUG(std::cerr << "    Inlining graph [" << i << "/"
@@ -467,10 +461,9 @@ void EquivClassGraphs::processGraph(DSGraph &G) {
   }
 
   // Recompute the Incomplete markers.
-  assert(G.getInlinedGlobals().empty());
   G.maskIncompleteMarkers();
   G.markIncompleteNodes(DSGraph::MarkFormalArgs);
-  
+
   // Delete dead nodes.  Treat globals that are unreachable but that can
   // reach live nodes as live.
   G.removeDeadNodes(DSGraph::KeepUnreachableGlobals);
@@ -483,7 +476,7 @@ void EquivClassGraphs::processGraph(DSGraph &G) {
   // globals graph.
   DSScalarMap &MainSM = G.getScalarMap();
   for (DSScalarMap::global_iterator I = MainSM.global_begin(),
-         E = MainSM.global_end(); I != E; ++I) 
+         E = MainSM.global_end(); I != E; ++I)
     RC.getClonedNH(MainSM[*I]);
 
   DEBUG(std::cerr << "  -- DONE ProcessGraph for function "