[llvm] r274354 - CodeGen: Use MachineInstr& in SlotIndexes.cpp, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 1 08:08:53 PDT 2016
Author: dexonsmith
Date: Fri Jul 1 10:08:52 2016
New Revision: 274354
URL: http://llvm.org/viewvc/llvm-project?rev=274354&view=rev
Log:
CodeGen: Use MachineInstr& in SlotIndexes.cpp, NFC
Avoid implicit conversions from iterator to pointer by preferring
MachineInstr& and using range-based for loops.
Modified:
llvm/trunk/lib/CodeGen/SlotIndexes.cpp
Modified: llvm/trunk/lib/CodeGen/SlotIndexes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SlotIndexes.cpp?rev=274354&r1=274353&r2=274354&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SlotIndexes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SlotIndexes.cpp Fri Jul 1 10:08:52 2016
@@ -69,34 +69,29 @@ bool SlotIndexes::runOnMachineFunction(M
indexList.push_back(createEntry(nullptr, index));
// Iterate over the function.
- for (MachineFunction::iterator mbbItr = mf->begin(), mbbEnd = mf->end();
- mbbItr != mbbEnd; ++mbbItr) {
- MachineBasicBlock *mbb = &*mbbItr;
-
+ for (MachineBasicBlock &MBB : *mf) {
// Insert an index for the MBB start.
SlotIndex blockStartIndex(&indexList.back(), SlotIndex::Slot_Block);
- for (MachineBasicBlock::iterator miItr = mbb->begin(), miEnd = mbb->end();
- miItr != miEnd; ++miItr) {
- MachineInstr *mi = miItr;
- if (mi->isDebugValue())
+ for (MachineInstr &MI : MBB) {
+ if (MI.isDebugValue())
continue;
// Insert a store index for the instr.
- indexList.push_back(createEntry(mi, index += SlotIndex::InstrDist));
+ indexList.push_back(createEntry(&MI, index += SlotIndex::InstrDist));
// Save this base index in the maps.
- mi2iMap.insert(std::make_pair(mi, SlotIndex(&indexList.back(),
- SlotIndex::Slot_Block)));
+ mi2iMap.insert(std::make_pair(
+ &MI, SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
}
// We insert one blank instructions between basic blocks.
indexList.push_back(createEntry(nullptr, index += SlotIndex::InstrDist));
- MBBRanges[mbb->getNumber()].first = blockStartIndex;
- MBBRanges[mbb->getNumber()].second = SlotIndex(&indexList.back(),
+ MBBRanges[MBB.getNumber()].first = blockStartIndex;
+ MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),
SlotIndex::Slot_Block);
- idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, mbb));
+ idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, &MBB));
}
// Sort the Idx2MBBMap
@@ -182,7 +177,7 @@ void SlotIndexes::repairIndexesInRange(M
"Decremented past the beginning of region to repair.");
MachineInstr *SlotMI = ListI->getInstr();
- MachineInstr *MI = (MBBI != MBB->end() && !pastStart) ? MBBI : nullptr;
+ MachineInstr *MI = (MBBI != MBB->end() && !pastStart) ? &*MBBI : nullptr;
bool MBBIAtBegin = MBBI == Begin && (!includeStart || pastStart);
if (SlotMI == MI && !MBBIAtBegin) {
@@ -207,9 +202,9 @@ void SlotIndexes::repairIndexesInRange(M
// to update the IndexList while we are iterating it.
for (MachineBasicBlock::iterator I = End; I != Begin;) {
--I;
- MachineInstr *MI = I;
- if (!MI->isDebugValue() && mi2iMap.find(MI) == mi2iMap.end())
- insertMachineInstrInMaps(*MI);
+ MachineInstr &MI = *I;
+ if (!MI.isDebugValue() && mi2iMap.find(&MI) == mi2iMap.end())
+ insertMachineInstrInMaps(MI);
}
}
More information about the llvm-commits
mailing list