[llvm-commits] CVS: llvm/include/llvm/BasicBlock.h Function.h Module.h SymbolTableListTraits.h

Chris Lattner sabre at nondot.org
Mon Apr 16 21:04:41 PDT 2007



Changes in directory llvm/include/llvm:

BasicBlock.h updated: 1.65 -> 1.66
Function.h updated: 1.76 -> 1.77
Module.h updated: 1.86 -> 1.87
SymbolTableListTraits.h updated: 1.6 -> 1.7
---
Log message:

The (negative) offset from a SymbolTableListTraits-using ilist to its container
object is always constant.  As such, evaluate it at compile time instead of storing
it as an ivar in SymbolTableListTraits.  This shrinks every SymbolTableListTraits
ilist by a word, shrinking BasicBlock from 44->40 bytes, Function from 96->88 bytes,
and Module from 60->52 bytes.


---
Diffs of the changes:  (+61 -3)

 BasicBlock.h            |   12 ++++++++++++
 Function.h              |   22 ++++++++++++++++++++++
 Module.h                |   20 ++++++++++++++++++++
 SymbolTableListTraits.h |   10 +++++++---
 4 files changed, 61 insertions(+), 3 deletions(-)


Index: llvm/include/llvm/BasicBlock.h
diff -u llvm/include/llvm/BasicBlock.h:1.65 llvm/include/llvm/BasicBlock.h:1.66
--- llvm/include/llvm/BasicBlock.h:1.65	Mon Apr 16 22:26:42 2007
+++ llvm/include/llvm/BasicBlock.h	Mon Apr 16 23:04:14 2007
@@ -31,6 +31,7 @@
   static void destroySentinel(Instruction *I) { delete I; }
   static iplist<Instruction> &getList(BasicBlock *BB);
   static ValueSymbolTable *getSymTab(BasicBlock *ItemParent);
+  static int getListOffset();
 };
 
 /// This represents a single basic block in LLVM. A basic block is simply a
@@ -194,8 +195,19 @@
   /// the basic block).
   ///
   BasicBlock *splitBasicBlock(iterator I, const std::string &BBName = "");
+  
+  
+  static unsigned getInstListOffset() {
+    BasicBlock *Obj = 0;
+    return reinterpret_cast<unsigned>(&Obj->InstList);
+  }
 };
 
+inline int 
+ilist_traits<Instruction>::getListOffset() {
+  return BasicBlock::getInstListOffset();
+}
+
 } // End llvm namespace
 
 #endif


Index: llvm/include/llvm/Function.h
diff -u llvm/include/llvm/Function.h:1.76 llvm/include/llvm/Function.h:1.77
--- llvm/include/llvm/Function.h:1.76	Mon Apr 16 22:26:42 2007
+++ llvm/include/llvm/Function.h	Mon Apr 16 23:04:14 2007
@@ -37,6 +37,7 @@
   static void destroySentinel(BasicBlock *BB) { delete BB; }
   static iplist<BasicBlock> &getList(Function *F);
   static ValueSymbolTable *getSymTab(Function *ItemParent);
+  static int getListOffset();
 };
 
 template<> struct ilist_traits<Argument>
@@ -47,6 +48,7 @@
   static void destroySentinel(Argument *A) { delete A; }
   static iplist<Argument> &getList(Function *F);
   static ValueSymbolTable *getSymTab(Function *ItemParent);
+  static int getListOffset();
 };
 
 class Function : public GlobalValue, public Annotable {
@@ -238,6 +240,15 @@
   /// including any contained basic blocks.
   ///
   void dropAllReferences();
+  
+  static unsigned getBasicBlockListOffset() {
+    Function *Obj = 0;
+    return reinterpret_cast<unsigned>(&Obj->BasicBlocks);
+  }
+  static unsigned getArgumentListOffset() {
+    Function *Obj = 0;
+    return reinterpret_cast<unsigned>(&Obj->ArgumentList);
+  }
 };
 
 inline ValueSymbolTable *
@@ -250,6 +261,17 @@
   return F ? &F->getValueSymbolTable() : 0;
 }
 
+inline int 
+ilist_traits<BasicBlock>::getListOffset() {
+  return Function::getBasicBlockListOffset();
+}
+
+inline int 
+ilist_traits<Argument>::getListOffset() {
+  return Function::getArgumentListOffset();
+}
+
+
 } // End llvm namespace
 
 #endif


Index: llvm/include/llvm/Module.h
diff -u llvm/include/llvm/Module.h:1.86 llvm/include/llvm/Module.h:1.87
--- llvm/include/llvm/Module.h:1.86	Mon Apr 16 22:26:42 2007
+++ llvm/include/llvm/Module.h	Mon Apr 16 23:04:14 2007
@@ -32,6 +32,7 @@
   static void destroySentinel(Function *F) { delete F; }
   static iplist<Function> &getList(Module *M);
   static inline ValueSymbolTable *getSymTab(Module *M);
+  static int getListOffset();
 };
 template<> struct ilist_traits<GlobalVariable>
   : public SymbolTableListTraits<GlobalVariable, Module> {
@@ -40,6 +41,7 @@
   static void destroySentinel(GlobalVariable *GV) { delete GV; }
   static iplist<GlobalVariable> &getList(Module *M);
   static inline ValueSymbolTable *getSymTab(Module *M);
+  static int getListOffset();
 };
 
 /// A Module instance is used to store all the information related to an
@@ -313,6 +315,15 @@
   /// that has "dropped all references", except operator delete.
   void dropAllReferences();
 /// @}
+
+  static unsigned getFunctionListOffset() {
+    Module *Obj = 0;
+    return reinterpret_cast<unsigned>(&Obj->FunctionList);
+  }
+  static unsigned getGlobalVariableListOffset() {
+    Module *Obj = 0;
+    return reinterpret_cast<unsigned>(&Obj->GlobalList);
+  }
 };
 
 /// An iostream inserter for modules.
@@ -331,6 +342,15 @@
   return M ? &M->getValueSymbolTable() : 0;
 }
 
+inline int 
+ilist_traits<Function>::getListOffset() {
+  return Module::getFunctionListOffset();
+}
+
+inline int 
+ilist_traits<GlobalVariable>::getListOffset() {
+  return Module::getGlobalVariableListOffset();
+}
 
 } // End llvm namespace
 


Index: llvm/include/llvm/SymbolTableListTraits.h
diff -u llvm/include/llvm/SymbolTableListTraits.h:1.6 llvm/include/llvm/SymbolTableListTraits.h:1.7
--- llvm/include/llvm/SymbolTableListTraits.h:1.6	Mon Apr 16 22:26:42 2007
+++ llvm/include/llvm/SymbolTableListTraits.h	Mon Apr 16 23:04:14 2007
@@ -39,10 +39,15 @@
 template<typename ValueSubClass, typename ItemParentClass>
 class SymbolTableListTraits {
   typedef ilist_traits<ValueSubClass> TraitsClass;
-  ItemParentClass *ItemParent;
 public:
-  SymbolTableListTraits() : ItemParent(0) {}
+  SymbolTableListTraits() {}
 
+  /// getListOwner - Return the object that owns this list.  If this is a list
+  /// of instructions, it returns the BasicBlock that owns them.
+  ItemParentClass *getListOwner() {
+    return reinterpret_cast<ItemParentClass*>((char*)this-
+                                              TraitsClass::getListOffset());
+  }
   static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }
   static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); }
   static const ValueSubClass *getPrev(const ValueSubClass *V) {
@@ -62,7 +67,6 @@
                              ilist_iterator<ValueSubClass> first,
                              ilist_iterator<ValueSubClass> last);
 //private:
-  void setItemParent(ItemParentClass *IP) { ItemParent = IP; }
   template<typename TPtr>
   void setSymTabObject(TPtr *, TPtr);
 };






More information about the llvm-commits mailing list