[llvm-commits] CVS: poolalloc/lib/PoolAllocate/PoolAllocate.cpp PoolAllocate.h

Chris Lattner lattner at cs.uiuc.edu
Tue Feb 8 15:46:44 PST 2005



Changes in directory poolalloc/lib/PoolAllocate:

PoolAllocate.cpp updated: 1.99 -> 1.100
PoolAllocate.h updated: 1.35 -> 1.36

---
Log message:

Add a pointer to FuncInfo to indicate what function it is for.
Add CloneToOrigMap and getOrigFunctionFromClone method.
Speed up getFuncInfoOrClone.
Add comments.


---
Diffs of the changes:  (+35 -14)

Index: poolalloc/lib/PoolAllocate/PoolAllocate.cpp
diff -u poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.99 poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.100
--- poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.99	Tue Feb  8 15:46:49 2005
+++ poolalloc/lib/PoolAllocate/PoolAllocate.cpp	Tue Feb  8 17:46:34 2005
@@ -267,10 +267,15 @@
 }
 
 
+/// FindFunctionPoolArgs - In the first pass over the program, we decide which
+/// arguments will have to be added for each function, build the FunctionInfo
+/// map and recording this info in the ArgNodes set.
 void PoolAllocate::FindFunctionPoolArgs(Function &F) {
   DSGraph &G = ECGraphs->getDSGraph(F);
 
-  FuncInfo &FI = FunctionInfo[&F];   // Create a new entry for F
+  // Create a new entry for F.
+  FuncInfo &FI =
+    FunctionInfo.insert(std::make_pair(&F, FuncInfo(F))).first->second;
   hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
 
   if (G.node_begin() == G.node_end())
@@ -292,7 +297,7 @@
   DSGraph &G = ECGraphs->getDSGraph(F);
   if (G.node_begin() == G.node_end()) return 0;
     
-  FuncInfo &FI = FunctionInfo[&F];
+  FuncInfo &FI = *getFuncInfo(F);
   if (FI.ArgNodes.empty())
     return 0;           // No need to clone if no pools need to be passed in!
 
@@ -314,6 +319,7 @@
   // Create the new function...
   Function *New = new Function(FuncTy, Function::InternalLinkage, F.getName());
   F.getParent()->getFunctionList().insert(&F, New);
+  CloneToOrigMap[New] = &F;   // Remember original function.
 
   // Set the rest of the new arguments names to be PDa<n> and add entries to the
   // pool descriptors map
@@ -515,7 +521,7 @@
 
   if (G.node_begin() == G.node_end()) return;  // Quick exit if nothing to do.
   
-  FuncInfo &FI = FunctionInfo[&F];   // Get FuncInfo for F
+  FuncInfo &FI = *getFuncInfo(F);
   hash_set<const DSNode*> &MarkedNodes = FI.MarkedNodes;
 
   // Calculate which DSNodes are reachable from globals.  If a node is reachable


Index: poolalloc/lib/PoolAllocate/PoolAllocate.h
diff -u poolalloc/lib/PoolAllocate/PoolAllocate.h:1.35 poolalloc/lib/PoolAllocate/PoolAllocate.h:1.36
--- poolalloc/lib/PoolAllocate/PoolAllocate.h:1.35	Tue Feb  8 16:11:45 2005
+++ poolalloc/lib/PoolAllocate/PoolAllocate.h	Tue Feb  8 17:46:34 2005
@@ -44,14 +44,18 @@
   /// maps to the original function...
   ///
   struct FuncInfo {
-    FuncInfo() : Clone(0) {}
+    FuncInfo(Function &f) : F(f), Clone(0) {}
 
     /// MarkedNodes - The set of nodes which are not locally pool allocatable in
     /// the current function.
     ///
     hash_set<const DSNode*> MarkedNodes;
 
+    /// F - The function this FuncInfo corresponds to.
+    Function &F;
+
     /// Clone - The cloned version of the function, if applicable.
+    ///
     Function *Clone;
 
     /// ArgNodes - The list of DSNodes which have pools passed in as arguments.
@@ -70,15 +74,15 @@
     /// indirect function calls that are not used in the function.
     std::map<const DSNode*, Value*> PoolDescriptors;
 
-    //This is a map from Old to New Value Map reverse of the one above
-    //Useful in SAFECode for check insertion
-    std::map<const Value*, Value*> ValueMap;
-
     /// NewToOldValueMap - When and if a function needs to be cloned, this map
     /// contains a mapping from all of the values in the new function back to
     /// the values they correspond to in the old function.
     ///
     std::map<Value*, const Value*> NewToOldValueMap;
+
+    /// ValueMap - This is a map from Old to New Value Map reverse of the one
+    /// above.  Useful in SAFECode for check insertion.
+    std::map<const Value*, Value*> ValueMap;
   };
 
 }; // end PA namespace
@@ -92,8 +96,8 @@
   PA::EquivClassGraphs *ECGraphs;
 
   std::map<Function*, PA::FuncInfo> FunctionInfo;
-
- public:
+  std::map<Function*, Function*> CloneToOrigMap;
+public:
 
   Function *PoolInit, *PoolDestroy, *PoolAlloc, *PoolRealloc, *PoolMemAlign;
   Function *PoolFree;
@@ -113,7 +117,16 @@
   
   PA::EquivClassGraphs &getECGraphs() const { return *ECGraphs; }
   
+  /// getOrigFunctionFromClone - Given a pointer to a function that was cloned
+  /// from another function, return the original function.  If the argument
+  /// function is not a clone, return null.
+  Function *getOrigFunctionFromClone(Function *F) const {
+    std::map<Function*, Function*>::const_iterator I = CloneToOrigMap.find(F);
+    return I != CloneToOrigMap.end() ? I->second : 0;
+  }
+
   /// getFuncInfo - Return the FuncInfo object for the specified function.
+  ///
   PA::FuncInfo *getFuncInfo(Function &F) {
     std::map<Function*, PA::FuncInfo>::iterator I = FunctionInfo.find(&F);
     return I != FunctionInfo.end() ? &I->second : 0;
@@ -127,10 +140,8 @@
     if (PA::FuncInfo *FI = getFuncInfo(F))
       return FI;
     // Maybe this is a function clone?
-    for (std::map<Function*, PA::FuncInfo>::iterator I = FunctionInfo.begin(),
-           E = FunctionInfo.end(); I != E; ++I)
-      if (I->second.Clone == &F)
-        return &I->second;
+    if (Function *FC = getOrigFunctionFromClone(&F))
+      return getFuncInfo(F);
     return 0;
   }
   
@@ -140,6 +151,7 @@
   virtual void releaseMemory() {
     FunctionInfo.clear();
     GlobalNodes.clear();
+    CloneToOrigMap.clear();
   }
 
 
@@ -175,6 +187,9 @@
   /// are global pools.
   bool SetupGlobalPools(Module &M);
 
+  /// FindFunctionPoolArgs - In the first pass over the program, we decide which
+  /// arguments will have to be added for each function, build the FunctionInfo
+  /// map and recording this info in the ArgNodes set.
   void FindFunctionPoolArgs(Function &F);   
   
   /// MakeFunctionClone - If the specified function needs to be modified for





More information about the llvm-commits mailing list