From 0dd2a6a89f49438b239638ab147ac5746d6c32c3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 7 Mar 2009 12:33:24 +0000 Subject: [PATCH] simplify the way how traits get hold of the symbol table git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66336 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BasicBlock.h | 7 +++++-- include/llvm/Module.h | 19 ------------------- include/llvm/SymbolTableListTraits.h | 10 ++++++++-- lib/VMCore/BasicBlock.cpp | 8 +++----- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 0de71008e76..072f6152ea7 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -45,8 +45,6 @@ template<> struct ilist_traits Instruction *provideInitialHead() const { return createSentinel(); } Instruction *ensureHead(Instruction*) const { return createSentinel(); } static void noteHead(Instruction*, Instruction*) {} - - static ValueSymbolTable *getSymTab(BasicBlock *ItemParent); private: mutable ilist_node Sentinel; }; @@ -184,10 +182,15 @@ public: /// const InstListType &getInstList() const { return InstList; } InstListType &getInstList() { return InstList; } + + /// getSublistAccess() - returns pointer to member of instruction list static iplist BasicBlock::*getSublistAccess(Instruction*) { return &BasicBlock::InstList; } + /// getValueSymbolTable() - returns pointer to symbol table (if any) + ValueSymbolTable *getValueSymbolTable(); + /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const BasicBlock *) { return true; } static inline bool classof(const Value *V) { diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 2564ddc5da0..9d0b2b62f27 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -31,21 +31,18 @@ template<> struct ilist_traits // 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 inline ValueSymbolTable *getSymTab(Module *M); }; template<> struct ilist_traits : public SymbolTableListTraits { // 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 inline ValueSymbolTable *getSymTab(Module *M); }; template<> struct ilist_traits : public SymbolTableListTraits { // createSentinel is used to create a node that marks the end of the list. static GlobalAlias *createSentinel(); static void destroySentinel(GlobalAlias *GA) { delete GA; } - static inline ValueSymbolTable *getSymTab(Module *M); }; /// A Module instance is used to store all the information related to an @@ -409,22 +406,6 @@ inline raw_ostream &operator<<(raw_ostream &O, const Module &M) { M.print(O, 0); return O; } - - -inline ValueSymbolTable * -ilist_traits::getSymTab(Module *M) { - return M ? &M->getValueSymbolTable() : 0; -} - -inline ValueSymbolTable * -ilist_traits::getSymTab(Module *M) { - return M ? &M->getValueSymbolTable() : 0; -} - -inline ValueSymbolTable * -ilist_traits::getSymTab(Module *M) { - return M ? &M->getValueSymbolTable() : 0; -} } // End llvm namespace diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h index 44f64dc57f0..337b76f7668 100644 --- a/include/llvm/SymbolTableListTraits.h +++ b/include/llvm/SymbolTableListTraits.h @@ -55,8 +55,12 @@ public: } static iplist &getList(ItemParentClass *Par) { - return Par->*(Par->getSublistAccess((ValueSubClass*)0)); -} + return Par->*(Par->getSublistAccess((ValueSubClass*)0)); + } + + static ValueSymbolTable *getSymTab(ItemParentClass *Par) { + return Par ? toPtr(Par->getValueSymbolTable()) : 0; + } void addNodeToList(ValueSubClass *V); void removeNodeFromList(ValueSubClass *V); @@ -66,6 +70,8 @@ public: //private: template void setSymTabObject(TPtr *, TPtr); + static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; } + static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } }; } // End llvm namespace diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index f68223155dc..3065766362e 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -23,11 +23,9 @@ #include using namespace llvm; -inline ValueSymbolTable * -ilist_traits::getSymTab(BasicBlock *BB) { - if (BB) - if (Function *F = BB->getParent()) - return &F->getValueSymbolTable(); +ValueSymbolTable *BasicBlock::getValueSymbolTable() { + if (Function *F = getParent()) + return &F->getValueSymbolTable(); return 0; }