diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-09-11 16:38:18 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-09-11 16:38:18 +0000 |
| commit | cc9edace0cf5f496ee117ec41d1c448a7abc1280 (patch) | |
| tree | c7dcbfb7b09b3054ff3f3b3db582fac8b6300418 | |
| parent | 085bbf1e2fb4f8c5924843426eaea99f64e84815 (diff) | |
| download | bcm5719-llvm-cc9edace0cf5f496ee117ec41d1c448a7abc1280.tar.gz bcm5719-llvm-cc9edace0cf5f496ee117ec41d1c448a7abc1280.zip | |
CodeGen: Turn on sentinel tracking for MachineInstr iterators
This is a prep commit before fixing MachineBasicBlock::reverse_iterator
invalidation semantics, ala r281167 for ilist::reverse_iterator. This
changes MachineBasicBlock::Instructions to track which node is the
sentinel regardless of LLVM_ENABLE_ABI_BREAKING_CHECKS.
There's almost no functionality change (aside from ABI). However, in
the rare configuration:
#if !defined(NDEBUG) && !defined(LLVM_ENABLE_ABI_BREAKING_CHECKS)
the isKnownSentinel() assertions in ilist_iterator<>::operator* suddenly
have teeth for MachineInstr. If these assertions start firing for your
out-of-tree backend, have a look at the suggestions in the commit
message for r279314, and at some of the commits leading up to it that
avoid dereferencing the end() iterator.
llvm-svn: 281168
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachineBasicBlock.h | 10 | ||||
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachineInstr.h | 3 | ||||
| -rw-r--r-- | llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h | 4 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 6 | ||||
| -rw-r--r-- | llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp | 3 |
5 files changed, 15 insertions, 11 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index 4f949a6074f..47f8dd5e5f1 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -43,12 +43,14 @@ private: friend class MachineBasicBlock; // Set by the owning MachineBasicBlock. MachineBasicBlock *Parent; + typedef simple_ilist<MachineInstr, ilist_sentinel_tracking<true>>::iterator + instr_iterator; + public: void addNodeToList(MachineInstr *N); void removeNodeFromList(MachineInstr *N); - void transferNodesFromList(ilist_traits &OldList, - simple_ilist<MachineInstr>::iterator First, - simple_ilist<MachineInstr>::iterator Last); + void transferNodesFromList(ilist_traits &OldList, instr_iterator First, + instr_iterator Last); void deleteNode(MachineInstr *MI); // Leave out createNode... @@ -70,7 +72,7 @@ public: }; private: - typedef ilist<MachineInstr> Instructions; + typedef ilist<MachineInstr, ilist_sentinel_tracking<true>> Instructions; Instructions Insts; const BasicBlock *BB; int Number; diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index 0a5c7deb863..3870a1ffc9c 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -50,7 +50,8 @@ class MachineMemOperand; /// without having their destructor called. /// class MachineInstr - : public ilist_node_with_parent<MachineInstr, MachineBasicBlock> { + : public ilist_node_with_parent<MachineInstr, MachineBasicBlock, + ilist_sentinel_tracking<true>> { public: typedef MachineMemOperand **mmo_iterator; diff --git a/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h b/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h index e4c46dfe209..6da1ef3e1d1 100644 --- a/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h +++ b/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h @@ -20,12 +20,12 @@ namespace llvm { template <class T> struct MachineInstrBundleIteratorTraits { - typedef simple_ilist<T> list_type; + typedef simple_ilist<T, ilist_sentinel_tracking<true>> list_type; typedef typename list_type::iterator instr_iterator; typedef typename list_type::iterator nonconst_instr_iterator; }; template <class T> struct MachineInstrBundleIteratorTraits<const T> { - typedef simple_ilist<T> list_type; + typedef simple_ilist<T, ilist_sentinel_tracking<true>> list_type; typedef typename list_type::const_iterator instr_iterator; typedef typename list_type::iterator nonconst_instr_iterator; }; diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index d50f4e7763a..d9eef55e79f 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -118,9 +118,9 @@ void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr *N) { /// When moving a range of instructions from one MBB list to another, we need to /// update the parent pointers and the use/def lists. -void ilist_traits<MachineInstr>::transferNodesFromList( - ilist_traits &FromList, simple_ilist<MachineInstr>::iterator First, - simple_ilist<MachineInstr>::iterator Last) { +void ilist_traits<MachineInstr>::transferNodesFromList(ilist_traits &FromList, + instr_iterator First, + instr_iterator Last) { assert(Parent->getParent() == FromList.Parent->getParent() && "MachineInstr parent mismatch!"); assert(this != &FromList && "Called without a real transfer..."); diff --git a/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp b/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp index 857994a3b29..738d07d06a6 100644 --- a/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp @@ -15,7 +15,8 @@ using namespace llvm; namespace { -struct MyBundledInstr : public ilist_node<MyBundledInstr> { +struct MyBundledInstr + : public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> { bool isBundledWithPred() const { return true; } bool isBundledWithSucc() const { return true; } }; |

