diff options
author | Chris Lattner <sabre@nondot.org> | 2007-04-17 03:26:42 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-04-17 03:26:42 +0000 |
commit | 17fcdd5e1b78b829068ca657c97357a39d6e768b (patch) | |
tree | db5c01cfda299d428837e2689e9aca31bf1bf556 /lib | |
parent | 205c27d4a904c12d1bfb0b2961daab70f286cc20 (diff) | |
download | external_llvm-17fcdd5e1b78b829068ca657c97357a39d6e768b.tar.gz external_llvm-17fcdd5e1b78b829068ca657c97357a39d6e768b.tar.bz2 external_llvm-17fcdd5e1b78b829068ca657c97357a39d6e768b.zip |
Refactor SymbolTableListTraits to only have a single pointer in it, instead
of two. This shrinkifies Function by 8 bytes (104->96) and Module by 8
bytes (68->60). On a testcase of mine, this reduces the memory used to
read a module header from 565680b to 561024, a little over 4K.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36188 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 28 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 7 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/SymbolTableListTraitsImpl.h | 92 | ||||
-rw-r--r-- | lib/VMCore/Type.cpp | 1 |
5 files changed, 77 insertions, 59 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 2e3b426e2b..e10948e2ad 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -22,6 +22,15 @@ #include <algorithm> using namespace llvm; +inline ValueSymbolTable * +ilist_traits<Instruction>::getSymTab(BasicBlock *BB) { + if (BB) + if (Function *F = BB->getParent()) + return &F->getValueSymbolTable(); + return 0; +} + + namespace { /// DummyInst - An instance of this class is used to mark the end of the /// instruction list. This is not a real instruction. @@ -57,24 +66,24 @@ iplist<Instruction> &ilist_traits<Instruction>::getList(BasicBlock *BB) { // Explicit instantiation of SymbolTableListTraits since some of the methods // are not in the public header file... -template class SymbolTableListTraits<Instruction, BasicBlock, Function>; +template class SymbolTableListTraits<Instruction, BasicBlock>; -BasicBlock::BasicBlock(const std::string &Name, Function *Parent, +BasicBlock::BasicBlock(const std::string &Name, Function *NewParent, BasicBlock *InsertBefore) - : Value(Type::LabelTy, Value::BasicBlockVal) { - // Initialize the instlist... + : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) { + // Initialize the instlist. InstList.setItemParent(this); // Make sure that we get added to a function LeakDetector::addGarbageObject(this); if (InsertBefore) { - assert(Parent && + assert(NewParent && "Cannot insert block before another block with no function!"); - Parent->getBasicBlockList().insert(InsertBefore, this); - } else if (Parent) { - Parent->getBasicBlockList().push_back(this); + NewParent->getBasicBlockList().insert(InsertBefore, this); + } else if (NewParent) { + NewParent->getBasicBlockList().push_back(this); } setName(Name); @@ -91,7 +100,8 @@ void BasicBlock::setParent(Function *parent) { if (getParent()) LeakDetector::addGarbageObject(this); - InstList.setParent(parent); + // Set Parent=parent, updating instruction symtab entries as appropriate. + InstList.setSymTabObject(&Parent, parent); if (getParent()) LeakDetector::removeGarbageObject(this); diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index edce58d6aa..7949e39f84 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -44,8 +44,8 @@ iplist<Argument> &ilist_traits<Argument>::getList(Function *F) { // Explicit instantiations of SymbolTableListTraits since some of the methods // are not in the public header file... -template class SymbolTableListTraits<Argument, Function, Function>; -template class SymbolTableListTraits<BasicBlock, Function, Function>; +template class SymbolTableListTraits<Argument, Function>; +template class SymbolTableListTraits<BasicBlock, Function>; //===----------------------------------------------------------------------===// // Argument Implementation @@ -144,9 +144,7 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage, ParamAttrs = 0; CallingConvention = 0; BasicBlocks.setItemParent(this); - BasicBlocks.setParent(this); ArgumentList.setItemParent(this); - ArgumentList.setParent(this); SymTab = new ValueSymbolTable(); assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy) @@ -171,7 +169,6 @@ Function::~Function() { // Delete all of the method arguments and unlink from symbol table... ArgumentList.clear(); - ArgumentList.setParent(0); delete SymTab; } diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 016ab16ff5..465cb69445 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -55,8 +55,8 @@ iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) { // Explicit instantiations of SymbolTableListTraits since some of the methods // are not in the public header file. -template class SymbolTableListTraits<GlobalVariable, Module, Module>; -template class SymbolTableListTraits<Function, Module, Module>; +template class SymbolTableListTraits<GlobalVariable, Module>; +template class SymbolTableListTraits<Function, Module>; //===----------------------------------------------------------------------===// // Primitive Module methods. @@ -65,9 +65,7 @@ template class SymbolTableListTraits<Function, Module, Module>; Module::Module(const std::string &MID) : ModuleID(MID), DataLayout("") { FunctionList.setItemParent(this); - FunctionList.setParent(this); GlobalList.setItemParent(this); - GlobalList.setParent(this); ValSymTab = new ValueSymbolTable(); TypeSymTab = new TypeSymbolTable(); } @@ -75,9 +73,7 @@ Module::Module(const std::string &MID) Module::~Module() { dropAllReferences(); GlobalList.clear(); - GlobalList.setParent(0); FunctionList.clear(); - FunctionList.setParent(0); LibraryList.clear(); delete ValSymTab; delete TypeSymTab; diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h index 9c3d2525cf..ce2c0c0cc7 100644 --- a/lib/VMCore/SymbolTableListTraitsImpl.h +++ b/lib/VMCore/SymbolTableListTraitsImpl.h @@ -21,53 +21,68 @@ namespace llvm { -template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass, - typename SubClass> -void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> -::setParent(SymTabClass *STO) { - iplist<ValueSubClass> &List = SubClass::getList(ItemParent); +/// setSymTabObject - This is called when (f.e.) the parent of a basic block +/// changes. This requires us to remove all the instruction symtab entries from +/// the current function and reinsert them into the new function. +template<typename ValueSubClass, typename ItemParentClass> +template<typename TPtr> +void SymbolTableListTraits<ValueSubClass,ItemParentClass> +::setSymTabObject(TPtr *Dest, TPtr Src) { + // Get the old symtab and value list before doing the assignment. + ValueSymbolTable *OldST = TraitsClass::getSymTab(ItemParent); - // Remove all of the items from the old symtab.. - if (SymTabObject && !List.empty()) { - ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable(); - for (typename iplist<ValueSubClass>::iterator I = List.begin(); - I != List.end(); ++I) - if (I->hasName()) SymTab.removeValueName(I->getValueName()); + // Do it. + *Dest = Src; + + // Get the new SymTab object. + ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent); + + // If there is nothing to do, quick exit. + if (OldST == NewST) return; + + // Move all the elements from the old symtab to the new one. + iplist<ValueSubClass> &ItemList = TraitsClass::getList(ItemParent); + if (ItemList.empty()) return; + + if (OldST) { + // Remove all entries from the previous symtab. + for (typename iplist<ValueSubClass>::iterator I = ItemList.begin(); + I != ItemList.end(); ++I) + if (I->hasName()) + OldST->removeValueName(I->getValueName()); } - SymTabObject = STO; - - // Add all of the items to the new symtab... - if (SymTabObject && !List.empty()) { - ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable(); - for (typename iplist<ValueSubClass>::iterator I = List.begin(); - I != List.end(); ++I) - if (I->hasName()) SymTab.reinsertValue(I); + if (NewST) { + // Add all of the items to the new symtab. + for (typename iplist<ValueSubClass>::iterator I = ItemList.begin(); + I != ItemList.end(); ++I) + if (I->hasName()) + NewST->reinsertValue(I); } + } -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> -void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +template<typename ValueSubClass, typename ItemParentClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass> ::addNodeToList(ValueSubClass *V) { assert(V->getParent() == 0 && "Value already in a container!!"); V->setParent(ItemParent); - if (V->hasName() && SymTabObject) - SymTabObject->getValueSymbolTable().reinsertValue(V); + if (V->hasName()) + if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent)) + ST->reinsertValue(V); } -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> -void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +template<typename ValueSubClass, typename ItemParentClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass> ::removeNodeFromList(ValueSubClass *V) { V->setParent(0); - if (V->hasName() && SymTabObject) - SymTabObject->getValueSymbolTable().removeValueName(V->getValueName()); + if (V->hasName()) + if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent)) + ST->removeValueName(V->getValueName()); } -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> -void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> +template<typename ValueSubClass, typename ItemParentClass> +void SymbolTableListTraits<ValueSubClass,ItemParentClass> ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2, ilist_iterator<ValueSubClass> first, ilist_iterator<ValueSubClass> last) { @@ -77,16 +92,17 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> // We only have to update symbol table entries if we are transferring the // instructions to a different symtab object... - SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject; - if (NewSTO != OldSTO) { + ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent); + ValueSymbolTable *OldST = TraitsClass::getSymTab(OldIP); + if (NewST != OldST) { for (; first != last; ++first) { ValueSubClass &V = *first; bool HasName = V.hasName(); - if (OldSTO && HasName) - OldSTO->getValueSymbolTable().removeValueName(V.getValueName()); + if (OldST && HasName) + OldST->removeValueName(V.getValueName()); V.setParent(NewIP); - if (NewSTO && HasName) - NewSTO->getValueSymbolTable().reinsertValue(&V); + if (NewST && HasName) + NewST->reinsertValue(&V); } } else { // Just transferring between blocks in the same function, simply update the diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 10063126e5..e4c89f182a 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -433,7 +433,6 @@ FunctionType::FunctionType(const Type *Result, // Calculate whether or not this type is abstract setAbstract(isAbstract); - } StructType::StructType(const std::vector<const Type*> &Types, bool isPacked) |