Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2f1f35b

Browse files
committed
ADT: Guarantee transferNodesFromList is only called on transfers
Guarantee that ilist_traits<T>::transferNodesFromList is only called when nodes are actually changing lists. I also moved all the callbacks to occur *first*, before the operation. This is the only choice for iplist<T>::merge, so we might as well be consistent. I expect this to have no effect in practice, although it simplifies the logic in both iplist<T>::transfer and iplist<T>::insert. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280122 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b8d741f commit 2f1f35b

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

include/llvm/ADT/ilist.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ template <typename NodeTy> struct ilist_node_traits {
4343

4444
void addNodeToList(NodeTy *) {}
4545
void removeNodeFromList(NodeTy *) {}
46-
void transferNodesFromList(ilist_node_traits & /*SrcTraits*/,
46+
47+
/// Callback before transferring nodes to this list.
48+
///
49+
/// \pre \c this!=&OldList
50+
void transferNodesFromList(ilist_node_traits &OldList,
4751
ilist_iterator<NodeTy> /*first*/,
48-
ilist_iterator<NodeTy> /*last*/) {}
52+
ilist_iterator<NodeTy> /*last*/) {
53+
(void)OldList;
54+
}
4955
};
5056

5157
/// Default template traits for intrusive list.
@@ -165,9 +171,8 @@ class iplist : public Traits, simple_ilist<NodeTy> {
165171
}
166172

167173
iterator insert(iterator where, NodeTy *New) {
168-
auto I = base_list_type::insert(where, *New);
169-
this->addNodeToList(New); // Notify traits that we added a node...
170-
return I;
174+
this->addNodeToList(New); // Notify traits that we added a node...
175+
return base_list_type::insert(where, *New);
171176
}
172177

173178
iterator insert(iterator where, const NodeTy &New) {
@@ -182,9 +187,9 @@ class iplist : public Traits, simple_ilist<NodeTy> {
182187
}
183188

184189
NodeTy *remove(iterator &IT) {
185-
NodeTy *Node = &*IT;
186-
base_list_type::erase(IT++);
187-
this->removeNodeFromList(Node); // Notify traits that we removed a node...
190+
NodeTy *Node = &*IT++;
191+
this->removeNodeFromList(Node); // Notify traits that we removed a node...
192+
base_list_type::remove(*Node);
188193
return Node;
189194
}
190195

@@ -220,11 +225,10 @@ class iplist : public Traits, simple_ilist<NodeTy> {
220225
if (position == last)
221226
return;
222227

223-
base_list_type::splice(position, L2, first, last);
228+
if (this != &L2) // Notify traits we moved the nodes...
229+
this->transferNodesFromList(L2, first, last);
224230

225-
// Callback. Note that the nodes have moved from before-last to
226-
// before-position.
227-
this->transferNodesFromList(L2, first, position);
231+
base_list_type::splice(position, L2, first, last);
228232
}
229233

230234
public:

lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ transferNodesFromList(ilist_traits<MachineInstr> &FromList,
122122
ilist_iterator<MachineInstr> Last) {
123123
assert(Parent->getParent() == FromList.Parent->getParent() &&
124124
"MachineInstr parent mismatch!");
125-
126-
// Splice within the same MBB -> no change.
127-
if (Parent == FromList.Parent) return;
125+
assert(this != &FromList && "Called without a real transfer...");
126+
assert(Parent != FromList.Parent && "Two lists have the same parent?");
128127

129128
// If splicing between two blocks within the same function, just update the
130129
// parent pointers.

lib/IR/SymbolTableListTraitsImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void SymbolTableListTraits<ValueSubClass>::transferNodesFromList(
8585
ilist_iterator<ValueSubClass> last) {
8686
// We only have to do work here if transferring instructions between BBs
8787
ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
88-
if (NewIP == OldIP) return; // No work to do at all...
88+
assert(NewIP != OldIP && "Expected different list owners");
8989

9090
// We only have to update symbol table entries if we are transferring the
9191
// instructions to a different symtab object...

0 commit comments

Comments
 (0)