[llvm] r281168 - CodeGen: Turn on sentinel tracking for MachineInstr iterators

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 11 09:48:55 PDT 2016


> On 2016-Sep-11, at 09:38, Duncan P. N. Exon Smith via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: dexonsmith
> Date: Sun Sep 11 11:38:18 2016
> New Revision: 281168
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=281168&view=rev
> Log:
> CodeGen: Turn on sentinel tracking for MachineInstr iterators
> 
> This is a prep commit before fixing MachineBasicBlock::reverse_iterator
> invalidation semantics, ala r281167

I meant: r280032

> 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.
> 
> Modified:
>    llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
>    llvm/trunk/include/llvm/CodeGen/MachineInstr.h
>    llvm/trunk/include/llvm/CodeGen/MachineInstrBundleIterator.h
>    llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
>    llvm/trunk/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp
> 
> Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=281168&r1=281167&r2=281168&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Sun Sep 11 11:38:18 2016
> @@ -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;
> 
> Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=281168&r1=281167&r2=281168&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Sun Sep 11 11:38:18 2016
> @@ -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;
> 
> 
> Modified: llvm/trunk/include/llvm/CodeGen/MachineInstrBundleIterator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstrBundleIterator.h?rev=281168&r1=281167&r2=281168&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineInstrBundleIterator.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineInstrBundleIterator.h Sun Sep 11 11:38:18 2016
> @@ -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;
> };
> 
> Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=281168&r1=281167&r2=281168&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Sun Sep 11 11:38:18 2016
> @@ -118,9 +118,9 @@ void ilist_traits<MachineInstr>::removeN
> 
> /// 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...");
> 
> Modified: llvm/trunk/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp?rev=281168&r1=281167&r2=281168&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp (original)
> +++ llvm/trunk/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp Sun Sep 11 11:38:18 2016
> @@ -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; }
> };
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list