diff options
| author | Gabor Greif <ggreif@gmail.com> | 2009-03-01 16:38:10 +0000 |
|---|---|---|
| committer | Gabor Greif <ggreif@gmail.com> | 2009-03-01 16:38:10 +0000 |
| commit | 6f8d4ae3c0c8566d0b0384e40f160cddd3c8bb2a (patch) | |
| tree | c1bcb1680c5c570378b7ea1d9af528e20bf102b5 | |
| parent | 491f9e89ae154fdf24fd2dc743d83397a2b89b04 (diff) | |
| download | bcm5719-llvm-6f8d4ae3c0c8566d0b0384e40f160cddd3c8bb2a.tar.gz bcm5719-llvm-6f8d4ae3c0c8566d0b0384e40f160cddd3c8bb2a.zip | |
Reuse a technique (pioneered for BasicBlocks) of superposing ilist with
its sentinel. This is quite a win when a function really has a basic block.
When the function is just a declaration (and stays so) the old way did not
allocate a sentinel. So this change is most beneficial when the ratio of
function definition to declaration is high. I.e. linkers etc. Incidentally
these are the most resource demanding applications, so I expect that the
reduced malloc traffic, locality and space savings outweigh the cost of
addition of two pointers to Function.
llvm-svn: 65776
| -rw-r--r-- | llvm/include/llvm/Function.h | 11 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Function.cpp | 7 |
2 files changed, 8 insertions, 10 deletions
diff --git a/llvm/include/llvm/Function.h b/llvm/include/llvm/Function.h index ee53252b954..bdae9cd02f5 100644 --- a/llvm/include/llvm/Function.h +++ b/llvm/include/llvm/Function.h @@ -32,12 +32,17 @@ class FunctionType; template<> struct ilist_traits<BasicBlock> : public SymbolTableListTraits<BasicBlock, Function> { - // createSentinel is used to create a node that marks the end of the list... - static BasicBlock *createSentinel(); - static void destroySentinel(BasicBlock *BB) { delete BB; } + // 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>) + BasicBlock *createSentinel() const { + return const_cast<BasicBlock*>(static_cast<const BasicBlock*>(&Sentinel)); + } + static void destroySentinel(BasicBlock*) {} static iplist<BasicBlock> &getList(Function *F); static ValueSymbolTable *getSymTab(Function *ItemParent); static int getListOffset(); +private: + ilist_node<BasicBlock> Sentinel; }; template<> struct ilist_traits<Argument> diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index cff4457a418..fefe082cb4e 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -22,13 +22,6 @@ #include "llvm/ADT/StringExtras.h" using namespace llvm; -BasicBlock *ilist_traits<BasicBlock>::createSentinel() { - BasicBlock *Ret = BasicBlock::Create(); - // This should not be garbage monitored. - LeakDetector::removeGarbageObject(Ret); - return Ret; -} - iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) { return F->getBasicBlockList(); } |

