aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2021-02-18 22:46:43 -0800
committerKazu Hirata <kazu@google.com>2021-02-18 22:46:43 -0800
commitfd04f3a30cbb6506aea1ef0b104ab707c4331241 (patch)
tree906190087d9ce6fac99a77637aee75fd1c9d5b85 /llvm/lib
parent2d5eb67235c763898f7c3327fb97b1ae1307d8e4 (diff)
downloadllvm-fd04f3a30cbb6506aea1ef0b104ab707c4331241.zip
llvm-fd04f3a30cbb6506aea1ef0b104ab707c4331241.tar.gz
llvm-fd04f3a30cbb6506aea1ef0b104ab707c4331241.tar.bz2
[CodeGen] Use range-based for loops (NFC)
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/RegAllocPBQP.cpp11
-rw-r--r--llvm/lib/CodeGen/RegisterCoalescer.cpp24
-rw-r--r--llvm/lib/CodeGen/RegisterScavenging.cpp9
-rw-r--r--llvm/lib/CodeGen/ShadowStackGCLowering.cpp4
-rw-r--r--llvm/lib/CodeGen/SlotIndexes.cpp10
-rw-r--r--llvm/lib/CodeGen/SpillPlacement.cpp46
-rw-r--r--llvm/lib/CodeGen/SplitKit.cpp4
-rw-r--r--llvm/lib/CodeGen/StackSlotColoring.cpp13
-rw-r--r--llvm/lib/CodeGen/TwoAddressInstructionPass.cpp5
9 files changed, 54 insertions, 72 deletions
diff --git a/llvm/lib/CodeGen/RegAllocPBQP.cpp b/llvm/lib/CodeGen/RegAllocPBQP.cpp
index 7c5af1a..73290f1 100644
--- a/llvm/lib/CodeGen/RegAllocPBQP.cpp
+++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp
@@ -703,9 +703,8 @@ void RegAllocPBQP::spillVReg(Register VReg,
// Copy any newly inserted live intervals into the list of regs to
// allocate.
- for (LiveRangeEdit::iterator I = LRE.begin(), E = LRE.end();
- I != E; ++I) {
- const LiveInterval &LI = LIS.getInterval(*I);
+ for (const Register &R : LRE) {
+ const LiveInterval &LI = LIS.getInterval(R);
assert(!LI.empty() && "Empty spill range.");
LLVM_DEBUG(dbgs() << printReg(LI.reg(), &TRI) << " ");
VRegsToAlloc.insert(LI.reg());
@@ -759,10 +758,8 @@ void RegAllocPBQP::finalizeAlloc(MachineFunction &MF,
MachineRegisterInfo &MRI = MF.getRegInfo();
// First allocate registers for the empty intervals.
- for (RegSet::const_iterator
- I = EmptyIntervalVRegs.begin(), E = EmptyIntervalVRegs.end();
- I != E; ++I) {
- LiveInterval &LI = LIS.getInterval(*I);
+ for (const Register &R : EmptyIntervalVRegs) {
+ LiveInterval &LI = LIS.getInterval(R);
Register PReg = MRI.getSimpleHint(LI.reg());
diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index 5f770d6..3e4b2ba 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -3877,21 +3877,20 @@ RegisterCoalescer::copyCoalesceInMBB(MachineBasicBlock *MBB) {
// are not inherently easier to resolve, but slightly preferable until we
// have local live range splitting. In particular this is required by
// cmp+jmp macro fusion.
- for (MachineBasicBlock::iterator MII = MBB->begin(), E = MBB->end();
- MII != E; ++MII) {
- if (!MII->isCopyLike())
+ for (MachineInstr &MI : *MBB) {
+ if (!MI.isCopyLike())
continue;
- bool ApplyTerminalRule = applyTerminalRule(*MII);
- if (isLocalCopy(&(*MII), LIS)) {
+ bool ApplyTerminalRule = applyTerminalRule(MI);
+ if (isLocalCopy(&MI, LIS)) {
if (ApplyTerminalRule)
- LocalTerminals.push_back(&(*MII));
+ LocalTerminals.push_back(&MI);
else
- LocalWorkList.push_back(&(*MII));
+ LocalWorkList.push_back(&MI);
} else {
if (ApplyTerminalRule)
- GlobalTerminals.push_back(&(*MII));
+ GlobalTerminals.push_back(&MI);
else
- WorkList.push_back(&(*MII));
+ WorkList.push_back(&MI);
}
}
// Append the copies evicted by the terminal rule at the end of the list.
@@ -3935,10 +3934,9 @@ void RegisterCoalescer::joinAllIntervals() {
std::vector<MBBPriorityInfo> MBBs;
MBBs.reserve(MF->size());
- for (MachineFunction::iterator I = MF->begin(), E = MF->end(); I != E; ++I) {
- MachineBasicBlock *MBB = &*I;
- MBBs.push_back(MBBPriorityInfo(MBB, Loops->getLoopDepth(MBB),
- JoinSplitEdges && isSplitEdge(MBB)));
+ for (MachineBasicBlock &MBB : *MF) {
+ MBBs.push_back(MBBPriorityInfo(&MBB, Loops->getLoopDepth(&MBB),
+ JoinSplitEdges && isSplitEdge(&MBB)));
}
array_pod_sort(MBBs.begin(), MBBs.end(), compareMBBPriority);
diff --git a/llvm/lib/CodeGen/RegisterScavenging.cpp b/llvm/lib/CodeGen/RegisterScavenging.cpp
index a833895..e885bfd 100644
--- a/llvm/lib/CodeGen/RegisterScavenging.cpp
+++ b/llvm/lib/CodeGen/RegisterScavenging.cpp
@@ -167,13 +167,12 @@ void RegScavenger::forward() {
MachineInstr &MI = *MBBI;
- for (SmallVectorImpl<ScavengedInfo>::iterator I = Scavenged.begin(),
- IE = Scavenged.end(); I != IE; ++I) {
- if (I->Restore != &MI)
+ for (ScavengedInfo &I : Scavenged) {
+ if (I.Restore != &MI)
continue;
- I->Reg = 0;
- I->Restore = nullptr;
+ I.Reg = 0;
+ I.Restore = nullptr;
}
if (MI.isDebugInstr())
diff --git a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
index f2111a0..36752ef 100644
--- a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
+++ b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
@@ -238,8 +238,8 @@ void ShadowStackGCLowering::CollectRoots(Function &F) {
SmallVector<std::pair<CallInst *, AllocaInst *>, 16> MetaRoots;
- for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
- for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;)
+ for (BasicBlock &BB : F)
+ for (BasicBlock::iterator II = BB.begin(), E = BB.end(); II != E;)
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II++))
if (Function *F = CI->getCalledFunction())
if (F->getIntrinsicID() == Intrinsic::gcroot) {
diff --git a/llvm/lib/CodeGen/SlotIndexes.cpp b/llvm/lib/CodeGen/SlotIndexes.cpp
index d2bfdc6..c72bcf2 100644
--- a/llvm/lib/CodeGen/SlotIndexes.cpp
+++ b/llvm/lib/CodeGen/SlotIndexes.cpp
@@ -248,12 +248,11 @@ void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB,
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void SlotIndexes::dump() const {
- for (IndexList::const_iterator itr = indexList.begin();
- itr != indexList.end(); ++itr) {
- dbgs() << itr->getIndex() << " ";
+ for (const IndexListEntry &ILE : indexList) {
+ dbgs() << ILE.getIndex() << " ";
- if (itr->getInstr()) {
- dbgs() << *itr->getInstr();
+ if (ILE.getInstr()) {
+ dbgs() << *ILE.getInstr();
} else {
dbgs() << "\n";
}
@@ -280,4 +279,3 @@ LLVM_DUMP_METHOD void SlotIndex::dump() const {
dbgs() << "\n";
}
#endif
-
diff --git a/llvm/lib/CodeGen/SpillPlacement.cpp b/llvm/lib/CodeGen/SpillPlacement.cpp
index 6f91092..91da5e4 100644
--- a/llvm/lib/CodeGen/SpillPlacement.cpp
+++ b/llvm/lib/CodeGen/SpillPlacement.cpp
@@ -121,9 +121,9 @@ struct SpillPlacement::Node {
SumLinkWeights += w;
// There can be multiple links to the same bundle, add them up.
- for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I)
- if (I->second == b) {
- I->first += w;
+ for (std::pair<BlockFrequency, unsigned> &L : Links)
+ if (L.second == b) {
+ L.first += w;
return;
}
// This must be the first link to b.
@@ -153,11 +153,11 @@ struct SpillPlacement::Node {
// Compute the weighted sum of inputs.
BlockFrequency SumN = BiasN;
BlockFrequency SumP = BiasP;
- for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) {
- if (nodes[I->second].Value == -1)
- SumN += I->first;
- else if (nodes[I->second].Value == 1)
- SumP += I->first;
+ for (std::pair<BlockFrequency, unsigned> &L : Links) {
+ if (nodes[L.second].Value == -1)
+ SumN += L.first;
+ else if (nodes[L.second].Value == 1)
+ SumP += L.first;
}
// Each weighted sum is going to be less than the total frequency of the
@@ -258,35 +258,33 @@ void SpillPlacement::setThreshold(const BlockFrequency &Entry) {
/// addConstraints - Compute node biases and weights from a set of constraints.
/// Set a bit in NodeMask for each active node.
void SpillPlacement::addConstraints(ArrayRef<BlockConstraint> LiveBlocks) {
- for (ArrayRef<BlockConstraint>::iterator I = LiveBlocks.begin(),
- E = LiveBlocks.end(); I != E; ++I) {
- BlockFrequency Freq = BlockFrequencies[I->Number];
+ for (const BlockConstraint &LB : LiveBlocks) {
+ BlockFrequency Freq = BlockFrequencies[LB.Number];
// Live-in to block?
- if (I->Entry != DontCare) {
- unsigned ib = bundles->getBundle(I->Number, false);
+ if (LB.Entry != DontCare) {
+ unsigned ib = bundles->getBundle(LB.Number, false);
activate(ib);
- nodes[ib].addBias(Freq, I->Entry);
+ nodes[ib].addBias(Freq, LB.Entry);
}
// Live-out from block?
- if (I->Exit != DontCare) {
- unsigned ob = bundles->getBundle(I->Number, true);
+ if (LB.Exit != DontCare) {
+ unsigned ob = bundles->getBundle(LB.Number, true);
activate(ob);
- nodes[ob].addBias(Freq, I->Exit);
+ nodes[ob].addBias(Freq, LB.Exit);
}
}
}
/// addPrefSpill - Same as addConstraints(PrefSpill)
void SpillPlacement::addPrefSpill(ArrayRef<unsigned> Blocks, bool Strong) {
- for (ArrayRef<unsigned>::iterator I = Blocks.begin(), E = Blocks.end();
- I != E; ++I) {
- BlockFrequency Freq = BlockFrequencies[*I];
+ for (unsigned B : Blocks) {
+ BlockFrequency Freq = BlockFrequencies[B];
if (Strong)
Freq += Freq;
- unsigned ib = bundles->getBundle(*I, false);
- unsigned ob = bundles->getBundle(*I, true);
+ unsigned ib = bundles->getBundle(B, false);
+ unsigned ob = bundles->getBundle(B, true);
activate(ib);
activate(ob);
nodes[ib].addBias(Freq, PrefSpill);
@@ -295,9 +293,7 @@ void SpillPlacement::addPrefSpill(ArrayRef<unsigned> Blocks, bool Strong) {
}
void SpillPlacement::addLinks(ArrayRef<unsigned> Links) {
- for (ArrayRef<unsigned>::iterator I = Links.begin(), E = Links.end(); I != E;
- ++I) {
- unsigned Number = *I;
+ for (unsigned Number : Links) {
unsigned ib = bundles->getBundle(Number, false);
unsigned ob = bundles->getBundle(Number, true);
diff --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp
index 5f97729..d3e75ca 100644
--- a/llvm/lib/CodeGen/SplitKit.cpp
+++ b/llvm/lib/CodeGen/SplitKit.cpp
@@ -1364,8 +1364,8 @@ void SplitEditor::rewriteAssigned(bool ExtendRanges) {
void SplitEditor::deleteRematVictims() {
SmallVector<MachineInstr*, 8> Dead;
- for (LiveRangeEdit::iterator I = Edit->begin(), E = Edit->end(); I != E; ++I){
- LiveInterval *LI = &LIS.getInterval(*I);
+ for (const Register &R : *Edit) {
+ LiveInterval *LI = &LIS.getInterval(R);
for (const LiveRange::Segment &S : LI->segments) {
// Dead defs end at the dead slot.
if (S.end != S.valno->def.getDeadSlot())
diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp
index a6f8974f..bd5653f 100644
--- a/llvm/lib/CodeGen/StackSlotColoring.cpp
+++ b/llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -157,12 +157,8 @@ void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction &MF) {
SSRefs.resize(MFI->getObjectIndexEnd());
// FIXME: Need the equivalent of MachineRegisterInfo for frameindex operands.
- for (MachineFunction::iterator MBBI = MF.begin(), E = MF.end();
- MBBI != E; ++MBBI) {
- MachineBasicBlock *MBB = &*MBBI;
- for (MachineBasicBlock::iterator MII = MBB->begin(), EE = MBB->end();
- MII != EE; ++MII) {
- MachineInstr &MI = *MII;
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : MBB) {
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isFI())
@@ -474,9 +470,8 @@ bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
++I;
}
- for (SmallVectorImpl<MachineInstr *>::iterator I = toErase.begin(),
- E = toErase.end(); I != E; ++I)
- (*I)->eraseFromParent();
+ for (MachineInstr *MI : toErase)
+ MI->eraseFromParent();
return changed;
}
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index 2a9132b..a011b03 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -1549,9 +1549,8 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &Func) {
.set(MachineFunctionProperties::Property::TiedOpsRewritten);
TiedOperandMap TiedOperands;
- for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end();
- MBBI != MBBE; ++MBBI) {
- MBB = &*MBBI;
+ for (MachineBasicBlock &MBBI : *MF) {
+ MBB = &MBBI;
unsigned Dist = 0;
DistanceMap.clear();
SrcRegMap.clear();