1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[Analysis] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-02-22 20:17:18 -08:00
parent b632082885
commit 4fcbdc3b1b
8 changed files with 34 additions and 46 deletions

View File

@ -283,9 +283,8 @@ Instruction* AliasSet::getUniqueInstruction() {
void AliasSetTracker::clear() {
// Delete all the PointerRec entries.
for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end();
I != E; ++I)
I->second->eraseFromList();
for (auto &I : PointerMap)
I.second->eraseFromList();
PointerMap.clear();
@ -303,12 +302,11 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
bool &MustAliasAll) {
AliasSet *FoundSet = nullptr;
AliasResult AllAR = MustAlias;
for (iterator I = begin(), E = end(); I != E;) {
iterator Cur = I++;
if (Cur->Forward)
for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
if (AS.Forward)
continue;
AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, AA);
AliasResult AR = AS.aliasesPointer(Ptr, Size, AAInfo, AA);
if (AR == NoAlias)
continue;
@ -317,10 +315,10 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
if (!FoundSet) {
// If this is the first alias set ptr can go into, remember it.
FoundSet = &*Cur;
FoundSet = &AS;
} else {
// Otherwise, we must merge the sets.
FoundSet->mergeSetIn(*Cur, *this);
FoundSet->mergeSetIn(AS, *this);
}
}
@ -330,16 +328,15 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
AliasSet *FoundSet = nullptr;
for (iterator I = begin(), E = end(); I != E;) {
iterator Cur = I++;
if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
if (AS.Forward || !AS.aliasesUnknownInst(Inst, AA))
continue;
if (!FoundSet) {
// If this is the first alias set ptr can go into, remember it.
FoundSet = &*Cur;
FoundSet = &AS;
} else {
// Otherwise, we must merge the sets.
FoundSet->mergeSetIn(*Cur, *this);
FoundSet->mergeSetIn(AS, *this);
}
}
return FoundSet;

View File

@ -398,8 +398,7 @@ DivergenceAnalysisPrinterPass::run(Function &F, FunctionAnalysisManager &FAM) {
OS << (DI.isDivergent(Arg) ? "DIVERGENT: " : " ");
OS << Arg << "\n";
}
for (auto BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
auto &BB = *BI;
for (const BasicBlock &BB : F) {
OS << "\n " << BB.getName() << ":\n";
for (auto &I : BB.instructionsWithoutDebug()) {
OS << (DI.isDivergent(I) ? "DIVERGENT: " : " ");

View File

@ -176,8 +176,8 @@ void IRInstructionMapper::convertToUnsignedVec(
if (HaveLegalRange) {
mapToIllegalUnsigned(It, IntegerMappingForBB, InstrListForBB, true);
for_each(InstrListForBB,
[this](IRInstructionData *ID) { this->IDL->push_back(*ID); });
for (IRInstructionData *ID : InstrListForBB)
this->IDL->push_back(*ID);
llvm::append_range(InstrList, InstrListForBB);
llvm::append_range(IntegerMapping, IntegerMappingForBB);
}

View File

@ -609,9 +609,8 @@ bool RecurrenceDescriptor::hasMultipleUsesOf(
Instruction *I, SmallPtrSetImpl<Instruction *> &Insts,
unsigned MaxNumUses) {
unsigned NumUses = 0;
for (User::op_iterator Use = I->op_begin(), E = I->op_end(); Use != E;
++Use) {
if (Insts.count(dyn_cast<Instruction>(*Use)))
for (const Use &U : I->operands()) {
if (Insts.count(dyn_cast<Instruction>(U)))
++NumUses;
if (NumUses > MaxNumUses)
return true;

View File

@ -876,17 +876,14 @@ void LoopInfo::erase(Loop *Unloop) {
// First handle the special case of no parent loop to simplify the algorithm.
if (Unloop->isOutermost()) {
// Since BBLoop had no parent, Unloop blocks are no longer in a loop.
for (Loop::block_iterator I = Unloop->block_begin(),
E = Unloop->block_end();
I != E; ++I) {
for (BasicBlock *BB : Unloop->blocks()) {
// Don't reparent blocks in subloops.
if (getLoopFor(*I) != Unloop)
if (getLoopFor(BB) != Unloop)
continue;
// Blocks no longer have a parent but are still referenced by Unloop until
// the Unloop object is deleted.
changeLoopFor(*I, nullptr);
changeLoopFor(BB, nullptr);
}
// Remove the loop from the top-level LoopInfo object.

View File

@ -1395,11 +1395,9 @@ void MemorySSAUpdater::removeBlocks(
MemorySSA::AccessList *Acc = MSSA->getWritableBlockAccesses(BB);
if (!Acc)
continue;
for (auto AB = Acc->begin(), AE = Acc->end(); AB != AE;) {
MemoryAccess *MA = &*AB;
++AB;
MSSA->removeFromLookups(MA);
MSSA->removeFromLists(MA);
for (MemoryAccess &MA : llvm::make_early_inc_range(*Acc)) {
MSSA->removeFromLookups(&MA);
MSSA->removeFromLists(&MA);
}
}
}

View File

@ -511,10 +511,8 @@ static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
assert(STy);
const StructLayout *SL = DL.getStructLayout(C->getType());
for (StructType::element_iterator EB = STy->element_begin(), EI = EB,
EE = STy->element_end();
EI != EE; ++EI) {
auto Offset = SL->getElementOffset(EI - EB);
for (auto EI : llvm::enumerate(STy->elements())) {
auto Offset = SL->getElementOffset(EI.index());
unsigned Op = SL->getElementContainingOffset(Offset);
findFuncPointers(cast<Constant>(I->getOperand(Op)),
StartingOffset + Offset, M, Index, VTableFuncs);

View File

@ -586,8 +586,8 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
for (auto I = ECs.begin(), E = ECs.end(); I != E; ++I) {
uint64_t LeaderDemandedBits = 0;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI)
LeaderDemandedBits |= DBits[*MI];
for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
LeaderDemandedBits |= DBits[M];
uint64_t MinBW = (sizeof(LeaderDemandedBits) * 8) -
llvm::countLeadingZeros(LeaderDemandedBits);
@ -600,22 +600,22 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
// indvars.
// If we are required to shrink a PHI, abandon this entire equivalence class.
bool Abort = false;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI)
if (isa<PHINode>(*MI) && MinBW < (*MI)->getType()->getScalarSizeInBits()) {
for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
if (isa<PHINode>(M) && MinBW < M->getType()->getScalarSizeInBits()) {
Abort = true;
break;
}
if (Abort)
continue;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI) {
if (!isa<Instruction>(*MI))
for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end())) {
if (!isa<Instruction>(M))
continue;
Type *Ty = (*MI)->getType();
if (Roots.count(*MI))
Ty = cast<Instruction>(*MI)->getOperand(0)->getType();
Type *Ty = M->getType();
if (Roots.count(M))
Ty = cast<Instruction>(M)->getOperand(0)->getType();
if (MinBW < Ty->getScalarSizeInBits())
MinBWs[cast<Instruction>(*MI)] = MinBW;
MinBWs[cast<Instruction>(M)] = MinBW;
}
}