"ghostify" the ilist<Function> sentinel
authorGabor Greif <ggreif@gmail.com>
Fri, 27 Mar 2009 22:28:33 +0000 (22:28 +0000)
committerGabor Greif <ggreif@gmail.com>
Fri, 27 Mar 2009 22:28:33 +0000 (22:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67872 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/VMCore/Module.cpp

index 9d0b2b62f27dc5bcdfb1c3cb2619387adfcf455f..9c8607a188a1360f8329591d5b74dc7f594b89eb 100644 (file)
@@ -28,9 +28,20 @@ class FunctionType;
 
 template<> struct ilist_traits<Function>
   : 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; }
+
+  // createSentinel is used to get hold of the node that marks the end of the
+  // list... (same trick used here as in ilist_traits<Instruction>)
+  Function *createSentinel() const {
+    return static_cast<Function*>(&Sentinel);
+  }
+  static void destroySentinel(Function*) {}
+
+  Function *provideInitialHead() const { return createSentinel(); }
+  Function *ensureHead(Function*) const { return createSentinel(); }
+  static void noteHead(Function*, Function*) {}
+
+private:
+  mutable ilist_node<Function> Sentinel;
 };
 template<> struct ilist_traits<GlobalVariable>
   : public SymbolTableListTraits<GlobalVariable, Module> {
index 25d297a03e31c8697127dbd7b65d074d8dff9f91..a598005e2a8946336fcd13efb190a10231d67dd8 100644 (file)
@@ -29,14 +29,6 @@ using namespace llvm;
 // Methods to implement the globals and functions lists.
 //
 
-Function *ilist_traits<Function>::createSentinel() {
-  FunctionType *FTy =
-    FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
-  Function *Ret = Function::Create(FTy, GlobalValue::ExternalLinkage);
-  // This should not be garbage monitored.
-  LeakDetector::removeGarbageObject(Ret);
-  return Ret;
-}
 GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
   GlobalVariable *Ret = new GlobalVariable(Type::Int32Ty, false,
                                            GlobalValue::ExternalLinkage);