From 9225507cda6c634ded5054f44a75835a0c8cf62a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 17 Aug 2008 17:25:25 +0000 Subject: [PATCH] switch valuemap's from std::map to densemap. This speeds up llvm-dis on a stripped kc++ .bc file from 0.83 to 0.77s (8%) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54896 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/AsmWriter.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index cf29b5a1047..87d0da5b8ff 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -26,6 +26,7 @@ #include "llvm/Module.h" #include "llvm/ValueSymbolTable.h" #include "llvm/TypeSymbolTable.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CFG.h" @@ -46,7 +47,7 @@ AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {} class SlotMachine { public: /// ValueMap - A mapping of Values to slot numbers - typedef std::map ValueMap; + typedef DenseMap ValueMap; private: /// TheModule - The module for which we are holding slot numbers @@ -1605,7 +1606,7 @@ SlotMachine::SlotMachine(const Module *M) : TheModule(M) ///< Saved for lazy initialization. , TheFunction(0) , FunctionProcessed(false) - , mNext(0), fMap(), fNext(0) + , mNext(0), fNext(0) { } @@ -1615,7 +1616,7 @@ SlotMachine::SlotMachine(const Function *F) : TheModule(F ? F->getParent() : 0) ///< Saved for lazy initialization , TheFunction(F) ///< Saved for lazy initialization , FunctionProcessed(false) - , mNext(0), fMap(), fNext(0) + , mNext(0), fNext(0) { } @@ -1694,10 +1695,8 @@ int SlotMachine::getGlobalSlot(const GlobalValue *V) { initialize(); // Find the type plane in the module map - ValueMap::const_iterator MI = mMap.find(V); - if (MI == mMap.end()) return -1; - - return MI->second; + ValueMap::iterator MI = mMap.find(V); + return MI == mMap.end() ? -1 : MI->second; } @@ -1708,10 +1707,8 @@ int SlotMachine::getLocalSlot(const Value *V) { // Check for uninitialized state and do lazy initialization. initialize(); - ValueMap::const_iterator FI = fMap.find(V); - if (FI == fMap.end()) return -1; - - return FI->second; + ValueMap::iterator FI = fMap.find(V); + return FI == fMap.end() ? -1 : FI->second; }