OSDN Git Service

CodeGen: Give MachineBasicBlock::reverse_iterator a handle to the current MI
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 11 Sep 2016 18:51:28 +0000 (18:51 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 11 Sep 2016 18:51:28 +0000 (18:51 +0000)
commitd546df8daf879ae9d9a8a3492cfcd9cfedb81d9e
tree85b1c7bffcf0febb8091a7a64e9c2c74eac121a6
parentce85c7eb57a0a867896afc521d2c3eadabe36bc1
CodeGen: Give MachineBasicBlock::reverse_iterator a handle to the current MI

Now that MachineBasicBlock::reverse_instr_iterator knows when it's at
the end (since r281168 and r281170), implement
MachineBasicBlock::reverse_iterator directly on top of an
ilist::reverse_iterator by adding an IsReverse template parameter to
MachineInstrBundleIterator.  This replaces another hard-to-reason-about
use of std::reverse_iterator on list iterators, matching the changes for
ilist::reverse_iterator from r280032 (see the "out of scope" section at
the end of that commit message).  MachineBasicBlock::reverse_iterator
now has a handle to the current node and has obvious invalidation
semantics.

r280032 has a more detailed explanation of how list-style reverse
iterators (invalidated when the pointed-at node is deleted) are
different from vector-style reverse iterators like std::reverse_iterator
(invalidated on every operation).  A great motivating example is this
commit's changes to lib/CodeGen/DeadMachineInstructionElim.cpp.

Note: If your out-of-tree backend deletes instructions while iterating
on a MachineBasicBlock::reverse_iterator or converts between
MachineBasicBlock::iterator and MachineBasicBlock::reverse_iterator,
you'll need to update your code in similar ways to r280032.  The
following table might help:

                  [Old]              ==>             [New]
        delete &*RI, RE = end()                   delete &*RI++
        RI->erase(), RE = end()                   RI++->erase()
      reverse_iterator(I)                 std::prev(I).getReverse()
      reverse_iterator(I)                          ++I.getReverse()
    --reverse_iterator(I)                            I.getReverse()
      reverse_iterator(std::next(I))                 I.getReverse()
                RI.base()                std::prev(RI).getReverse()
                RI.base()                         ++RI.getReverse()
              --RI.base()                           RI.getReverse()
     std::next(RI).base()                           RI.getReverse()

(For more details, have a look at r280032.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281172 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/CodeGen/MachineInstrBundleIterator.h
lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
lib/CodeGen/DeadMachineInstructionElim.cpp
lib/CodeGen/IfConversion.cpp
lib/Target/AArch64/AArch64InstrInfo.cpp
lib/Target/AMDGPU/R600InstrInfo.cpp
lib/Target/ARM/MLxExpansionPass.cpp
lib/Target/Hexagon/HexagonInstrInfo.cpp
lib/Target/Mips/MipsDelaySlotFiller.cpp
lib/Target/Mips/MipsInstrInfo.cpp
lib/Target/Mips/MipsLongBranch.cpp
lib/Target/X86/X86InstrInfo.cpp
unittests/CodeGen/MachineInstrBundleIteratorTest.cpp