Changes in directory llvm/include/llvm:
Argument.h updated: 1.15 -> 1.16 BasicBlock.h updated: 1.64 -> 1.65 Function.h updated: 1.75 -> 1.76 GlobalVariable.h updated: 1.41 -> 1.42 Instruction.h updated: 1.83 -> 1.84 Module.h updated: 1.85 -> 1.86 SymbolTableListTraits.h updated: 1.5 -> 1.6 ValueSymbolTable.h updated: 1.11 -> 1.12 --- 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: (+61 -54) Argument.h | 8 +++----- BasicBlock.h | 10 ++++++---- Function.h | 18 +++++++++++++++--- GlobalVariable.h | 8 +++----- Instruction.h | 8 +++----- Module.h | 17 +++++++++++++++-- SymbolTableListTraits.h | 27 ++++++++++----------------- ValueSymbolTable.h | 19 ++++++------------- 8 files changed, 61 insertions(+), 54 deletions(-) Index: llvm/include/llvm/Argument.h diff -u llvm/include/llvm/Argument.h:1.15 llvm/include/llvm/Argument.h:1.16 --- llvm/include/llvm/Argument.h:1.15 Fri Apr 13 13:12:09 2007 +++ llvm/include/llvm/Argument.h Mon Apr 16 22:26:42 2007 @@ -18,9 +18,8 @@ namespace llvm { -template<typename SC> struct ilist_traits; -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> class SymbolTableListTraits; +template<typename ValueSubClass, typename ItemParentClass> + class SymbolTableListTraits; /// A class to represent an incoming formal argument to a Function. An argument /// is a very simple Value. It is essentially a named (optional) type. When used @@ -33,8 +32,7 @@ Argument *Prev, *Next; // Next and Prev links for our intrusive linked list void setNext(Argument *N) { Next = N; } void setPrev(Argument *N) { Prev = N; } - friend class SymbolTableListTraits<Argument, Function, Function, - ilist_traits<Argument> >; + friend class SymbolTableListTraits<Argument, Function>; void setParent(Function *parent); public: Index: llvm/include/llvm/BasicBlock.h diff -u llvm/include/llvm/BasicBlock.h:1.64 llvm/include/llvm/BasicBlock.h:1.65 --- llvm/include/llvm/BasicBlock.h:1.64 Fri Apr 13 13:12:09 2007 +++ llvm/include/llvm/BasicBlock.h Mon Apr 16 22:26:42 2007 @@ -25,11 +25,12 @@ template <class Ptr, class USE_iterator> class PredIterator; template<> struct ilist_traits<Instruction> - : public SymbolTableListTraits<Instruction, BasicBlock, Function> { + : public SymbolTableListTraits<Instruction, BasicBlock> { // createSentinel is used to create a node that marks the end of the list... static Instruction *createSentinel(); static void destroySentinel(Instruction *I) { delete I; } static iplist<Instruction> &getList(BasicBlock *BB); + static ValueSymbolTable *getSymTab(BasicBlock *ItemParent); }; /// This represents a single basic block in LLVM. A basic block is simply a @@ -52,11 +53,12 @@ private : InstListType InstList; BasicBlock *Prev, *Next; // Next and Prev links for our intrusive linked list + Function *Parent; void setParent(Function *parent); void setNext(BasicBlock *N) { Next = N; } void setPrev(BasicBlock *N) { Prev = N; } - friend class SymbolTableListTraits<BasicBlock, Function, Function>; + friend class SymbolTableListTraits<BasicBlock, Function>; BasicBlock(const BasicBlock &); // Do not implement void operator=(const BasicBlock &); // Do not implement @@ -76,8 +78,8 @@ /// getParent - Return the enclosing method, or null if none /// - const Function *getParent() const { return InstList.getParent(); } - Function *getParent() { return InstList.getParent(); } + const Function *getParent() const { return Parent; } + Function *getParent() { return Parent; } // getNext/Prev - Return the next or previous basic block in the list. BasicBlock *getNext() { return Next; } Index: llvm/include/llvm/Function.h diff -u llvm/include/llvm/Function.h:1.75 llvm/include/llvm/Function.h:1.76 --- llvm/include/llvm/Function.h:1.75 Mon Apr 16 01:54:34 2007 +++ llvm/include/llvm/Function.h Mon Apr 16 22:26:42 2007 @@ -30,21 +30,23 @@ // Traits for intrusive list of instructions... template<> struct ilist_traits<BasicBlock> - : public SymbolTableListTraits<BasicBlock, Function, Function> { + : public SymbolTableListTraits<BasicBlock, Function> { // createSentinel is used to create a node that marks the end of the list... static BasicBlock *createSentinel(); static void destroySentinel(BasicBlock *BB) { delete BB; } static iplist<BasicBlock> &getList(Function *F); + static ValueSymbolTable *getSymTab(Function *ItemParent); }; template<> struct ilist_traits<Argument> - : public SymbolTableListTraits<Argument, Function, Function> { + : public SymbolTableListTraits<Argument, Function> { // createSentinel is used to create a node that marks the end of the list... static Argument *createSentinel(); static void destroySentinel(Argument *A) { delete A; } static iplist<Argument> &getList(Function *F); + static ValueSymbolTable *getSymTab(Function *ItemParent); }; class Function : public GlobalValue, public Annotable { @@ -67,7 +69,7 @@ ParamAttrsList *ParamAttrs; ///< Parameter attributes unsigned CallingConvention; ///< Calling convention to use - friend class SymbolTableListTraits<Function, Module, Module>; + friend class SymbolTableListTraits<Function, Module>; void setParent(Module *parent); Function *Prev, *Next; @@ -238,6 +240,16 @@ void dropAllReferences(); }; +inline ValueSymbolTable * +ilist_traits<BasicBlock>::getSymTab(Function *F) { + return F ? &F->getValueSymbolTable() : 0; +} + +inline ValueSymbolTable * +ilist_traits<Argument>::getSymTab(Function *F) { + return F ? &F->getValueSymbolTable() : 0; +} + } // End llvm namespace #endif Index: llvm/include/llvm/GlobalVariable.h diff -u llvm/include/llvm/GlobalVariable.h:1.41 llvm/include/llvm/GlobalVariable.h:1.42 --- llvm/include/llvm/GlobalVariable.h:1.41 Fri Apr 13 13:12:09 2007 +++ llvm/include/llvm/GlobalVariable.h Mon Apr 16 22:26:42 2007 @@ -27,13 +27,11 @@ class Module; class Constant; class PointerType; -template<typename SC> struct ilist_traits; -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> class SymbolTableListTraits; +template<typename ValueSubClass, typename ItemParentClass> + class SymbolTableListTraits; class GlobalVariable : public GlobalValue { - friend class SymbolTableListTraits<GlobalVariable, Module, Module, - ilist_traits<GlobalVariable> >; + friend class SymbolTableListTraits<GlobalVariable, Module>; void operator=(const GlobalVariable &); // Do not implement GlobalVariable(const GlobalVariable &); // Do not implement Index: llvm/include/llvm/Instruction.h diff -u llvm/include/llvm/Instruction.h:1.83 llvm/include/llvm/Instruction.h:1.84 --- llvm/include/llvm/Instruction.h:1.83 Fri Apr 13 13:12:09 2007 +++ llvm/include/llvm/Instruction.h Mon Apr 16 22:26:42 2007 @@ -22,9 +22,8 @@ struct AssemblyAnnotationWriter; class BinaryOperator; -template<typename SC> struct ilist_traits; -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass> class SymbolTableListTraits; +template<typename ValueSubClass, typename ItemParentClass> + class SymbolTableListTraits; class Instruction : public User { void operator=(const Instruction &); // Do not implement @@ -36,8 +35,7 @@ void setNext(Instruction *N) { Next = N; } void setPrev(Instruction *N) { Prev = N; } - friend class SymbolTableListTraits<Instruction, BasicBlock, Function, - ilist_traits<Instruction> >; + friend class SymbolTableListTraits<Instruction, BasicBlock>; void setParent(BasicBlock *P); protected: Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, Index: llvm/include/llvm/Module.h diff -u llvm/include/llvm/Module.h:1.85 llvm/include/llvm/Module.h:1.86 --- llvm/include/llvm/Module.h:1.85 Fri Mar 23 13:44:11 2007 +++ llvm/include/llvm/Module.h Mon Apr 16 22:26:42 2007 @@ -26,18 +26,20 @@ class FunctionType; template<> struct ilist_traits<Function> - : public SymbolTableListTraits<Function, Module, Module> { + : public SymbolTableListTraits<Function, Module> { // createSentinel is used to create a node that marks the end of the list. static Function *createSentinel(); static void destroySentinel(Function *F) { delete F; } static iplist<Function> &getList(Module *M); + static inline ValueSymbolTable *getSymTab(Module *M); }; template<> struct ilist_traits<GlobalVariable> - : public SymbolTableListTraits<GlobalVariable, Module, Module> { + : public SymbolTableListTraits<GlobalVariable, Module> { // createSentinel is used to create a node that marks the end of the list. static GlobalVariable *createSentinel(); static void destroySentinel(GlobalVariable *GV) { delete GV; } static iplist<GlobalVariable> &getList(Module *M); + static inline ValueSymbolTable *getSymTab(Module *M); }; /// A Module instance is used to store all the information related to an @@ -319,6 +321,17 @@ return O; } +inline ValueSymbolTable * +ilist_traits<Function>::getSymTab(Module *M) { + return M ? &M->getValueSymbolTable() : 0; +} + +inline ValueSymbolTable * +ilist_traits<GlobalVariable>::getSymTab(Module *M) { + return M ? &M->getValueSymbolTable() : 0; +} + + } // End llvm namespace #endif Index: llvm/include/llvm/SymbolTableListTraits.h diff -u llvm/include/llvm/SymbolTableListTraits.h:1.5 llvm/include/llvm/SymbolTableListTraits.h:1.6 --- llvm/include/llvm/SymbolTableListTraits.h:1.5 Thu Apr 21 15:11:51 2005 +++ llvm/include/llvm/SymbolTableListTraits.h Mon Apr 16 22:26:42 2007 @@ -31,24 +31,17 @@ template<typename NodeTy, typename Traits> class iplist; template<typename Ty> struct ilist_traits; -// ValueSubClass - The type of objects that I hold -// ItemParentType - I call setParent() on all of my "ValueSubclass" items, and -// this is the value that I pass in. -// SymTabType - This is the class type, whose symtab I insert my -// ValueSubClass items into. Most of the time it is -// ItemParentType, but Instructions have item parents of BB's -// but symtabtype's of a Function +// ValueSubClass - The type of objects that I hold, e.g. Instruction. +// ItemParentType - The type of object that owns the list, e.g. BasicBlock. +// TraitBaseClass - The class this trait should inherit from, it should +// inherit from ilist_traits<ValueSubClass> // -template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, - typename SubClass=ilist_traits<ValueSubClass> > +template<typename ValueSubClass, typename ItemParentClass> class SymbolTableListTraits { - SymTabClass *SymTabObject; + typedef ilist_traits<ValueSubClass> TraitsClass; ItemParentClass *ItemParent; public: - SymbolTableListTraits() : SymTabObject(0), ItemParent(0) {} - - SymTabClass *getParent() { return SymTabObject; } - const SymTabClass *getParent() const { return SymTabObject; } + SymbolTableListTraits() : ItemParent(0) {} static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); } static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); } @@ -68,10 +61,10 @@ ilist_traits<ValueSubClass> > &L2, ilist_iterator<ValueSubClass> first, ilist_iterator<ValueSubClass> last); - //private: - void setItemParent(ItemParentClass *IP) { ItemParent = IP; }//This is private! - void setParent(SymTabClass *Parent); // This is private! + void setItemParent(ItemParentClass *IP) { ItemParent = IP; } + template<typename TPtr> + void setSymTabObject(TPtr *, TPtr); }; } // End llvm namespace Index: llvm/include/llvm/ValueSymbolTable.h diff -u llvm/include/llvm/ValueSymbolTable.h:1.11 llvm/include/llvm/ValueSymbolTable.h:1.12 --- llvm/include/llvm/ValueSymbolTable.h:1.11 Mon Apr 16 21:04:39 2007 +++ llvm/include/llvm/ValueSymbolTable.h Mon Apr 16 22:26:42 2007 @@ -18,10 +18,8 @@ #include "llvm/ADT/StringMap.h" namespace llvm { - template<typename ValueSubClass, typename ItemParentClass, - typename SymTabClass, typename SubClass> + template<typename ValueSubClass, typename ItemParentClass> class SymbolTableListTraits; - template<typename NodeTy> struct ilist_traits; class BasicBlock; class Function; class Module; @@ -32,16 +30,11 @@ /// class ValueSymbolTable { friend class Value; - friend class SymbolTableListTraits<Argument, Function, Function, - ilist_traits<Argument> >; - friend class SymbolTableListTraits<BasicBlock, Function, Function, - ilist_traits<BasicBlock> >; - friend class SymbolTableListTraits<Instruction, BasicBlock, Function, - ilist_traits<Instruction> >; - friend class SymbolTableListTraits<Function, Module, Module, - ilist_traits<Function> >; - friend class SymbolTableListTraits<GlobalVariable, Module, Module, - ilist_traits<GlobalVariable> >; + friend class SymbolTableListTraits<Argument, Function>; + friend class SymbolTableListTraits<BasicBlock, Function>; + friend class SymbolTableListTraits<Instruction, BasicBlock>; + friend class SymbolTableListTraits<Function, Module>; + friend class SymbolTableListTraits<GlobalVariable, Module>; /// @name Types /// @{ public: _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits