[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp DataStructure.cpp Local.cpp Printer.cpp Steensgaard.cpp TopDownClosure.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Jan 31 22:53:05 PST 2003


Changes in directory llvm/lib/Analysis/DataStructure:

BottomUpClosure.cpp updated: 1.49 -> 1.50
DataStructure.cpp updated: 1.77 -> 1.78
Local.cpp updated: 1.44 -> 1.45
Printer.cpp updated: 1.43 -> 1.44
Steensgaard.cpp updated: 1.15 -> 1.16
TopDownClosure.cpp updated: 1.32 -> 1.33

---
Log message:

Change DSGraph stuff to use hash_(set|map) instead of std::(set|map)
This change provides a small (3%) but consistent speedup



---
Diffs of the changes:

Index: llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp
diff -u llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp:1.49 llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp:1.50
--- llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp:1.49	Fri Jan 31 22:01:20 2003
+++ llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp	Fri Jan 31 22:51:55 2003
@@ -11,6 +11,7 @@
 #include "llvm/Analysis/DSGraph.h"
 #include "llvm/Module.h"
 #include "Support/Statistic.h"
+#include "Support/hash_map"
 
 namespace {
   Statistic<> MaxSCC("budatastructure", "Maximum SCC Size in Call Graph");
@@ -128,7 +129,7 @@
 
 void BUDataStructures::calculateReachableGraphs(Function *F) {
   std::vector<Function*> Stack;
-  std::map<Function*, unsigned> ValMap;
+  hash_map<Function*, unsigned> ValMap;
   unsigned NextID = 1;
   calculateGraphs(F, Stack, NextID, ValMap);
 }
@@ -152,7 +153,7 @@
 unsigned BUDataStructures::calculateGraphs(Function *F,
                                            std::vector<Function*> &Stack,
                                            unsigned &NextID, 
-                                     std::map<Function*, unsigned> &ValMap) {
+                                     hash_map<Function*, unsigned> &ValMap) {
   assert(ValMap.find(F) == ValMap.end() && "Shouldn't revisit functions!");
   unsigned Min = NextID++, MyID = Min;
   ValMap[F] = Min;
@@ -173,7 +174,7 @@
     Function *Callee = *I;
     unsigned M;
     // Have we visited the destination function yet?
-    std::map<Function*, unsigned>::iterator It = ValMap.find(Callee);
+    hash_map<Function*, unsigned>::iterator It = ValMap.find(Callee);
     if (It == ValMap.end())  // No, visit it now.
       M = calculateGraphs(Callee, Stack, NextID, ValMap);
     else                    // Yes, get it's number.
@@ -206,7 +207,7 @@
   } else {
     // SCCFunctions - Keep track of the functions in the current SCC
     //
-    std::set<Function*> SCCFunctions;
+    hash_set<Function*> SCCFunctions;
 
     Function *NF;
     std::vector<Function*>::iterator FirstInSCC = Stack.end();
@@ -283,7 +284,7 @@
 // our memory... here...
 //
 void BUDataStructures::releaseMemory() {
-  for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
+  for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
          E = DSInfo.end(); I != E; ++I)
     delete I->second;
 
@@ -383,7 +384,7 @@
 // IN the SCC at all.
 //
 DSGraph &BUDataStructures::inlineNonSCCGraphs(Function &F,
-                                             std::set<Function*> &SCCFunctions){
+                                             hash_set<Function*> &SCCFunctions){
   DSGraph &Graph = getDSGraph(F);
   DEBUG(std::cerr << "  [BU] Inlining Non-SCC graphs for: "
                   << F.getName() << "\n");
@@ -452,12 +453,12 @@
 
 
 DSGraph &BUDataStructures::calculateSCCGraph(Function &F,
-                                             std::set<Function*> &SCCFunctions){
+                                             hash_set<Function*> &SCCFunctions){
   DSGraph &Graph = getDSGraph(F);
   DEBUG(std::cerr << "  [BU] Calculating SCC graph for: " << F.getName()<<"\n");
 
   std::vector<DSCallSite> UnresolvableCalls;
-  std::map<Function*, DSCallSite> SCCCallSiteMap;
+  hash_map<Function*, DSCallSite> SCCCallSiteMap;
   std::vector<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls();
 
   while (1) {  // Loop until we run out of resolvable call sites!


Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.77 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.78
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.77	Fri Jan 31 22:01:20 2003
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Fri Jan 31 22:51:55 2003
@@ -540,12 +540,12 @@
 
 DSGraph::DSGraph(const DSGraph &G) : Func(G.Func), GlobalsGraph(0) {
   PrintAuxCalls = false;
-  std::map<const DSNode*, DSNodeHandle> NodeMap;
+  hash_map<const DSNode*, DSNodeHandle> NodeMap;
   RetNode = cloneInto(G, ScalarMap, NodeMap);
 }
 
 DSGraph::DSGraph(const DSGraph &G,
-                 std::map<const DSNode*, DSNodeHandle> &NodeMap)
+                 hash_map<const DSNode*, DSNodeHandle> &NodeMap)
   : Func(G.Func), GlobalsGraph(0) {
   PrintAuxCalls = false;
   RetNode = cloneInto(G, ScalarMap, NodeMap);
@@ -572,7 +572,7 @@
 /// remapLinks - Change all of the Links in the current node according to the
 /// specified mapping.
 ///
-void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) {
+void DSNode::remapLinks(hash_map<const DSNode*, DSNodeHandle> &OldNodeMap) {
   for (unsigned i = 0, e = Links.size(); i != e; ++i) {
     DSNodeHandle &H = OldNodeMap[Links[i].getNode()];
     Links[i].setNode(H.getNode());
@@ -588,8 +588,8 @@
 // calling function's graph.
 //
 DSNodeHandle DSGraph::cloneInto(const DSGraph &G, 
-                                std::map<Value*, DSNodeHandle> &OldValMap,
-                              std::map<const DSNode*, DSNodeHandle> &OldNodeMap,
+                                hash_map<Value*, DSNodeHandle> &OldValMap,
+                              hash_map<const DSNode*, DSNodeHandle> &OldNodeMap,
                                 unsigned CloneFlags) {
   assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
   assert(&G != this && "Cannot clone graph into itself!");
@@ -625,7 +625,7 @@
   }
 
   // Copy the value map... and merge all of the global nodes...
-  for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
+  for (hash_map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
          E = G.ScalarMap.end(); I != E; ++I) {
     DSNodeHandle &H = OldValMap[I->first];
     DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
@@ -633,7 +633,7 @@
     H.setOffset(I->second.getOffset()+MappedNode.getOffset());
 
     if (isa<GlobalValue>(I->first)) {  // Is this a global?
-      std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
+      hash_map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
       if (GVI != ScalarMap.end()) {   // Is the global value in this fn already?
         GVI->second.mergeWith(H);
       } else {
@@ -671,16 +671,16 @@
 ///
 void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph,
                            unsigned CloneFlags) {
-  std::map<Value*, DSNodeHandle> OldValMap;
+  hash_map<Value*, DSNodeHandle> OldValMap;
   DSNodeHandle RetVal;
-  std::map<Value*, DSNodeHandle> *ScalarMap = &OldValMap;
+  hash_map<Value*, DSNodeHandle> *ScalarMap = &OldValMap;
 
   // If this is not a recursive call, clone the graph into this graph...
   if (&Graph != this) {
     // Clone the callee's graph into the current graph, keeping
     // track of where scalars in the old graph _used_ to point,
     // and of the new nodes matching nodes of the old graph.
-    std::map<const DSNode*, DSNodeHandle> OldNodeMap;
+    hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
     
     // The clone call may invalidate any of the vectors in the data
     // structure graph.  Strip locals and don't copy the list of callers
@@ -811,7 +811,7 @@
 // removeRefsToGlobal - Helper function that removes globals from the
 // ScalarMap so that the referrer count will go down to zero.
 static void removeRefsToGlobal(DSNode* N,
-                               std::map<Value*, DSNodeHandle> &ScalarMap) {
+                               hash_map<Value*, DSNodeHandle> &ScalarMap) {
   while (!N->getGlobals().empty()) {
     GlobalValue *GV = N->getGlobals().back();
     N->getGlobals().pop_back();      
@@ -939,18 +939,16 @@
 /// DSNodes, marking any nodes which are reachable.  All reachable nodes it adds
 /// to the set, which allows it to only traverse visited nodes once.
 ///
-void DSNode::markReachableNodes(std::set<DSNode*> &ReachableNodes) {
+void DSNode::markReachableNodes(hash_set<DSNode*> &ReachableNodes) {
   if (this == 0) return;
-  std::set<DSNode*>::iterator I = ReachableNodes.lower_bound(this);
-  if (I != ReachableNodes.end() && *I == this)
-    return;                                        // Already marked reachable
-  ReachableNodes.insert(I, this);                  // Is reachable now
+  if (ReachableNodes.count(this)) return;          // Already marked reachable
+  ReachableNodes.insert(this);                     // Is reachable now
 
   for (unsigned i = 0, e = getSize(); i < e; i += DS::PointerSize)
     getLink(i).getNode()->markReachableNodes(ReachableNodes);
 }
 
-void DSCallSite::markReachableNodes(std::set<DSNode*> &Nodes) {
+void DSCallSite::markReachableNodes(hash_set<DSNode*> &Nodes) {
   getRetVal().getNode()->markReachableNodes(Nodes);
   getCallee().getNode()->markReachableNodes(Nodes);
   
@@ -965,8 +963,8 @@
 //
 // This function returns true if the specified node is alive.
 //
-static bool markAliveIfCanReachAlive(DSNode *N, std::set<DSNode*> &Alive,
-                                     std::set<DSNode*> &Visited) {
+static bool markAliveIfCanReachAlive(DSNode *N, hash_set<DSNode*> &Alive,
+                                     hash_set<DSNode*> &Visited) {
   if (N == 0) return false;
 
   // If we know that this node is alive, return so!
@@ -974,10 +972,9 @@
 
   // Otherwise, we don't think the node is alive yet, check for infinite
   // recursion.
-  std::set<DSNode*>::iterator VI = Visited.lower_bound(N);
-  if (VI != Visited.end() && *VI == N) return false;  // Found a cycle
+  if (Visited.count(N)) return false;  // Found a cycle
   // No recursion, insert into Visited...
-  Visited.insert(VI, N);
+  Visited.insert(N);
 
   if (N->NodeType & DSNode::GlobalNode)
     return false; // Global nodes will be marked on their own
@@ -992,8 +989,8 @@
   return ChildrenAreAlive;
 }
 
-static bool CallSiteUsesAliveArgs(DSCallSite &CS, std::set<DSNode*> &Alive,
-                                  std::set<DSNode*> &Visited) {
+static bool CallSiteUsesAliveArgs(DSCallSite &CS, hash_set<DSNode*> &Alive,
+                                  hash_set<DSNode*> &Visited) {
   if (markAliveIfCanReachAlive(CS.getRetVal().getNode(), Alive, Visited) ||
       markAliveIfCanReachAlive(CS.getCallee().getNode(), Alive, Visited))
     return true;
@@ -1034,11 +1031,11 @@
   // FIXME: Merge nontrivially identical call nodes...
 
   // Alive - a set that holds all nodes found to be reachable/alive.
-  std::set<DSNode*> Alive;
+  hash_set<DSNode*> Alive;
   std::vector<std::pair<Value*, DSNode*> > GlobalNodes;
 
   // Mark all nodes reachable by (non-global) scalar nodes as alive...
-  for (std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.begin(),
+  for (hash_map<Value*, DSNodeHandle>::iterator I = ScalarMap.begin(),
          E = ScalarMap.end(); I != E; ++I)
     if (!isa<GlobalValue>(I->first) ||
         GlobalIsAlivenessRoot(I->second.getNode(), Flags))
@@ -1052,7 +1049,7 @@
   // If any global nodes points to a non-global that is "alive", the global is
   // "alive" as well...
   //
-  std::set<DSNode*> Visited;
+  hash_set<DSNode*> Visited;
   for (unsigned i = 0, e = GlobalNodes.size(); i != e; ++i)
     markAliveIfCanReachAlive(GlobalNodes[i].second, Alive, Visited);
 
@@ -1129,7 +1126,7 @@
 // This is a helper function for cloneGlobals and cloneCalls.
 // 
 DSNode* GlobalDSGraph::cloneNodeInto(DSNode *OldNode,
-                                    std::map<const DSNode*, DSNode*> &NodeCache,
+                                    hash_map<const DSNode*, DSNode*> &NodeCache,
                                     bool GlobalsAreFinal) {
   if (OldNode == 0) return 0;
 
@@ -1208,7 +1205,7 @@
 // links (and recursively their such links) into this graph.
 // 
 void GlobalDSGraph::cloneCalls(DSGraph& Graph) {
-  std::map<const DSNode*, DSNode*> NodeCache;
+  hash_map<const DSNode*, DSNode*> NodeCache;
   std::vector<DSCallSite >& FromCalls =Graph.FunctionCalls;
 
   FunctionCalls.reserve(FunctionCalls.size() + FromCalls.size());


Index: llvm/lib/Analysis/DataStructure/Local.cpp
diff -u llvm/lib/Analysis/DataStructure/Local.cpp:1.44 llvm/lib/Analysis/DataStructure/Local.cpp:1.45
--- llvm/lib/Analysis/DataStructure/Local.cpp:1.44	Fri Jan 31 22:01:21 2003
+++ llvm/lib/Analysis/DataStructure/Local.cpp	Fri Jan 31 22:51:55 2003
@@ -56,12 +56,12 @@
     DSGraph &G;
     std::vector<DSNode*> &Nodes;
     DSNodeHandle &RetNode;               // Node that gets returned...
-    std::map<Value*, DSNodeHandle> &ScalarMap;
+    hash_map<Value*, DSNodeHandle> &ScalarMap;
     std::vector<DSCallSite> &FunctionCalls;
 
   public:
     GraphBuilder(DSGraph &g, std::vector<DSNode*> &nodes, DSNodeHandle &retNode,
-                 std::map<Value*, DSNodeHandle> &SM,
+                 hash_map<Value*, DSNodeHandle> &SM,
                  std::vector<DSCallSite> &fc)
       : G(g), Nodes(nodes), RetNode(retNode), ScalarMap(SM), FunctionCalls(fc) {
 
@@ -166,7 +166,7 @@
         return NH = getValueDest(*CE->getOperand(0));
       if (CE->getOpcode() == Instruction::GetElementPtr) {
         visitGetElementPtrInst(*CE);
-        std::map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE);
+        hash_map<Value*, DSNodeHandle>::iterator I = ScalarMap.find(CE);
         assert(I != ScalarMap.end() && "GEP didn't get processed right?");
         return NH = I->second;
       }
@@ -431,7 +431,7 @@
 // our memory... here...
 //
 void LocalDataStructures::releaseMemory() {
-  for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
+  for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
          E = DSInfo.end(); I != E; ++I)
     delete I->second;
 


Index: llvm/lib/Analysis/DataStructure/Printer.cpp
diff -u llvm/lib/Analysis/DataStructure/Printer.cpp:1.43 llvm/lib/Analysis/DataStructure/Printer.cpp:1.44
--- llvm/lib/Analysis/DataStructure/Printer.cpp:1.43	Fri Jan 31 22:01:21 2003
+++ llvm/lib/Analysis/DataStructure/Printer.cpp	Fri Jan 31 22:51:55 2003
@@ -87,8 +87,8 @@
   static void addCustomGraphFeatures(const DSGraph *G,
                                      GraphWriter<const DSGraph*> &GW) {
     // Add scalar nodes to the graph...
-    const std::map<Value*, DSNodeHandle> &VM = G->getScalarMap();
-    for (std::map<Value*, DSNodeHandle>::const_iterator I = VM.begin();
+    const hash_map<Value*, DSNodeHandle> &VM = G->getScalarMap();
+    for (hash_map<Value*, DSNodeHandle>::const_iterator I = VM.begin();
          I != VM.end(); ++I)
       if (!isa<GlobalValue>(I->first)) {
         std::stringstream OS;


Index: llvm/lib/Analysis/DataStructure/Steensgaard.cpp
diff -u llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.15 llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.16
--- llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.15	Thu Jan 23 16:05:33 2003
+++ llvm/lib/Analysis/DataStructure/Steensgaard.cpp	Fri Jan 31 22:51:55 2003
@@ -89,7 +89,7 @@
                                  const DSCallSite &Call,
                                  DSNodeHandle &RetVal) {
   assert(ResultGraph != 0 && "Result graph not allocated!");
-  std::map<Value*, DSNodeHandle> &ValMap = ResultGraph->getScalarMap();
+  hash_map<Value*, DSNodeHandle> &ValMap = ResultGraph->getScalarMap();
 
   // Handle the return value of the function...
   if (Call.getRetVal().getNode() && RetVal.getNode())
@@ -98,7 +98,7 @@
   // Loop over all pointer arguments, resolving them to their provided pointers
   unsigned PtrArgIdx = 0;
   for (Function::aiterator AI = F->abegin(), AE = F->aend(); AI != AE; ++AI) {
-    std::map<Value*, DSNodeHandle>::iterator I = ValMap.find(AI);
+    hash_map<Value*, DSNodeHandle>::iterator I = ValMap.find(AI);
     if (I != ValMap.end())    // If its a pointer argument...
       I->second.addEdgeTo(Call.getPtrArg(PtrArgIdx++));
   }
@@ -120,16 +120,16 @@
   // RetValMap - Keep track of the return values for all functions that return
   // valid pointers.
   //
-  std::map<Function*, DSNodeHandle> RetValMap;
+  hash_map<Function*, DSNodeHandle> RetValMap;
 
   // Loop over the rest of the module, merging graphs for non-external functions
   // into this graph.
   //
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isExternal()) {
-      std::map<Value*, DSNodeHandle> ValMap;
+      hash_map<Value*, DSNodeHandle> ValMap;
       {  // Scope to free NodeMap memory ASAP
-        std::map<const DSNode*, DSNodeHandle> NodeMap;
+        hash_map<const DSNode*, DSNodeHandle> NodeMap;
         const DSGraph &FDSG = LDS.getDSGraph(*I);
         DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
 
@@ -142,11 +142,11 @@
 
       // Incorporate the inlined Function's ScalarMap into the global
       // ScalarMap...
-      std::map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
+      hash_map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
 
       while (!ValMap.empty()) { // Loop over value map, moving entries over...
         const std::pair<Value*, DSNodeHandle> &DSN = *ValMap.begin();
-        std::map<Value*, DSNodeHandle>::iterator I = GVM.find(DSN.first);
+        hash_map<Value*, DSNodeHandle>::iterator I = GVM.find(DSN.first);
         if (I == GVM.end())
           GVM[DSN.first] = DSN.second;
         else
@@ -209,12 +209,12 @@
 AliasAnalysis::Result Steens::alias(const Value *V1, const Value *V2) {
   assert(ResultGraph && "Result graph has not been computed yet!");
 
-  std::map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
+  hash_map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
 
-  std::map<Value*, DSNodeHandle>::iterator I = GVM.find(const_cast<Value*>(V1));
+  hash_map<Value*, DSNodeHandle>::iterator I = GVM.find(const_cast<Value*>(V1));
   if (I != GVM.end() && I->second.getNode()) {
     DSNodeHandle &V1H = I->second;
-    std::map<Value*, DSNodeHandle>::iterator J=GVM.find(const_cast<Value*>(V2));
+    hash_map<Value*, DSNodeHandle>::iterator J=GVM.find(const_cast<Value*>(V2));
     if (J != GVM.end() && J->second.getNode()) {
       DSNodeHandle &V2H = J->second;
       // If the two pointers point to different data structure graph nodes, they


Index: llvm/lib/Analysis/DataStructure/TopDownClosure.cpp
diff -u llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.32 llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.33
--- llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.32	Thu Jan 23 16:05:33 2003
+++ llvm/lib/Analysis/DataStructure/TopDownClosure.cpp	Fri Jan 31 22:51:55 2003
@@ -40,7 +40,7 @@
 // our memory... here...
 //
 void TDDataStructures::releaseMemory() {
-  for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
+  for (hash_map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
          E = DSInfo.end(); I != E; ++I)
     delete I->second;
 
@@ -140,8 +140,8 @@
             << "'\n");
       
       // Clone our current graph into the callee...
-      std::map<Value*, DSNodeHandle> OldValMap;
-      std::map<const DSNode*, DSNodeHandle> OldNodeMap;
+      hash_map<Value*, DSNodeHandle> OldValMap;
+      hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
       CG.cloneInto(Graph, OldValMap, OldNodeMap,
                    DSGraph::StripModRefBits |
                    DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes);





More information about the llvm-commits mailing list