1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +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() { void AliasSetTracker::clear() {
// Delete all the PointerRec entries. // Delete all the PointerRec entries.
for (PointerMapType::iterator I = PointerMap.begin(), E = PointerMap.end(); for (auto &I : PointerMap)
I != E; ++I) I.second->eraseFromList();
I->second->eraseFromList();
PointerMap.clear(); PointerMap.clear();
@ -303,12 +302,11 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
bool &MustAliasAll) { bool &MustAliasAll) {
AliasSet *FoundSet = nullptr; AliasSet *FoundSet = nullptr;
AliasResult AllAR = MustAlias; AliasResult AllAR = MustAlias;
for (iterator I = begin(), E = end(); I != E;) { for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
iterator Cur = I++; if (AS.Forward)
if (Cur->Forward)
continue; continue;
AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, AA); AliasResult AR = AS.aliasesPointer(Ptr, Size, AAInfo, AA);
if (AR == NoAlias) if (AR == NoAlias)
continue; continue;
@ -317,10 +315,10 @@ AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
if (!FoundSet) { if (!FoundSet) {
// If this is the first alias set ptr can go into, remember it. // If this is the first alias set ptr can go into, remember it.
FoundSet = &*Cur; FoundSet = &AS;
} else { } else {
// Otherwise, we must merge the sets. // 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 *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
AliasSet *FoundSet = nullptr; AliasSet *FoundSet = nullptr;
for (iterator I = begin(), E = end(); I != E;) { for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
iterator Cur = I++; if (AS.Forward || !AS.aliasesUnknownInst(Inst, AA))
if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
continue; continue;
if (!FoundSet) { if (!FoundSet) {
// If this is the first alias set ptr can go into, remember it. // If this is the first alias set ptr can go into, remember it.
FoundSet = &*Cur; FoundSet = &AS;
} else { } else {
// Otherwise, we must merge the sets. // Otherwise, we must merge the sets.
FoundSet->mergeSetIn(*Cur, *this); FoundSet->mergeSetIn(AS, *this);
} }
} }
return FoundSet; return FoundSet;

View File

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

View File

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

View File

@ -609,9 +609,8 @@ bool RecurrenceDescriptor::hasMultipleUsesOf(
Instruction *I, SmallPtrSetImpl<Instruction *> &Insts, Instruction *I, SmallPtrSetImpl<Instruction *> &Insts,
unsigned MaxNumUses) { unsigned MaxNumUses) {
unsigned NumUses = 0; unsigned NumUses = 0;
for (User::op_iterator Use = I->op_begin(), E = I->op_end(); Use != E; for (const Use &U : I->operands()) {
++Use) { if (Insts.count(dyn_cast<Instruction>(U)))
if (Insts.count(dyn_cast<Instruction>(*Use)))
++NumUses; ++NumUses;
if (NumUses > MaxNumUses) if (NumUses > MaxNumUses)
return true; 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. // First handle the special case of no parent loop to simplify the algorithm.
if (Unloop->isOutermost()) { if (Unloop->isOutermost()) {
// Since BBLoop had no parent, Unloop blocks are no longer in a loop. // Since BBLoop had no parent, Unloop blocks are no longer in a loop.
for (Loop::block_iterator I = Unloop->block_begin(), for (BasicBlock *BB : Unloop->blocks()) {
E = Unloop->block_end();
I != E; ++I) {
// Don't reparent blocks in subloops. // Don't reparent blocks in subloops.
if (getLoopFor(*I) != Unloop) if (getLoopFor(BB) != Unloop)
continue; continue;
// Blocks no longer have a parent but are still referenced by Unloop until // Blocks no longer have a parent but are still referenced by Unloop until
// the Unloop object is deleted. // the Unloop object is deleted.
changeLoopFor(*I, nullptr); changeLoopFor(BB, nullptr);
} }
// Remove the loop from the top-level LoopInfo object. // Remove the loop from the top-level LoopInfo object.

View File

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

View File

@ -511,10 +511,8 @@ static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
assert(STy); assert(STy);
const StructLayout *SL = DL.getStructLayout(C->getType()); const StructLayout *SL = DL.getStructLayout(C->getType());
for (StructType::element_iterator EB = STy->element_begin(), EI = EB, for (auto EI : llvm::enumerate(STy->elements())) {
EE = STy->element_end(); auto Offset = SL->getElementOffset(EI.index());
EI != EE; ++EI) {
auto Offset = SL->getElementOffset(EI - EB);
unsigned Op = SL->getElementContainingOffset(Offset); unsigned Op = SL->getElementContainingOffset(Offset);
findFuncPointers(cast<Constant>(I->getOperand(Op)), findFuncPointers(cast<Constant>(I->getOperand(Op)),
StartingOffset + Offset, M, Index, VTableFuncs); 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) { for (auto I = ECs.begin(), E = ECs.end(); I != E; ++I) {
uint64_t LeaderDemandedBits = 0; uint64_t LeaderDemandedBits = 0;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI) for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
LeaderDemandedBits |= DBits[*MI]; LeaderDemandedBits |= DBits[M];
uint64_t MinBW = (sizeof(LeaderDemandedBits) * 8) - uint64_t MinBW = (sizeof(LeaderDemandedBits) * 8) -
llvm::countLeadingZeros(LeaderDemandedBits); llvm::countLeadingZeros(LeaderDemandedBits);
@ -600,22 +600,22 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
// indvars. // indvars.
// If we are required to shrink a PHI, abandon this entire equivalence class. // If we are required to shrink a PHI, abandon this entire equivalence class.
bool Abort = false; bool Abort = false;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI) for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
if (isa<PHINode>(*MI) && MinBW < (*MI)->getType()->getScalarSizeInBits()) { if (isa<PHINode>(M) && MinBW < M->getType()->getScalarSizeInBits()) {
Abort = true; Abort = true;
break; break;
} }
if (Abort) if (Abort)
continue; continue;
for (auto MI = ECs.member_begin(I), ME = ECs.member_end(); MI != ME; ++MI) { for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end())) {
if (!isa<Instruction>(*MI)) if (!isa<Instruction>(M))
continue; continue;
Type *Ty = (*MI)->getType(); Type *Ty = M->getType();
if (Roots.count(*MI)) if (Roots.count(M))
Ty = cast<Instruction>(*MI)->getOperand(0)->getType(); Ty = cast<Instruction>(M)->getOperand(0)->getType();
if (MinBW < Ty->getScalarSizeInBits()) if (MinBW < Ty->getScalarSizeInBits())
MinBWs[cast<Instruction>(*MI)] = MinBW; MinBWs[cast<Instruction>(M)] = MinBW;
} }
} }