[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp ReaderInternals.h

Chris Lattner lattner at cs.uiuc.edu
Thu Oct 9 01:06:01 PDT 2003


Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.70 -> 1.71
ReaderInternals.h updated: 1.51 -> 1.52

---
Log message:

Eliminate the old LateResolveValues data structure, replacing it with a 
new, simpler, ForwardReferences data structure.  This is just the first
simple replacement, subsequent changes will improve the code more.

This simple change improves the performance of loading a file from HDF5
(contributed by Bill) from 2.36s to 1.93s, a 22% improvement.  This 
presumably has to do with the fact that we only create ONE placeholder for
a particular forward referenced values, and also may be because the data 
structure is much simpler.


---
Diffs of the changes:  (+28 -26)

Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.70 llvm/lib/Bytecode/Reader/Reader.cpp:1.71
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.70	Thu Oct  9 00:25:34 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Thu Oct  9 01:05:39 2003
@@ -128,8 +128,14 @@
 
   if (!Create) return 0;  // Do not create a placeholder?
 
+  std::pair<unsigned,unsigned> KeyValue(type, oNum);
+  std::map<std::pair<unsigned,unsigned>, Value*>::iterator I = 
+    ForwardReferences.lower_bound(KeyValue);
+  if (I != ForwardReferences.end() && I->first == KeyValue)
+    return I->second;   // We have already created this placeholder
+
   Value *Val = new ValPHolder(getType(type), oNum);
-  if (insertValue(Val, LateResolveValues) == -1) return 0;
+  ForwardReferences.insert(I, std::make_pair(KeyValue, Val));
   return Val;
 }
 
@@ -377,31 +383,27 @@
   ParsedBasicBlocks.clear();
 
 
-  // Check for unresolvable references
-  while (!LateResolveValues.empty()) {
-    ValueList &VL = *LateResolveValues.back();
-    LateResolveValues.pop_back();    
-
-    while (!VL.empty()) {
-      Value *V = VL.back();
-      unsigned IDNumber = getValueIDNumberFromPlaceHolder(V);
-      VL.pop_back();
-
-      Value *NewVal = getValue(V->getType(), IDNumber, false);
-      if (NewVal == 0)
-        throw std::string("Unresolvable reference found: <" +
-                          V->getType()->getDescription() + ">:" + 
-                          utostr(IDNumber) + ".");
+  // Resolve forward references
+  while (!ForwardReferences.empty()) {
+    std::map<std::pair<unsigned,unsigned>, Value*>::iterator I = ForwardReferences.begin();
+    unsigned type = I->first.first;
+    unsigned Slot = I->first.second;
+    Value *PlaceHolder = I->second;
+    ForwardReferences.erase(I);
+
+    Value *NewVal = getValue(type, Slot, false);
+    if (NewVal == 0)
+      throw std::string("Unresolvable reference found: <" +
+                        PlaceHolder->getType()->getDescription() + ">:" + 
+                        utostr(Slot) + ".");
 
-      // Fixup all of the uses of this placeholder def...
-      V->replaceAllUsesWith(NewVal);
+    // Fixup all of the uses of this placeholder def...
+    PlaceHolder->replaceAllUsesWith(NewVal);
       
-      // Now that all the uses are gone, delete the placeholder...
-      // If we couldn't find a def (error case), then leak a little
-      // memory, because otherwise we can't remove all uses!
-      delete V;
-    }
-    delete &VL;
+    // Now that all the uses are gone, delete the placeholder...
+    // If we couldn't find a def (error case), then leak a little
+    // memory, because otherwise we can't remove all uses!
+    delete PlaceHolder;
   }
 
   // Clear out function-level types...


Index: llvm/lib/Bytecode/Reader/ReaderInternals.h
diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.51 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.52
--- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.51	Thu Oct  9 00:25:34 2003
+++ llvm/lib/Bytecode/Reader/ReaderInternals.h	Thu Oct  9 01:05:40 2003
@@ -57,7 +57,6 @@
   }
   void freeState() {
     freeTable(Values);
-    freeTable(LateResolveValues);
     freeTable(ModuleValues);
   }
 
@@ -100,8 +99,9 @@
   bool hasInternalMarkerOnly;       // Only types of linkage are intern/external
 
   typedef std::vector<ValueList*> ValueTable;
-  ValueTable Values, LateResolveValues;
+  ValueTable Values;
   ValueTable ModuleValues;
+  std::map<std::pair<unsigned,unsigned>, Value*> ForwardReferences;
 
   std::vector<BasicBlock*> ParsedBasicBlocks;
 





More information about the llvm-commits mailing list