diff options
author | Gabor Greif <ggreif@gmail.com> | 2009-03-04 20:36:44 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2009-03-04 20:36:44 +0000 |
commit | c23b8719ef9d6b1220e854b37d40e9e1c48a82bc (patch) | |
tree | afd0f1a6f924ba5609ce8f6212078b7407895840 /include/llvm | |
parent | 076aee32e86bc4a0c096262b3261923f25220dc6 (diff) | |
download | external_llvm-c23b8719ef9d6b1220e854b37d40e9e1c48a82bc.zip external_llvm-c23b8719ef9d6b1220e854b37d40e9e1c48a82bc.tar.gz external_llvm-c23b8719ef9d6b1220e854b37d40e9e1c48a82bc.tar.bz2 |
Give sentinel traits the right to determine the policy where the sentinel is kept.
This should result in less indirect memory accesses, less dead writes and tighter code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/ADT/ilist.h | 45 | ||||
-rw-r--r-- | include/llvm/BasicBlock.h | 4 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineBasicBlock.h | 3 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineFunction.h | 13 | ||||
-rw-r--r-- | include/llvm/CodeGen/SelectionDAG.h | 6 | ||||
-rw-r--r-- | include/llvm/Function.h | 8 | ||||
-rw-r--r-- | include/llvm/Support/Recycler.h | 3 |
7 files changed, 71 insertions, 11 deletions
diff --git a/include/llvm/ADT/ilist.h b/include/llvm/ADT/ilist.h index ee7d199..51442e3 100644 --- a/include/llvm/ADT/ilist.h +++ b/include/llvm/ADT/ilist.h @@ -60,13 +60,45 @@ struct ilist_nextprev_traits { static void setNext(NodeTy *N, NodeTy *Next) { N->setNext(Next); } }; +template<typename NodeTy> +struct ilist_traits; + /// ilist_sentinel_traits - A fragment for template traits for intrusive list /// that provides default sentinel implementations for common operations. /// +/// ilist_sentinel_traits implements a lazy dynamic sentinel allocation +/// strategy. The sentinel is stored in the prev field of ilist's Head. +/// template<typename NodeTy> struct ilist_sentinel_traits { + /// createSentinel - create the dynamic sentinel static NodeTy *createSentinel() { return new NodeTy(); } + + /// destroySentinel - deallocate the dynamic sentinel static void destroySentinel(NodeTy *N) { delete N; } + + /// provideInitialHead - when constructing an ilist, provide a starting + /// value for its Head + /// @return null node to indicate that it needs to be allocated later + static NodeTy *provideInitialHead() { return 0; } + + /// ensureHead - make sure that Head is either already + /// initialized or assigned a fresh sentinel + /// @return the sentinel + static NodeTy *ensureHead(NodeTy *&Head) { + if (!Head) { + Head = ilist_traits<NodeTy>::createSentinel(); + ilist_traits<NodeTy>::noteHead(Head, Head); + ilist_traits<NodeTy>::setNext(Head, 0); + return Head; + } + return ilist_traits<NodeTy>::getPrev(Head); + } + + /// noteHead - stash the sentinel into its default location + static void noteHead(NodeTy *NewHead, NodeTy *Sentinel) { + ilist_traits<NodeTy>::setPrev(NewHead, Sentinel); + } }; /// ilist_node_traits - A fragment for template traits for intrusive list @@ -284,17 +316,14 @@ class iplist : public Traits { // circularly linked list where we snip the 'next' link from the sentinel node // back to the first node in the list (to preserve assertions about going off // the end of the list). - NodeTy *getTail() { return this->getPrev(Head); } - const NodeTy *getTail() const { return this->getPrev(Head); } - void setTail(NodeTy *N) const { this->setPrev(Head, N); } + NodeTy *getTail() { return this->ensureHead(Head); } + const NodeTy *getTail() const { return this->ensureHead(Head); } + void setTail(NodeTy *N) const { this->noteHead(Head, N); } /// CreateLazySentinel - This method verifies whether the sentinel for the /// list has been created and lazily makes it if not. void CreateLazySentinel() const { - if (Head != 0) return; - Head = Traits::createSentinel(); - this->setNext(Head, 0); - setTail(Head); + this->Traits::ensureHead(Head); } static bool op_less(NodeTy &L, NodeTy &R) { return L < R; } @@ -318,7 +347,7 @@ public: typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; - iplist() : Head(0) {} + iplist() : Head(this->Traits::provideInitialHead()) {} ~iplist() { if (!Head) return; clear(); diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 521815f..561dbb2 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -41,6 +41,10 @@ template<> struct ilist_traits<Instruction> return static_cast<Instruction*>(&Sentinel); } static void destroySentinel(Instruction*) {} + + Instruction *provideInitialHead() const { return createSentinel(); } + Instruction *ensureHead(Instruction*) const { return createSentinel(); } + static iplist<Instruction> &getList(BasicBlock *BB); static ValueSymbolTable *getSymTab(BasicBlock *ItemParent); static int getListOffset(); diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index 5a9f399..de0a4c4 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -38,6 +38,9 @@ public: } void destroySentinel(MachineInstr *) const {} + MachineInstr *provideInitialHead() const { return createSentinel(); } + MachineInstr *ensureHead(MachineInstr*) const { return createSentinel(); } + void addNodeToList(MachineInstr* N); void removeNodeFromList(MachineInstr* N); void transferNodesFromList(ilist_traits &SrcTraits, diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index 1371f1d..7386b2b 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -44,6 +44,11 @@ public: } void destroySentinel(MachineBasicBlock *) const {} + MachineBasicBlock *provideInitialHead() const { return createSentinel(); } + MachineBasicBlock *ensureHead(MachineBasicBlock*) const { + return createSentinel(); + } + void addNodeToList(MachineBasicBlock* MBB); void removeNodeFromList(MachineBasicBlock* MBB); void deleteNode(MachineBasicBlock *MBB); @@ -363,8 +368,12 @@ template <> struct GraphTraits<const MachineFunction*> : // nodes_iterator/begin/end - Allow iteration over all nodes in the graph typedef MachineFunction::const_iterator nodes_iterator; - static nodes_iterator nodes_begin(const MachineFunction *F) { return F->begin(); } - static nodes_iterator nodes_end (const MachineFunction *F) { return F->end(); } + static nodes_iterator nodes_begin(const MachineFunction *F) { + return F->begin(); + } + static nodes_iterator nodes_end (const MachineFunction *F) { + return F->end(); + } }; diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index fe89fe05..b895242 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -46,6 +46,9 @@ public: } static void destroySentinel(SDNode *) {} + SDNode *provideInitialHead() const { return createSentinel(); } + SDNode *ensureHead(SDNode*) const { return createSentinel(); } + static void deleteNode(SDNode *) { assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!"); } @@ -112,7 +115,8 @@ class SelectionDAG { /// setGraphColorHelper - Implementation of setSubgraphColor. /// Return whether we had to truncate the search. /// - bool setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited, + bool setSubgraphColorHelper(SDNode *N, const char *Color, + DenseSet<SDNode *> &visited, int level, bool &printed); public: diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 37e8f19..cb3cc93 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -38,6 +38,10 @@ template<> struct ilist_traits<BasicBlock> return static_cast<BasicBlock*>(&Sentinel); } static void destroySentinel(BasicBlock*) {} + + BasicBlock *provideInitialHead() const { return createSentinel(); } + BasicBlock *ensureHead(BasicBlock*) const { return createSentinel(); } + static iplist<BasicBlock> &getList(Function *F); static ValueSymbolTable *getSymTab(Function *ItemParent); static int getListOffset(); @@ -52,6 +56,10 @@ template<> struct ilist_traits<Argument> return static_cast<Argument*>(&Sentinel); } static void destroySentinel(Argument*) {} + + Argument *provideInitialHead() const { return createSentinel(); } + Argument *ensureHead(Argument*) const { return createSentinel(); } + static iplist<Argument> &getList(Function *F); static ValueSymbolTable *getSymTab(Function *ItemParent); static int getListOffset(); diff --git a/include/llvm/Support/Recycler.h b/include/llvm/Support/Recycler.h index 3f235b6..39c992b 100644 --- a/include/llvm/Support/Recycler.h +++ b/include/llvm/Support/Recycler.h @@ -46,6 +46,9 @@ struct ilist_traits<RecyclerStruct> : ilist_default_traits<RecyclerStruct> { } static void destroySentinel(RecyclerStruct *) {} + RecyclerStruct *provideInitialHead() const { return createSentinel(); } + RecyclerStruct *ensureHead(RecyclerStruct*) const { return createSentinel(); } + static void deleteNode(RecyclerStruct *) { assert(0 && "Recycler's ilist_traits shouldn't see a deleteNode call!"); } |