Another sentinel optimization. This one should always
authorGabor Greif <ggreif@gmail.com>
Sun, 1 Mar 2009 17:13:15 +0000 (17:13 +0000)
committerGabor Greif <ggreif@gmail.com>
Sun, 1 Mar 2009 17:13:15 +0000 (17:13 +0000)
be a win, since almost every interesting function has at least one Argument.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65778 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bdae9cd02f5a32f9066b9f6fa02a066b2157cec2..9f4f23be08846d38f5de40a734591b8e8c7be800 100644 (file)
@@ -48,12 +48,15 @@ private:
 template<> struct ilist_traits<Argument>
   : public SymbolTableListTraits<Argument, Function> {
 
-  // createSentinel is used to create a node that marks the end of the list...
-  static Argument *createSentinel();
-  static void destroySentinel(Argument *A) { delete A; }
+  Argument *createSentinel() const {
+    return const_cast<Argument*>(static_cast<const Argument*>(&Sentinel));
+  }
+  static void destroySentinel(Argument*) {}
   static iplist<Argument> &getList(Function *F);
   static ValueSymbolTable *getSymTab(Function *ItemParent);
   static int getListOffset();
+private:
+  ilist_node<Argument> Sentinel;
 };
 
 class Function : public GlobalValue, public Annotable,
index fefe082cb4e44d2635bd37c20b8fad240526077a..258158f801ea437590d86a51f980044788230851 100644 (file)
@@ -26,13 +26,6 @@ iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) {
   return F->getBasicBlockList();
 }
 
-Argument *ilist_traits<Argument>::createSentinel() {
-  Argument *Ret = new Argument(Type::Int32Ty);
-  // This should not be garbage monitored.
-  LeakDetector::removeGarbageObject(Ret);
-  return Ret;
-}
-
 iplist<Argument> &ilist_traits<Argument>::getList(Function *F) {
   return F->getArgumentList();
 }