llvm.org GIT mirror llvm / f8dfef7
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36189 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
8 changed file(s) with 70 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3030 static void destroySentinel(Instruction *I) { delete I; }
3131 static iplist &getList(BasicBlock *BB);
3232 static ValueSymbolTable *getSymTab(BasicBlock *ItemParent);
33 static int getListOffset();
3334 };
3435
3536 /// This represents a single basic block in LLVM. A basic block is simply a
193194 /// the basic block).
194195 ///
195196 BasicBlock *splitBasicBlock(iterator I, const std::string &BBName = "");
197
198
199 static unsigned getInstListOffset() {
200 BasicBlock *Obj = 0;
201 return reinterpret_cast(&Obj->InstList);
202 }
196203 };
197204
205 inline int
206 ilist_traits::getListOffset() {
207 return BasicBlock::getInstListOffset();
208 }
209
198210 } // End llvm namespace
199211
200212 #endif
3636 static void destroySentinel(BasicBlock *BB) { delete BB; }
3737 static iplist &getList(Function *F);
3838 static ValueSymbolTable *getSymTab(Function *ItemParent);
39 static int getListOffset();
3940 };
4041
4142 template<> struct ilist_traits
4647 static void destroySentinel(Argument *A) { delete A; }
4748 static iplist &getList(Function *F);
4849 static ValueSymbolTable *getSymTab(Function *ItemParent);
50 static int getListOffset();
4951 };
5052
5153 class Function : public GlobalValue, public Annotable {
237239 /// including any contained basic blocks.
238240 ///
239241 void dropAllReferences();
242
243 static unsigned getBasicBlockListOffset() {
244 Function *Obj = 0;
245 return reinterpret_cast(&Obj->BasicBlocks);
246 }
247 static unsigned getArgumentListOffset() {
248 Function *Obj = 0;
249 return reinterpret_cast(&Obj->ArgumentList);
250 }
240251 };
241252
242253 inline ValueSymbolTable *
249260 return F ? &F->getValueSymbolTable() : 0;
250261 }
251262
263 inline int
264 ilist_traits::getListOffset() {
265 return Function::getBasicBlockListOffset();
266 }
267
268 inline int
269 ilist_traits::getListOffset() {
270 return Function::getArgumentListOffset();
271 }
272
273
252274 } // End llvm namespace
253275
254276 #endif
3131 static void destroySentinel(Function *F) { delete F; }
3232 static iplist &getList(Module *M);
3333 static inline ValueSymbolTable *getSymTab(Module *M);
34 static int getListOffset();
3435 };
3536 template<> struct ilist_traits
3637 : public SymbolTableListTraits {
3940 static void destroySentinel(GlobalVariable *GV) { delete GV; }
4041 static iplist &getList(Module *M);
4142 static inline ValueSymbolTable *getSymTab(Module *M);
43 static int getListOffset();
4244 };
4345
4446 /// A Module instance is used to store all the information related to an
312314 /// that has "dropped all references", except operator delete.
313315 void dropAllReferences();
314316 /// @}
317
318 static unsigned getFunctionListOffset() {
319 Module *Obj = 0;
320 return reinterpret_cast(&Obj->FunctionList);
321 }
322 static unsigned getGlobalVariableListOffset() {
323 Module *Obj = 0;
324 return reinterpret_cast(&Obj->GlobalList);
325 }
315326 };
316327
317328 /// An iostream inserter for modules.
330341 return M ? &M->getValueSymbolTable() : 0;
331342 }
332343
344 inline int
345 ilist_traits::getListOffset() {
346 return Module::getFunctionListOffset();
347 }
348
349 inline int
350 ilist_traits::getListOffset() {
351 return Module::getGlobalVariableListOffset();
352 }
333353
334354 } // End llvm namespace
335355
3838 template
3939 class SymbolTableListTraits {
4040 typedef ilist_traits TraitsClass;
41 ItemParentClass *ItemParent;
4241 public:
43 SymbolTableListTraits() : ItemParent(0) {}
42 SymbolTableListTraits() {}
4443
44 /// getListOwner - Return the object that owns this list. If this is a list
45 /// of instructions, it returns the BasicBlock that owns them.
46 ItemParentClass *getListOwner() {
47 return reinterpret_cast((char*)this-
48 TraitsClass::getListOffset());
49 }
4550 static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }
4651 static ValueSubClass *getNext(ValueSubClass *V) { return V->getNext(); }
4752 static const ValueSubClass *getPrev(const ValueSubClass *V) {
6166 ilist_iterator first,
6267 ilist_iterator last);
6368 //private:
64 void setItemParent(ItemParentClass *IP) { ItemParent = IP; }
6569 template
6670 void setSymTabObject(TPtr *, TPtr);
6771 };
7171 BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
7272 BasicBlock *InsertBefore)
7373 : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) {
74 // Initialize the instlist.
75 InstList.setItemParent(this);
7674
7775 // Make sure that we get added to a function
7876 LeakDetector::addGarbageObject(this);
142142 : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name) {
143143 ParamAttrs = 0;
144144 CallingConvention = 0;
145 BasicBlocks.setItemParent(this);
146 ArgumentList.setItemParent(this);
147145 SymTab = new ValueSymbolTable();
148146
149147 assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
6363
6464 Module::Module(const std::string &MID)
6565 : ModuleID(MID), DataLayout("") {
66 FunctionList.setItemParent(this);
67 GlobalList.setItemParent(this);
6866 ValSymTab = new ValueSymbolTable();
6967 TypeSymTab = new TypeSymbolTable();
7068 }
2828 void SymbolTableListTraits
2929 ::setSymTabObject(TPtr *Dest, TPtr Src) {
3030 // Get the old symtab and value list before doing the assignment.
31 ValueSymbolTable *OldST = TraitsClass::getSymTab(ItemParent);
31 ValueSymbolTable *OldST = TraitsClass::getSymTab(getListOwner());
3232
3333 // Do it.
3434 *Dest = Src;
3535
3636 // Get the new SymTab object.
37 ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent);
37 ValueSymbolTable *NewST = TraitsClass::getSymTab(getListOwner());
3838
3939 // If there is nothing to do, quick exit.
4040 if (OldST == NewST) return;
4141
4242 // Move all the elements from the old symtab to the new one.
43 iplist &ItemList = TraitsClass::getList(ItemParent);
43 iplist &ItemList = TraitsClass::getList(getListOwner());
4444 if (ItemList.empty()) return;
4545
4646 if (OldST) {
6565 void SymbolTableListTraits
6666 ::addNodeToList(ValueSubClass *V) {
6767 assert(V->getParent() == 0 && "Value already in a container!!");
68 V->setParent(ItemParent);
68 ItemParentClass *Owner = getListOwner();
69 V->setParent(Owner);
6970 if (V->hasName())
70 if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent))
71 if (ValueSymbolTable *ST = TraitsClass::getSymTab(Owner))
7172 ST->reinsertValue(V);
7273 }
7374
7677 ::removeNodeFromList(ValueSubClass *V) {
7778 V->setParent(0);
7879 if (V->hasName())
79 if (ValueSymbolTable *ST = TraitsClass::getSymTab(ItemParent))
80 if (ValueSymbolTable *ST = TraitsClass::getSymTab(getListOwner()))
8081 ST->removeValueName(V->getValueName());
8182 }
8283
8687 ilist_iterator first,
8788 ilist_iterator last) {
8889 // We only have to do work here if transferring instructions between BBs
89 ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
90 ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
9091 if (NewIP == OldIP) return; // No work to do at all...
9192
9293 // We only have to update symbol table entries if we are transferring the
9394 // instructions to a different symtab object...
94 ValueSymbolTable *NewST = TraitsClass::getSymTab(ItemParent);
95 ValueSymbolTable *NewST = TraitsClass::getSymTab(NewIP);
9596 ValueSymbolTable *OldST = TraitsClass::getSymTab(OldIP);
9697 if (NewST != OldST) {
9798 for (; first != last; ++first) {