[llvm-commits] [llvm] r66061 - in /llvm/trunk/include/llvm: ADT/ilist.h BasicBlock.h CodeGen/MachineBasicBlock.h CodeGen/MachineFunction.h CodeGen/SelectionDAG.h Function.h Support/Recycler.h
Gabor Greif
ggreif at gmail.com
Wed Mar 4 12:36:44 PST 2009
Author: ggreif
Date: Wed Mar 4 14:36:44 2009
New Revision: 66061
URL: http://llvm.org/viewvc/llvm-project?rev=66061&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/ADT/ilist.h
llvm/trunk/include/llvm/BasicBlock.h
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
llvm/trunk/include/llvm/Function.h
llvm/trunk/include/llvm/Support/Recycler.h
Modified: llvm/trunk/include/llvm/ADT/ilist.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ilist.h (original)
+++ llvm/trunk/include/llvm/ADT/ilist.h Wed Mar 4 14:36:44 2009
@@ -60,13 +60,45 @@
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 @@
// 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 @@
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();
Modified: llvm/trunk/include/llvm/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BasicBlock.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/BasicBlock.h Wed Mar 4 14:36:44 2009
@@ -41,6 +41,10 @@
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();
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Wed Mar 4 14:36:44 2009
@@ -38,6 +38,9 @@
}
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,
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Wed Mar 4 14:36:44 2009
@@ -44,6 +44,11 @@
}
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 @@
// 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();
+ }
};
Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Wed Mar 4 14:36:44 2009
@@ -46,6 +46,9 @@
}
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 @@
/// 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:
Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Wed Mar 4 14:36:44 2009
@@ -38,6 +38,10 @@
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 @@
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();
Modified: llvm/trunk/include/llvm/Support/Recycler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Recycler.h?rev=66061&r1=66060&r2=66061&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Recycler.h (original)
+++ llvm/trunk/include/llvm/Support/Recycler.h Wed Mar 4 14:36:44 2009
@@ -46,6 +46,9 @@
}
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!");
}
More information about the llvm-commits
mailing list