diff options
author | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2016-11-08 19:27:10 +0000 |
---|---|---|
committer | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2016-11-08 19:27:10 +0000 |
commit | db273a1272eb972d5fc361262841c762636cae95 (patch) | |
tree | 69336e886b14dd9f5f9944597fafe5881adfa00d /llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp | |
parent | 1e77aaca8a9127f417d1f3e8694db1ebe4bf6440 (diff) | |
download | bcm5719-llvm-db273a1272eb972d5fc361262841c762636cae95.tar.gz bcm5719-llvm-db273a1272eb972d5fc361262841c762636cae95.zip |
[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
llvm-svn: 286272
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp index be2035566b8..653c2428441 100644 --- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -89,11 +89,28 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { 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 |