diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h index eb031613a9359..eae409e75293d 100644 --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -260,10 +260,7 @@ class DataLayout { /// /// The width is specified in bits. bool isLegalInteger(uint64_t Width) const { - for (unsigned LegalIntWidth : LegalIntWidths) - if (LegalIntWidth == Width) - return true; - return false; + return llvm::is_contained(LegalIntWidths, Width); } bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); } diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index b79de83ac698c..e75b7f01c868a 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1568,9 +1568,7 @@ class Record { void getDirectSuperClasses(SmallVectorImpl &Classes) const; bool isTemplateArg(Init *Name) const { - for (Init *TA : TemplateArgs) - if (TA == Name) return true; - return false; + return llvm::is_contained(TemplateArgs, Name); } const RecordVal *getValue(const Init *Name) const { diff --git a/llvm/lib/Analysis/AssumeBundleQueries.cpp b/llvm/lib/Analysis/AssumeBundleQueries.cpp index 0084e2f13f5f9..273b38a9567e5 100644 --- a/llvm/lib/Analysis/AssumeBundleQueries.cpp +++ b/llvm/lib/Analysis/AssumeBundleQueries.cpp @@ -157,9 +157,8 @@ llvm::getKnowledgeFromUse(const Use *U, return RetainedKnowledge::none(); RetainedKnowledge RK = getKnowledgeFromBundle(*cast(U->getUser()), *Bundle); - for (auto Attr : AttrKinds) - if (Attr == RK.AttrKind) - return RK; + if (llvm::is_contained(AttrKinds, RK.AttrKind)) + return RK; return RetainedKnowledge::none(); } diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index da894ef45bb25..b298c4285503f 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -616,15 +616,7 @@ bool Loop::isAnnotatedParallel() const { if (!LoopIdMD) return false; - bool LoopIdMDFound = false; - for (const MDOperand &MDOp : LoopIdMD->operands()) { - if (MDOp == DesiredLoopIdMetadata) { - LoopIdMDFound = true; - break; - } - } - - if (!LoopIdMDFound) + if (!llvm::is_contained(LoopIdMD->operands(), DesiredLoopIdMetadata)) return false; } } diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index 5565b9cededac..0379dbd0dcedc 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -222,10 +222,8 @@ MachineModuleInfo::getAddrLabelSymbolToEmit(const BasicBlock *BB) { /// \{ void MachineModuleInfo::addPersonality(const Function *Personality) { - for (unsigned i = 0; i < Personalities.size(); ++i) - if (Personalities[i] == Personality) - return; - Personalities.push_back(Personality); + if (!llvm::is_contained(Personalities, Personality)) + Personalities.push_back(Personality); } /// \} diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp index ed16ca20acecd..dbdc20fb4f8fe 100644 --- a/llvm/lib/CodeGen/MachineVerifier.cpp +++ b/llvm/lib/CodeGen/MachineVerifier.cpp @@ -2181,12 +2181,8 @@ void MachineVerifier::checkLiveness(const MachineOperand *MO, unsigned MONum) { if (!Register::isPhysicalRegister(MOP.getReg())) continue; - for (const MCPhysReg &SubReg : TRI->subregs(MOP.getReg())) { - if (SubReg == Reg) { - Bad = false; - break; - } - } + if (llvm::is_contained(TRI->subregs(MOP.getReg()), Reg)) + Bad = false; } } if (Bad) diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index 2a6b3eb19dedb..5a0c8976cf516 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -204,10 +204,7 @@ static Error optimizeELF_x86_64_GOTAndStubs(LinkGraph &G) { } static bool isDwarfSection(StringRef SectionName) { - for (auto &DwarfSectionName : DwarfSectionNames) - if (SectionName == DwarfSectionName) - return true; - return false; + return llvm::is_contained(DwarfSectionNames, SectionName); } namespace llvm { diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index e39cb732add10..8e6b6a373a2e2 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -247,11 +247,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, setStr(Sym.IRName, GV->getName()); - bool IsBuiltinFunc = false; - - for (const char *LibcallName : LibcallRoutineNames) - if (GV->getName() == LibcallName) - IsBuiltinFunc = true; + bool IsBuiltinFunc = llvm::is_contained(LibcallRoutineNames, GV->getName()); if (Used.count(GV) || IsBuiltinFunc) Sym.Flags |= 1 << storage::Symbol::FB_used; diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index 86aaab5a8156d..601957034489e 100644 --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -782,11 +782,7 @@ bool PrintIRInstrumentation::shouldPrintBeforePass(StringRef PassID) { return true; StringRef PassName = PIC->getPassNameForClassName(PassID); - for (const auto &P : printBeforePasses()) { - if (PassName == P) - return true; - } - return false; + return llvm::is_contained(printBeforePasses(), PassName); } bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) { @@ -794,11 +790,7 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) { return true; StringRef PassName = PIC->getPassNameForClassName(PassID); - for (const auto &P : printAfterPasses()) { - if (PassName == P) - return true; - } - return false; + return llvm::is_contained(printAfterPasses(), PassName); } void PrintIRInstrumentation::registerCallbacks( diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 18348b4c96417..13212098514d3 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2715,10 +2715,8 @@ Init *RecordResolver::resolve(Init *VarName) { if (Val) return Val; - for (Init *S : Stack) { - if (S == VarName) - return nullptr; // prevent infinite recursion - } + if (llvm::is_contained(Stack, VarName)) + return nullptr; // prevent infinite recursion if (RecordVal *RV = getCurrentRecord()->getValue(VarName)) { if (!isa(RV->getValue())) { diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp index b6a69b2819ee0..4a9d5cded732d 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp @@ -1419,11 +1419,7 @@ void AMDGPUMachineCFGStructurizer::extractKilledPHIs(MachineBasicBlock *MBB) { static bool isPHIRegionIndex(SmallVector PHIRegionIndices, unsigned Index) { - for (auto i : PHIRegionIndices) { - if (i == Index) - return true; - } - return false; + llvm::is_contained(PHIRegionIndices, Index); } bool AMDGPUMachineCFGStructurizer::shrinkPHI(MachineInstr &PHI, diff --git a/llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp b/llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp index 2f23e8643720c..7d5880de18460 100644 --- a/llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp +++ b/llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp @@ -1370,10 +1370,8 @@ bool HexagonHardwareLoops::isLoopFeeder(MachineLoop *L, MachineBasicBlock *A, LLVM_DEBUG(dbgs() << "\nhw_loop head, " << printMBBReference(**L->block_begin())); // Ignore all BBs that form Loop. - for (MachineBasicBlock *MBB : L->getBlocks()) { - if (A == MBB) - return false; - } + if (llvm::is_contained(L->getBlocks(), A)) + return false; MachineInstr *Def = MRI->getVRegDef(MO->getReg()); LoopFeederPhi.insert(std::make_pair(MO->getReg(), Def)); return true; diff --git a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp index 2692c08b93def..03aa88d31e6e4 100644 --- a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp +++ b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp @@ -60,10 +60,7 @@ CheckTy0Ty1MemSizeAlign(const LegalityQuery &Query, static bool CheckTyN(unsigned N, const LegalityQuery &Query, std::initializer_list SupportedValues) { - for (auto &Val : SupportedValues) - if (Val == Query.Types[N]) - return true; - return false; + return llvm::is_contained(SupportedValues, Query.Types[N]); } MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) { diff --git a/llvm/lib/Target/X86/X86SelectionDAGInfo.cpp b/llvm/lib/Target/X86/X86SelectionDAGInfo.cpp index e76908ef4bc40..a3238e6317a09 100644 --- a/llvm/lib/Target/X86/X86SelectionDAGInfo.cpp +++ b/llvm/lib/Target/X86/X86SelectionDAGInfo.cpp @@ -41,11 +41,7 @@ bool X86SelectionDAGInfo::isBaseRegConflictPossible( const X86RegisterInfo *TRI = static_cast( DAG.getSubtarget().getRegisterInfo()); - Register BaseReg = TRI->getBaseRegister(); - for (unsigned R : ClobberSet) - if (BaseReg == R) - return true; - return false; + return llvm::is_contained(ClobberSet, TRI->getBaseRegister()); } SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset( diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index d34634111ecf0..7dd9e71aedce4 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -986,13 +986,8 @@ promoteArguments(Function *F, function_ref AARGetter, // function, we could end up infinitely peeling the function argument. if (isSelfRecursive) { if (StructType *STy = dyn_cast(AgTy)) { - bool RecursiveType = false; - for (const auto *EltTy : STy->elements()) { - if (EltTy == PtrArg->getType()) { - RecursiveType = true; - break; - } - } + bool RecursiveType = + llvm::is_contained(STy->elements(), PtrArg->getType()); if (RecursiveType) continue; } diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 0057c35570cc8..df44e5010c61a 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -207,9 +207,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU, // Can't merge if there is PHI loop. for (PHINode &PN : BB->phis()) - for (Value *IncValue : PN.incoming_values()) - if (IncValue == &PN) - return false; + if (llvm::is_contained(PN.incoming_values(), &PN)) + return false; LLVM_DEBUG(dbgs() << "Merging: " << BB->getName() << " into " << PredBB->getName() << "\n"); diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 6dbfb0b61fea2..518238d59e27e 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -2675,9 +2675,8 @@ bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint, if (InsertionPoint->getParent()->getTerminator() == InsertionPoint) return true; if (const SCEVUnknown *U = dyn_cast(S)) - for (const Value *V : InsertionPoint->operand_values()) - if (V == U->getValue()) - return true; + if (llvm::is_contained(InsertionPoint->operand_values(), U->getValue())) + return true; } return false; } diff --git a/llvm/tools/llvm-xray/xray-graph-diff.cpp b/llvm/tools/llvm-xray/xray-graph-diff.cpp index 11210e2004a7a..9ff84f22d8245 100644 --- a/llvm/tools/llvm-xray/xray-graph-diff.cpp +++ b/llvm/tools/llvm-xray/xray-graph-diff.cpp @@ -294,10 +294,7 @@ static Twine truncateString(const StringRef &S, size_t n) { } template static bool containsNullptr(const T &Collection) { - for (const auto &E : Collection) - if (E == nullptr) - return true; - return false; + return llvm::is_contained(Collection, nullptr); } static std::string getLabel(const GraphDiffRenderer::GraphT::EdgeValueType &E, diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 765581bc46209..e7ba330bb6179 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -484,9 +484,8 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) { "amdgpu-unify-metadata", "amdgpu-printf-runtime-binding", "amdgpu-always-inline"}; - for (const auto &P : PassNameExactToIgnore) - if (Pass == P) - return false; + if (llvm::is_contained(PassNameExactToIgnore, Pass)) + return false; std::vector PassNamePrefix = { "x86-", "xcore-", "wasm-", "systemz-", "ppc-", "nvvm-", "nvptx-", @@ -511,10 +510,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) { for (const auto &P : PassNameContain) if (Pass.contains(P)) return true; - for (const auto &P : PassNameExact) - if (Pass == P) - return true; - return false; + return llvm::is_contained(PassNameExact, Pass); } // For use in NPM transition.