diff options
-rw-r--r-- | include/llvm/Module.h | 26 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 19 |
2 files changed, 23 insertions, 22 deletions
diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 7eb34b6896..8ce5ec4f1d 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -50,17 +50,35 @@ template<> struct ilist_traits<Function> private: mutable ilist_node<Function> Sentinel; }; + template<> struct ilist_traits<GlobalVariable> : 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; } + GlobalVariable *createSentinel() const { + return static_cast<GlobalVariable*>(&Sentinel); + } + static void destroySentinel(GlobalVariable*) {} + + GlobalVariable *provideInitialHead() const { return createSentinel(); } + GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); } + static void noteHead(GlobalVariable*, GlobalVariable*) {} +private: + mutable ilist_node<GlobalVariable> Sentinel; }; + template<> struct ilist_traits<GlobalAlias> : public SymbolTableListTraits<GlobalAlias, Module> { // createSentinel is used to create a node that marks the end of the list. - static GlobalAlias *createSentinel(); - static void destroySentinel(GlobalAlias *GA) { delete GA; } + GlobalAlias *createSentinel() const { + return static_cast<GlobalAlias*>(&Sentinel); + } + static void destroySentinel(GlobalAlias*) {} + + GlobalAlias *provideInitialHead() const { return createSentinel(); } + GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); } + static void noteHead(GlobalAlias*, GlobalAlias*) {} +private: + mutable ilist_node<GlobalAlias> Sentinel; }; template<> struct ilist_traits<NamedMDNode> diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index ee63d696d5..c29029bf6c 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -32,25 +32,10 @@ using namespace llvm; // Methods to implement the globals and functions lists. // -GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() { - GlobalVariable *Ret = new GlobalVariable(Type::getInt32Ty(getGlobalContext()), - false, GlobalValue::ExternalLinkage); - // This should not be garbage monitored. - LeakDetector::removeGarbageObject(Ret); - return Ret; -} -GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() { - GlobalAlias *Ret = new GlobalAlias(Type::getInt32Ty(getGlobalContext()), - GlobalValue::ExternalLinkage); - // This should not be garbage monitored. - LeakDetector::removeGarbageObject(Ret); - return Ret; -} - // Explicit instantiations of SymbolTableListTraits since some of the methods // are not in the public header file. -template class llvm::SymbolTableListTraits<GlobalVariable, Module>; template class llvm::SymbolTableListTraits<Function, Module>; +template class llvm::SymbolTableListTraits<GlobalVariable, Module>; template class llvm::SymbolTableListTraits<GlobalAlias, Module>; //===----------------------------------------------------------------------===// @@ -552,5 +537,3 @@ namespace { void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes) const { TypeFinder(StructTypes).run(*this); } - - |