diff options
author | Chris Lattner <sabre@nondot.org> | 2005-10-04 16:52:46 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-10-04 16:52:46 +0000 |
commit | d7a3fc6819c40aab09db86dfae816d1c855335a1 (patch) | |
tree | 8ba11960b633febdc5f5db1d078388303fc5c422 | |
parent | 9d528dc2b4a936a9515b874b59a3c1b9b786b37b (diff) |
minor cleanup/fastpath for the bcreader. This speeds up the bcreader
from 1:41 -> 1:39 on the large python .bc file in a release build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23623 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/Constants.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 64ac4c1e29..5fb0a875d0 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -520,6 +520,9 @@ namespace { typedef std::map<MapKey, ConstantClass *> MapTy; typedef typename MapTy::iterator MapIterator; private: + /// Map - This is the main map from the element descriptor to the Constants. + /// This is the primary way we avoid creating two of the same shape + /// constant. MapTy Map; typedef std::map<const TypeClass*, MapIterator> AbstractTypeMapTy; @@ -548,6 +551,24 @@ namespace { Exists = !IP.second; return IP.first; } + + /// SimpleRemove - This method removes the specified constant from the map, + /// without updating type information. This should only be used when we're + /// changing an element in the map, making this the second half of a 'move' + /// operation. + void SimpleRemove(ConstantClass *CP) { + MapIterator I = Map.find(MapKey((TypeClass*)CP->getRawType(), + getValType(CP))); + if (I == Map.end() || I->second != CP) { + // FIXME: This should not use a linear scan. If this gets to be a + // performance problem, someone should look at this. + for (I = Map.begin(); I != Map.end() && I->second != CP; ++I) + /* empty */; + } + assert(I != Map.end() && "Constant not found in constant table!"); + assert(I->second == CP && "Didn't find correct element?"); + Map.erase(I); + } /// getOrCreate - Return the specified constant from the map, creating it if /// necessary. @@ -1383,7 +1404,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To, // in place! if (I != ArrayConstants.map_end() && I->second == this) ++I; // Do not invalidate iterator! - ArrayConstants.remove(this); // Remove old shape from the map. + ArrayConstants.SimpleRemove(this); // Remove old shape from the map. // Update to the new values. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) @@ -1445,7 +1466,7 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To, // in place! if (I != StructConstants.map_end() && I->second == this) ++I; // Do not invalidate iterator! - StructConstants.remove(this); // Remove old shape from the map. + StructConstants.SimpleRemove(this); // Remove old shape from the map. // Update to the new values. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) |