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

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


Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.78 -> 1.79

---
Log message:

Another 10% performance improvement by not using replaceAllUsesWith


---
Diffs of the changes:  (+20 -13)

Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.78 llvm/lib/Bytecode/Reader/Reader.cpp:1.79
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.78	Thu Oct  9 17:39:30 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Thu Oct  9 18:10:14 2003
@@ -269,7 +269,6 @@
 
   BCR_TRACE(3, "Mutating forward refs!\n");
   Value *VPH = I->second;   // Get the placeholder...
-
   VPH->replaceAllUsesWith(NewV);
 
   // If this is a global variable being resolved, remove the placeholder from
@@ -382,25 +381,33 @@
     throw std::string("Illegal basic block operand reference");
   ParsedBasicBlocks.clear();
 
+  // Resolve forward references.  Replace any uses of a forward reference value
+  // with the real value.
+
+  // replaceAllUsesWith is very inefficient for instructions which have a LARGE
+  // number of operands.  PHI nodes often have forward references, and can also
+  // often have a very large number of operands.
+  std::map<Value*, Value*> ForwardRefMapping;
+  for (std::map<std::pair<unsigned,unsigned>, Value*>::iterator 
+         I = ForwardReferences.begin(), E = ForwardReferences.end();
+       I != E; ++I)
+    ForwardRefMapping[I->second] = getValue(I->first.first, I->first.second,
+                                            false);
+
+  for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
+    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+      for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
+        if (Argument *A = dyn_cast<Argument>(I->getOperand(i))) {
+          std::map<Value*, Value*>::iterator It = ForwardRefMapping.find(A);
+          if (It != ForwardRefMapping.end()) I->setOperand(i, It->second);
+        }
 
-  // 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...
-    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!





More information about the llvm-commits mailing list