[llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Function.cpp Module.cpp SymbolTableListTraitsImpl.h Type.cpp
Chris Lattner
sabre at nondot.org
Mon Apr 16 20:27:13 PDT 2007
Changes in directory llvm/lib/VMCore:
BasicBlock.cpp updated: 1.75 -> 1.76
Function.cpp updated: 1.121 -> 1.122
Module.cpp updated: 1.78 -> 1.79
SymbolTableListTraitsImpl.h updated: 1.10 -> 1.11
Type.cpp updated: 1.182 -> 1.183
---
Log message:
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.
---
Diffs of the changes: (+78 -60)
BasicBlock.cpp | 28 ++++++++-----
Function.cpp | 7 ---
Module.cpp | 8 ---
SymbolTableListTraitsImpl.h | 94 +++++++++++++++++++++++++-------------------
Type.cpp | 1
5 files changed, 78 insertions(+), 60 deletions(-)
Index: llvm/lib/VMCore/BasicBlock.cpp
diff -u llvm/lib/VMCore/BasicBlock.cpp:1.75 llvm/lib/VMCore/BasicBlock.cpp:1.76
--- llvm/lib/VMCore/BasicBlock.cpp:1.75 Sun Feb 11 23:18:08 2007
+++ llvm/lib/VMCore/BasicBlock.cpp Mon Apr 16 22:26:42 2007
@@ -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 @@
// 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 @@
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);
Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.121 llvm/lib/VMCore/Function.cpp:1.122
--- llvm/lib/VMCore/Function.cpp:1.121 Mon Apr 16 11:56:54 2007
+++ llvm/lib/VMCore/Function.cpp Mon Apr 16 22:26:42 2007
@@ -44,8 +44,8 @@
// 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 @@
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 @@
// Delete all of the method arguments and unlink from symbol table...
ArgumentList.clear();
- ArgumentList.setParent(0);
delete SymTab;
}
Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.78 llvm/lib/VMCore/Module.cpp:1.79
--- llvm/lib/VMCore/Module.cpp:1.78 Mon Apr 9 01:12:07 2007
+++ llvm/lib/VMCore/Module.cpp Mon Apr 16 22:26:42 2007
@@ -55,8 +55,8 @@
// 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 @@
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() {
dropAllReferences();
GlobalList.clear();
- GlobalList.setParent(0);
FunctionList.clear();
- FunctionList.setParent(0);
LibraryList.clear();
delete ValSymTab;
delete TypeSymTab;
Index: llvm/lib/VMCore/SymbolTableListTraitsImpl.h
diff -u llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.10 llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.11
--- llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.10 Sun Feb 11 23:18:08 2007
+++ llvm/lib/VMCore/SymbolTableListTraitsImpl.h Mon Apr 16 22:26:42 2007
@@ -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);
-
- // 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());
+/// 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);
+
+ // 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 @@
// 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
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.182 llvm/lib/VMCore/Type.cpp:1.183
--- llvm/lib/VMCore/Type.cpp:1.182 Tue Apr 10 21:44:19 2007
+++ llvm/lib/VMCore/Type.cpp Mon Apr 16 22:26:42 2007
@@ -433,7 +433,6 @@
// Calculate whether or not this type is abstract
setAbstract(isAbstract);
-
}
StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
More information about the llvm-commits
mailing list