[llvm] r286272 - [GlobalISel] Permit select() to erase.
Ahmed Bougacha via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 11:27:11 PST 2016
Author: ab
Date: Tue Nov 8 13:27:10 2016
New Revision: 286272
URL: http://llvm.org/viewvc/llvm-project?rev=286272&view=rev
Log:
[GlobalISel] Permit select() to erase.
Erasing reverse_iterators is problematic; iterate manually.
While there, keep track of the range of inserted instructions.
It can miss instructions inserted elsewhere, but those are harder
to track.
Differential Revision: http://reviews.llvm.org/D22924
Modified:
llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp
Modified: llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp?rev=286272&r1=286271&r2=286272&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelect.cpp Tue Nov 8 13:27:10 2016
@@ -89,11 +89,28 @@ bool InstructionSelect::runOnMachineFunc
bool Failed = false;
for (MachineBasicBlock *MBB : post_order(&MF)) {
- for (MachineBasicBlock::reverse_iterator MII = MBB->rbegin(),
- End = MBB->rend();
- MII != End;) {
- MachineInstr &MI = *MII++;
- DEBUG(dbgs() << "Selecting: " << MI << '\n');
+ if (MBB->empty())
+ continue;
+
+ // Select instructions in reverse block order. We permit erasing so have
+ // to resort to manually iterating and recognizing the begin (rend) case.
+ bool ReachedBegin = false;
+ for (auto MII = std::prev(MBB->end()), Begin = MBB->begin();
+ !ReachedBegin;) {
+ // Keep track of the insertion range for debug printing.
+ const auto AfterIt = std::next(MII);
+
+ // Select this instruction.
+ MachineInstr &MI = *MII;
+
+ // And have our iterator point to the next instruction, if there is one.
+ if (MII == Begin)
+ ReachedBegin = true;
+ else
+ --MII;
+
+ DEBUG(dbgs() << "Selecting: \n " << MI);
+
if (!ISel->select(MI)) {
if (TPC.isGlobalISelAbortEnabled())
// FIXME: It would be nice to dump all inserted instructions. It's
More information about the llvm-commits
mailing list