Skip to content

Commit

Permalink
[llvm] Use range-based for loops (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Dec 7, 2021
1 parent 2334314 commit 630c847
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 61 deletions.
16 changes: 8 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -3058,14 +3058,14 @@ void SelectionDAGBuilder::visitLandingPad(const LandingPadInst &LP) {
void SelectionDAGBuilder::UpdateSplitBlock(MachineBasicBlock *First,
MachineBasicBlock *Last) {
// Update JTCases.
for (unsigned i = 0, e = SL->JTCases.size(); i != e; ++i)
if (SL->JTCases[i].first.HeaderBB == First)
SL->JTCases[i].first.HeaderBB = Last;
for (JumpTableBlock &JTB : SL->JTCases)
if (JTB.first.HeaderBB == First)
JTB.first.HeaderBB = Last;

// Update BitTestCases.
for (unsigned i = 0, e = SL->BitTestCases.size(); i != e; ++i)
if (SL->BitTestCases[i].Parent == First)
SL->BitTestCases[i].Parent = Last;
for (BitTestBlock &BTB : SL->BitTestCases)
if (BTB.Parent == First)
BTB.Parent = Last;
}

void SelectionDAGBuilder::visitIndirectBr(const IndirectBrInst &I) {
Expand Down Expand Up @@ -9642,8 +9642,8 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
// We push in swifterror return as the last element of CLI.Ins.
ArgListTy &Args = CLI.getArgs();
if (supportSwiftError()) {
for (unsigned i = 0, e = Args.size(); i != e; ++i) {
if (Args[i].IsSwiftError) {
for (const ArgListEntry &Arg : Args) {
if (Arg.IsSwiftError) {
ISD::InputArg MyFlags;
MyFlags.VT = getPointerTy(DL);
MyFlags.ArgVT = EVT(getPointerTy(DL));
Expand Down
18 changes: 8 additions & 10 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Expand Up @@ -1784,27 +1784,25 @@ SelectionDAGISel::FinishBasicBlock() {
}

// Update PHI Nodes
for (unsigned pi = 0, pe = FuncInfo->PHINodesToUpdate.size();
pi != pe; ++pi) {
MachineInstrBuilder PHI(*MF, FuncInfo->PHINodesToUpdate[pi].first);
for (const std::pair<MachineInstr *, unsigned> &P :
FuncInfo->PHINodesToUpdate) {
MachineInstrBuilder PHI(*MF, P.first);
MachineBasicBlock *PHIBB = PHI->getParent();
assert(PHI->isPHI() &&
"This is not a machine PHI node that we are updating!");
// This is "default" BB. We have two jumps to it. From "header" BB and
// from last "case" BB, unless the latter was skipped.
if (PHIBB == BTB.Default) {
PHI.addReg(FuncInfo->PHINodesToUpdate[pi].second).addMBB(BTB.Parent);
PHI.addReg(P.second).addMBB(BTB.Parent);
if (!BTB.ContiguousRange) {
PHI.addReg(FuncInfo->PHINodesToUpdate[pi].second)
.addMBB(BTB.Cases.back().ThisBB);
PHI.addReg(P.second).addMBB(BTB.Cases.back().ThisBB);
}
}
// One of "cases" BB.
for (unsigned j = 0, ej = BTB.Cases.size();
j != ej; ++j) {
MachineBasicBlock* cBB = BTB.Cases[j].ThisBB;
for (const SwitchCG::BitTestCase &BT : BTB.Cases) {
MachineBasicBlock* cBB = BT.ThisBB;
if (cBB->isSuccessor(PHIBB))
PHI.addReg(FuncInfo->PHINodesToUpdate[pi].second).addMBB(cBB);
PHI.addReg(P.second).addMBB(cBB);
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Expand Up @@ -4853,13 +4853,9 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
}

// Now select chosen alternative in each constraint.
for (unsigned cIndex = 0, eIndex = ConstraintOperands.size();
cIndex != eIndex; ++cIndex) {
AsmOperandInfo &cInfo = ConstraintOperands[cIndex];
if (cInfo.Type == InlineAsm::isClobber)
continue;
cInfo.selectAlternative(bestMAIndex);
}
for (AsmOperandInfo &cInfo : ConstraintOperands)
if (cInfo.Type != InlineAsm::isClobber)
cInfo.selectAlternative(bestMAIndex);
}
}

Expand Down Expand Up @@ -4927,9 +4923,9 @@ TargetLowering::ConstraintWeight
ConstraintWeight BestWeight = CW_Invalid;

// Loop over the options, keeping track of the most general one.
for (unsigned i = 0, e = rCodes->size(); i != e; ++i) {
for (const std::string &rCode : *rCodes) {
ConstraintWeight weight =
getSingleConstraintMatchWeight(info, (*rCodes)[i].c_str());
getSingleConstraintMatchWeight(info, rCode.c_str());
if (weight > BestWeight)
BestWeight = weight;
}
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/CodeGen/ShadowStackGCLowering.cpp
Expand Up @@ -162,8 +162,8 @@ Type *ShadowStackGCLowering::GetConcreteStackEntryType(Function &F) {
// doInitialization creates the generic version of this type.
std::vector<Type *> EltTys;
EltTys.push_back(StackEntryTy);
for (size_t I = 0; I != Roots.size(); I++)
EltTys.push_back(Roots[I].second->getAllocatedType());
for (const std::pair<CallInst *, AllocaInst *> &Root : Roots)
EltTys.push_back(Root.second->getAllocatedType());

return StructType::create(EltTys, ("gc_stackentry." + F.getName()).str());
}
Expand Down Expand Up @@ -240,8 +240,8 @@ void ShadowStackGCLowering::CollectRoots(Function &F) {
SmallVector<std::pair<CallInst *, AllocaInst *>, 16> MetaRoots;

for (BasicBlock &BB : F)
for (BasicBlock::iterator II = BB.begin(), E = BB.end(); II != E;)
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II++))
for (Instruction &I : BB)
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(&I))
if (Function *F = CI->getCalledFunction())
if (F->getIntrinsicID() == Intrinsic::gcroot) {
std::pair<CallInst *, AllocaInst *> Pair = std::make_pair(
Expand Down Expand Up @@ -377,9 +377,9 @@ bool ShadowStackGCLowering::runOnFunction(Function &F) {
// Delete the original allocas (which are no longer used) and the intrinsic
// calls (which are no longer valid). Doing this last avoids invalidating
// iterators.
for (unsigned I = 0, E = Roots.size(); I != E; ++I) {
Roots[I].first->eraseFromParent();
Roots[I].second->eraseFromParent();
for (std::pair<CallInst *, AllocaInst *> &Root : Roots) {
Root.first->eraseFromParent();
Root.second->eraseFromParent();
}

Roots.clear();
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/CodeGen/StackSlotColoring.cpp
Expand Up @@ -325,8 +325,7 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {

LLVM_DEBUG(dbgs() << "Color spill slot intervals:\n");
bool Changed = false;
for (unsigned i = 0, e = SSIntervals.size(); i != e; ++i) {
LiveInterval *li = SSIntervals[i];
for (LiveInterval *li : SSIntervals) {
int SS = Register::stackSlot2Index(li->reg());
int NewSS = ColorSlot(li);
assert(NewSS >= 0 && "Stack coloring failed?");
Expand All @@ -338,17 +337,16 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
}

LLVM_DEBUG(dbgs() << "\nSpill slots after coloring:\n");
for (unsigned i = 0, e = SSIntervals.size(); i != e; ++i) {
LiveInterval *li = SSIntervals[i];
for (LiveInterval *li : SSIntervals) {
int SS = Register::stackSlot2Index(li->reg());
li->setWeight(SlotWeights[SS]);
}
// Sort them by new weight.
llvm::stable_sort(SSIntervals, IntervalSorter());

#ifndef NDEBUG
for (unsigned i = 0, e = SSIntervals.size(); i != e; ++i)
LLVM_DEBUG(SSIntervals[i]->dump());
for (LiveInterval *li : SSIntervals)
LLVM_DEBUG(li->dump());
LLVM_DEBUG(dbgs() << '\n');
#endif

Expand Down
21 changes: 9 additions & 12 deletions llvm/lib/CodeGen/TailDuplicator.cpp
Expand Up @@ -207,19 +207,17 @@ bool TailDuplicator::tailDuplicateAndUpdate(
// Add the new vregs as available values.
DenseMap<Register, AvailableValsTy>::iterator LI =
SSAUpdateVals.find(VReg);
for (unsigned j = 0, ee = LI->second.size(); j != ee; ++j) {
MachineBasicBlock *SrcBB = LI->second[j].first;
Register SrcReg = LI->second[j].second;
for (std::pair<MachineBasicBlock *, Register> &J : LI->second) {
MachineBasicBlock *SrcBB = J.first;
Register SrcReg = J.second;
SSAUpdate.AddAvailableValue(SrcBB, SrcReg);
}

SmallVector<MachineOperand *> DebugUses;
// Rewrite uses that are outside of the original def's block.
MachineRegisterInfo::use_iterator UI = MRI->use_begin(VReg);
while (UI != MRI->use_end()) {
MachineOperand &UseMO = *UI;
for (MachineOperand &UseMO :
llvm::make_early_inc_range(MRI->use_operands(VReg))) {
MachineInstr *UseMI = UseMO.getParent();
++UI;
// Rewrite debug uses last so that they can take advantage of any
// register mappings introduced by other users in its BB, since we
// cannot create new register definitions specifically for the debug
Expand Down Expand Up @@ -512,16 +510,16 @@ void TailDuplicator::updateSuccessorsPHIs(
SSAUpdateVals.find(Reg);
if (LI != SSAUpdateVals.end()) {
// This register is defined in the tail block.
for (unsigned j = 0, ee = LI->second.size(); j != ee; ++j) {
MachineBasicBlock *SrcBB = LI->second[j].first;
for (const std::pair<MachineBasicBlock *, Register> &J : LI->second) {
MachineBasicBlock *SrcBB = J.first;
// If we didn't duplicate a bb into a particular predecessor, we
// might still have added an entry to SSAUpdateVals to correcly
// recompute SSA. If that case, avoid adding a dummy extra argument
// this PHI.
if (!SrcBB->isSuccessor(SuccBB))
continue;

Register SrcReg = LI->second[j].second;
Register SrcReg = J.second;
if (Idx != 0) {
MI.getOperand(Idx).setReg(SrcReg);
MI.getOperand(Idx + 1).setMBB(SrcBB);
Expand All @@ -532,8 +530,7 @@ void TailDuplicator::updateSuccessorsPHIs(
}
} else {
// Live in tail block, must also be live in predecessors.
for (unsigned j = 0, ee = TDBBs.size(); j != ee; ++j) {
MachineBasicBlock *SrcBB = TDBBs[j];
for (MachineBasicBlock *SrcBB : TDBBs) {
if (Idx != 0) {
MI.getOperand(Idx).setReg(Reg);
MI.getOperand(Idx + 1).setMBB(SrcBB);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/TargetRegisterInfo.cpp
Expand Up @@ -248,8 +248,8 @@ static void getAllocatableSetForRC(const MachineFunction &MF,
const TargetRegisterClass *RC, BitVector &R){
assert(RC->isAllocatable() && "invalid for nonallocatable sets");
ArrayRef<MCPhysReg> Order = RC->getRawAllocationOrder(MF);
for (unsigned i = 0; i != Order.size(); ++i)
R.set(Order[i]);
for (MCPhysReg PR : Order)
R.set(PR);
}

BitVector TargetRegisterInfo::getAllocatableSet(const MachineFunction &MF,
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/DWARFLinker/DWARFLinker.cpp
Expand Up @@ -409,10 +409,10 @@ static bool dieNeedsChildrenToBeMeaningful(uint32_t Tag) {
void DWARFLinker::cleanupAuxiliarryData(LinkContext &Context) {
Context.clear();

for (auto I = DIEBlocks.begin(), E = DIEBlocks.end(); I != E; ++I)
(*I)->~DIEBlock();
for (auto I = DIELocs.begin(), E = DIELocs.end(); I != E; ++I)
(*I)->~DIELoc();
for (DIEBlock *I : DIEBlocks)
I->~DIEBlock();
for (DIELoc *I : DIELocs)
I->~DIELoc();

DIEBlocks.clear();
DIELocs.clear();
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/DWARFLinker/DWARFStreamer.cpp
Expand Up @@ -531,9 +531,7 @@ void DwarfStreamer::emitLineTableForUnit(MCDwarfLineTableParams Params,

unsigned RowsSinceLastSequence = 0;

for (unsigned Idx = 0; Idx < Rows.size(); ++Idx) {
auto &Row = Rows[Idx];

for (DWARFDebugLine::Row &Row : Rows) {
int64_t AddressDelta;
if (Address == -1ULL) {
MS->emitIntValue(dwarf::DW_LNS_extended_op, 1);
Expand Down

0 comments on commit 630c847

Please sign in to comment.