diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-09-11 18:51:28 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-09-11 18:51:28 +0000 |
commit | 1872096f1e2befed2a3be6617eddfb18a06f80d7 (patch) | |
tree | 568ba73e708d1bb44439df5204006b88b8dabff9 /llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | |
parent | e98bc7af8bb4eb8cf45413bf2826b1dbd8c9c57d (diff) | |
download | bcm5719-llvm-1872096f1e2befed2a3be6617eddfb18a06f80d7.tar.gz bcm5719-llvm-1872096f1e2befed2a3be6617eddfb18a06f80d7.zip |
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.)
llvm-svn: 281172
Diffstat (limited to 'llvm/lib/CodeGen/DeadMachineInstructionElim.cpp')
-rw-r--r-- | llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp index 0b8dc7a86ad..17c229a216a 100644 --- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp +++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp @@ -122,7 +122,7 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) { // liveness as we go. for (MachineBasicBlock::reverse_iterator MII = MBB.rbegin(), MIE = MBB.rend(); MII != MIE; ) { - MachineInstr *MI = &*MII; + MachineInstr *MI = &*MII++; // If the instruction is dead, delete it! if (isDead(MI)) { @@ -133,9 +133,6 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) { MI->eraseFromParentAndMarkDBGValuesForRemoval(); AnyChanges = true; ++NumDeletes; - MIE = MBB.rend(); - // MII is now pointing to the next instruction to process, - // so don't increment it. continue; } @@ -169,10 +166,6 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) { } } } - - // We didn't delete the current instruction, so increment MII to - // the next one. - ++MII; } } |