llvm.org GIT mirror llvm / 17fcdd5
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 Chris Lattner 13 years ago
13 changed file(s) with 140 addition(s) and 115 deletion(s). Raw diff Collapse all Expand all
1717
1818 namespace llvm {
1919
20 template struct ilist_traits;
21 template
22 typename SubClass> class SymbolTableListTraits;
20 template
21 class SymbolTableListTraits;
2322
2423 /// A class to represent an incoming formal argument to a Function. An argument
2524 /// is a very simple Value. It is essentially a named (optional) type. When used
3231 Argument *Prev, *Next; // Next and Prev links for our intrusive linked list
3332 void setNext(Argument *N) { Next = N; }
3433 void setPrev(Argument *N) { Prev = N; }
35 friend class SymbolTableListTraits
36 ilist_traits >;
34 friend class SymbolTableListTraits>;
3735 void setParent(Function *parent);
3836
3937 public:
2424 template class PredIterator;
2525
2626 template<> struct ilist_traits
27 : public SymbolTableListTraits, Function> {
27 : public SymbolTableListTraits> {
2828 // createSentinel is used to create a node that marks the end of the list...
2929 static Instruction *createSentinel();
3030 static void destroySentinel(Instruction *I) { delete I; }
3131 static iplist &getList(BasicBlock *BB);
32 static ValueSymbolTable *getSymTab(BasicBlock *ItemParent);
3233 };
3334
3435 /// This represents a single basic block in LLVM. A basic block is simply a
5152 private :
5253 InstListType InstList;
5354 BasicBlock *Prev, *Next; // Next and Prev links for our intrusive linked list
55 Function *Parent;
5456
5557 void setParent(Function *parent);
5658 void setNext(BasicBlock *N) { Next = N; }
5759 void setPrev(BasicBlock *N) { Prev = N; }
58 friend class SymbolTableListTraits, Function>;
60 friend class SymbolTableListTraits>;
5961
6062 BasicBlock(const BasicBlock &); // Do not implement
6163 void operator=(const BasicBlock &); // Do not implement
7577
7678 /// getParent - Return the enclosing method, or null if none
7779 ///
78 const Function *getParent() const { return InstList.getParent(); }
79 Function *getParent() { return InstList.getParent(); }
80 const Function *getParent() const { return Parent; }
81 Function *getParent() { return Parent; }
8082
8183 // getNext/Prev - Return the next or previous basic block in the list.
8284 BasicBlock *getNext() { return Next; }
2929
3030 // Traits for intrusive list of instructions...
3131 template<> struct ilist_traits
32 : public SymbolTableListTraits, Function> {
32 : public SymbolTableListTraits> {
3333
3434 // createSentinel is used to create a node that marks the end of the list...
3535 static BasicBlock *createSentinel();
3636 static void destroySentinel(BasicBlock *BB) { delete BB; }
3737 static iplist &getList(Function *F);
38 static ValueSymbolTable *getSymTab(Function *ItemParent);
3839 };
3940
4041 template<> struct ilist_traits
41 : public SymbolTableListTraits, Function> {
42 : public SymbolTableListTraits> {
4243
4344 // createSentinel is used to create a node that marks the end of the list...
4445 static Argument *createSentinel();
4546 static void destroySentinel(Argument *A) { delete A; }
4647 static iplist &getList(Function *F);
48 static ValueSymbolTable *getSymTab(Function *ItemParent);
4749 };
4850
4951 class Function : public GlobalValue, public Annotable {
6668 ParamAttrsList *ParamAttrs; ///< Parameter attributes
6769 unsigned CallingConvention; ///< Calling convention to use
6870
69 friend class SymbolTableListTraits, Module>;
71 friend class SymbolTableListTraits>;
7072
7173 void setParent(Module *parent);
7274 Function *Prev, *Next;
237239 void dropAllReferences();
238240 };
239241
242 inline ValueSymbolTable *
243 ilist_traits::getSymTab(Function *F) {
244 return F ? &F->getValueSymbolTable() : 0;
245 }
246
247 inline ValueSymbolTable *
248 ilist_traits::getSymTab(Function *F) {
249 return F ? &F->getValueSymbolTable() : 0;
250 }
251
240252 } // End llvm namespace
241253
242254 #endif
2626 class Module;
2727 class Constant;
2828 class PointerType;
29 template struct ilist_traits;
30 template
31 typename SubClass> class SymbolTableListTraits;
29 template
30 class SymbolTableListTraits;
3231
3332 class GlobalVariable : public GlobalValue {
34 friend class SymbolTableListTraits
35 ilist_traits >;
33 friend class SymbolTableListTraits>;
3634 void operator=(const GlobalVariable &); // Do not implement
3735 GlobalVariable(const GlobalVariable &); // Do not implement
3836
2121 struct AssemblyAnnotationWriter;
2222 class BinaryOperator;
2323
24 template struct ilist_traits;
25 template
26 typename SubClass> class SymbolTableListTraits;
24 template
25 class SymbolTableListTraits;
2726
2827 class Instruction : public User {
2928 void operator=(const Instruction &); // Do not implement
3534 void setNext(Instruction *N) { Next = N; }
3635 void setPrev(Instruction *N) { Prev = N; }
3736
38 friend class SymbolTableListTraits
39 ilist_traits >;
37 friend class SymbolTableListTraits>;
4038 void setParent(BasicBlock *P);
4139 protected:
4240 Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
2525 class FunctionType;
2626
2727 template<> struct ilist_traits
28 : public SymbolTableListTraits, Module> {
28 : public SymbolTableListTraits> {
2929 // createSentinel is used to create a node that marks the end of the list.
3030 static Function *createSentinel();
3131 static void destroySentinel(Function *F) { delete F; }
3232 static iplist &getList(Module *M);
33 static inline ValueSymbolTable *getSymTab(Module *M);
3334 };
3435 template<> struct ilist_traits
35 : public SymbolTableListTraits, Module> {
36 : public SymbolTableListTraits> {
3637 // createSentinel is used to create a node that marks the end of the list.
3738 static GlobalVariable *createSentinel();
3839 static void destroySentinel(GlobalVariable *GV) { delete GV; }
3940 static iplist &getList(Module *M);
41 static inline ValueSymbolTable *getSymTab(Module *M);
4042 };
4143
4244 /// A Module instance is used to store all the information related to an
318320 return O;
319321 }
320322
323 inline ValueSymbolTable *
324 ilist_traits::getSymTab(Module *M) {
325 return M ? &M->getValueSymbolTable() : 0;
326 }
327
328 inline ValueSymbolTable *
329 ilist_traits::getSymTab(Module *M) {
330 return M ? &M->getValueSymbolTable() : 0;
331 }
332
333
321334 } // End llvm namespace
322335
323336 #endif
3030 template class iplist;
3131 template struct ilist_traits;
3232
33 // ValueSubClass - The type of objects that I hold
34 // ItemParentType - I call setParent() on all of my "ValueSubclass" items, and
35 // this is the value that I pass in.
36 // SymTabType - This is the class type, whose symtab I insert my
37 // ValueSubClass items into. Most of the time it is
38 // ItemParentType, but Instructions have item parents of BB's
39 // but symtabtype's of a Function
33 // ValueSubClass - The type of objects that I hold, e.g. Instruction.
34 // ItemParentType - The type of object that owns the list, e.g. BasicBlock.
35 // TraitBaseClass - The class this trait should inherit from, it should
36 // inherit from ilist_traits
4037 //
41 template
42 typename SubClass=ilist_traits >
38 template>
4339 class SymbolTableListTraits {
44 SymTabClass *SymTabObject;
40 typedef ilist_traits TraitsClass;
4541 ItemParentClass *ItemParent;
4642 public:
47 SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {}
48
49 SymTabClass *getParent() { return SymTabObject; }
50 const SymTabClass *getParent() const { return SymTabObject; }
43 SymbolTableListTraits() : ItemParent(0) {}
5144
5245 static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }
5346 static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); }
6760 ilist_traits > &L2,
6861 ilist_iterator first,
6962 ilist_iterator last);
70
7163 //private:
72 void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private!
73 void setParent(SymTabClass *Parent); // This is private!
64 void setItemParent(ItemParentClass *IP) { ItemParent = IP; }
65 template
66 void setSymTabObject(TPtr *, TPtr);
7467 };
7568
7669 } // End llvm namespace
1717 #include "llvm/ADT/StringMap.h"
1818
1919 namespace llvm {
20 template
21 typename SymTabClass, typename SubClass>
20 templateClass>
2221 class SymbolTableListTraits;
23 template struct ilist_traits;
2422 class BasicBlock;
2523 class Function;
2624 class Module;
3129 ///
3230 class ValueSymbolTable {
3331 friend class Value;
34 friend class SymbolTableListTraits
35 ilist_traits >;
36 friend class SymbolTableListTraits
37 ilist_traits >;
38 friend class SymbolTableListTraits
39 ilist_traits >;
40 friend class SymbolTableListTraits
41 ilist_traits >;
42 friend class SymbolTableListTraits
43 ilist_traits >;
32 friend class SymbolTableListTraits>;
33 friend class SymbolTableListTraits;
34 friend class SymbolTableListTraits;
35 friend class SymbolTableListTraits;
36 friend class SymbolTableListTraits;
4437 /// @name Types
4538 /// @{
4639 public:
2121 #include
2222 using namespace llvm;
2323
24 inline ValueSymbolTable *
25 ilist_traits::getSymTab(BasicBlock *BB) {
26 if (BB)
27 if (Function *F = BB->getParent())
28 return &F->getValueSymbolTable();
29 return 0;
30 }
31
32
2433 namespace {
2534 /// DummyInst - An instance of this class is used to mark the end of the
2635 /// instruction list. This is not a real instruction.
5665
5766 // Explicit instantiation of SymbolTableListTraits since some of the methods
5867 // are not in the public header file...
59 template class SymbolTableListTraits;
60
61
62 BasicBlock::BasicBlock(const std::string &Name, Function *Parent,
68 template class SymbolTableListTraits;
69
70
71 BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
6372 BasicBlock *InsertBefore)
64 : Value(Type::LabelTy, Value::BasicBlockVal) {
65 // Initialize the instlist...
73 : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) {
74 // Initialize the instlist.
6675 InstList.setItemParent(this);
6776
6877 // Make sure that we get added to a function
6978 LeakDetector::addGarbageObject(this);
7079
7180 if (InsertBefore) {
72 assert(Parent &&
81 assert(NewParent &&
7382 "Cannot insert block before another block with no function!");
74 Parent->getBasicBlockList().insert(InsertBefore, this);
75 } else if (Parent) {
76 Parent->getBasicBlockList().push_back(this);
83 NewParent->getBasicBlockList().insert(InsertBefore, this);
84 } else if (NewParent) {
85 NewParent->getBasicBlockList().push_back(this);
7786 }
7887
7988 setName(Name);
9099 if (getParent())
91100 LeakDetector::addGarbageObject(this);
92101
93 InstList.setParent(parent);
102 // Set Parent=parent, updating instruction symtab entries as appropriate.
103 InstList.setSymTabObject(&Parent, parent);
94104
95105 if (getParent())
96106 LeakDetector::removeGarbageObject(this);
4343
4444 // Explicit instantiations of SymbolTableListTraits since some of the methods
4545 // are not in the public header file...
46 template class SymbolTableListTraits;
47 template class SymbolTableListTraits<BasicBlock, Function, Function>;
46 template class SymbolTableListTraits<Argument, Function>;
47 template class SymbolTableListTraits;
4848
4949 //===----------------------------------------------------------------------===//
5050 // Argument Implementation
143143 ParamAttrs = 0;
144144 CallingConvention = 0;
145145 BasicBlocks.setItemParent(this);
146 BasicBlocks.setParent(this);
147146 ArgumentList.setItemParent(this);
148 ArgumentList.setParent(this);
149147 SymTab = new ValueSymbolTable();
150148
151149 assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
170168
171169 // Delete all of the method arguments and unlink from symbol table...
172170 ArgumentList.clear();
173 ArgumentList.setParent(0);
174171 delete SymTab;
175172 }
176173
5454
5555 // Explicit instantiations of SymbolTableListTraits since some of the methods
5656 // are not in the public header file.
57 template class SymbolTableListTraits;
58 template class SymbolTableListTraits<Function, Module, Module>;
57 template class SymbolTableListTraits<GlobalVariable, Module>;
58 template class SymbolTableListTraits;
5959
6060 //===----------------------------------------------------------------------===//
6161 // Primitive Module methods.
6464 Module::Module(const std::string &MID)
6565 : ModuleID(MID), DataLayout("") {
6666 FunctionList.setItemParent(this);
67 FunctionList.setParent(this);
6867 GlobalList.setItemParent(this);
69 GlobalList.setParent(this);
7068 ValSymTab = new ValueSymbolTable();
7169 TypeSymTab = new TypeSymbolTable();
7270 }
7472 Module::~Module() {
7573 dropAllReferences();
7674 GlobalList.clear();
77 GlobalList.setParent(0);
7875 FunctionList.clear();
79 FunctionList.setParent(0);
8076 LibraryList.clear();
8177 delete ValSymTab;
8278 delete TypeSymTab;
2020
2121 namespace llvm {
2222
23 template
24 typename SubClass>
25 void SymbolTableListTraits
26 ::setParent(SymTabClass *STO) {
27 iplist &List = SubClass::getList(ItemParent);
23 /// setSymTabObject - This is called when (f.e.) the parent of a basic block
24 /// changes. This requires us to remove all the instruction symtab entries from
25 /// the current function and reinsert them into the new function.
26 template
27 template
28 void SymbolTableListTraits
29 ::setSymTabObject(TPtr *Dest, TPtr Src) {
30 // Get the old symtab and value list before doing the assignment.
31 ValueSymbolTable *OldST = TraitsClass::getSymTab(ItemParent);
2832
29 // Remove all of the items from the old symtab..
30 if (SymTabObject && !List.empty()) {
31 ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable();
32 for (typename iplist::iterator I = List.begin();
33 I != List.end(); ++I)
34 if (I->hasName()) SymTab.removeValueName(I->getValueName());
33 // Do it.
34 *Dest = Src;
35
36 // Get the new SymTab object.
37 ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent);
38
39 // If there is nothing to do, quick exit.
40 if (OldST == NewST) return;
41
42 // Move all the elements from the old symtab to the new one.
43 iplist &ItemList = TraitsClass::getList(ItemParent);
44 if (ItemList.empty()) return;
45
46 if (OldST) {
47 // Remove all entries from the previous symtab.
48 for (typename iplist::iterator I = ItemList.begin();
49 I != ItemList.end(); ++I)
50 if (I->hasName())
51 OldST->removeValueName(I->getValueName());
3552 }
3653
37 SymTabObject = STO;
38
39 // Add all of the items to the new symtab...
40 if (SymTabObject && !List.empty()) {
41 ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable();
42 for (typename iplist::iterator I = List.begin();
43 I != List.end(); ++I)
44 if (I->hasName()) SymTab.reinsertValue(I);
54 if (NewST) {
55 // Add all of the items to the new symtab.
56 for (typename iplist::iterator I = ItemList.begin();
57 I != ItemList.end(); ++I)
58 if (I->hasName())
59 NewST->reinsertValue(I);
4560 }
61
4662 }
4763
48 template
49 typename SubClass>
50 void SymbolTableListTraitsClass>
64 templateClass>
65 void SymbolTableListTraits
5166 ::addNodeToList(ValueSubClass *V) {
5267 assert(V->getParent() == 0 && "Value already in a container!!");
5368 V->setParent(ItemParent);
54 if (V->hasName() && SymTabObject)
55 SymTabObject->getValueSymbolTable().reinsertValue(V);
69 if (V->hasName())
70 if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent))
71 ST->reinsertValue(V);
5672 }
5773
58 template
59 typename SubClass>
60 void SymbolTableListTraitsClass>
74 templateClass>
75 void SymbolTableListTraits
6176 ::removeNodeFromList(ValueSubClass *V) {
6277 V->setParent(0);
63 if (V->hasName() && SymTabObject)
64 SymTabObject->getValueSymbolTable().removeValueName(V->getValueName());
78 if (V->hasName())
79 if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent))
80 ST->removeValueName(V->getValueName());
6581 }
6682
67 template
68 typename SubClass>
69 void SymbolTableListTraitsClass>
83 templateClass>
84 void SymbolTableListTraits
7085 ::transferNodesFromList(iplist > &L2,
7186 ilist_iterator first,
7287 ilist_iterator last) {
7691
7792 // We only have to update symbol table entries if we are transferring the
7893 // instructions to a different symtab object...
79 SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
80 if (NewSTO != OldSTO) {
94 ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent);
95 ValueSymbolTable *OldST = TraitsClass::getSymTab(OldIP);
96 if (NewST != OldST) {
8197 for (; first != last; ++first) {
8298 ValueSubClass &V = *first;
8399 bool HasName = V.hasName();
84 if (OldSTO && HasName)
85 OldSTO->getValueSymbolTable().removeValueName(V.getValueName());
100 if (OldST && HasName)
101 OldST->removeValueName(V.getValueName());
86102 V.setParent(NewIP);
87 if (NewSTO && HasName)
88 NewSTO->getValueSymbolTable().reinsertValue(&V);
103 if (NewST && HasName)
104 NewST->reinsertValue(&V);
89105 }
90106 } else {
91107 // Just transferring between blocks in the same function, simply update the
432432
433433 // Calculate whether or not this type is abstract
434434 setAbstract(isAbstract);
435
436435 }
437436
438437 StructType::StructType(const std::vector &Types, bool isPacked)