From ff49587cde7899b5f20e5bb8c836f023bff46d4f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 14 Feb 2021 08:36:20 -0800 Subject: [PATCH] [llvm] Use llvm::is_contained (NFC) --- include/llvm/IR/DataLayout.h | 5 +---- include/llvm/TableGen/Record.h | 4 +--- lib/Analysis/AssumeBundleQueries.cpp | 5 ++--- lib/Analysis/LoopInfo.cpp | 10 +--------- lib/CodeGen/MachineModuleInfo.cpp | 6 ++---- lib/CodeGen/MachineVerifier.cpp | 8 ++------ lib/ExecutionEngine/JITLink/ELF_x86_64.cpp | 5 +---- lib/Object/IRSymtab.cpp | 6 +----- lib/Passes/StandardInstrumentations.cpp | 12 ++---------- lib/TableGen/Record.cpp | 6 ++---- lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp | 6 +----- lib/Target/Hexagon/HexagonHardwareLoops.cpp | 6 ++---- lib/Target/Mips/MipsLegalizerInfo.cpp | 5 +---- lib/Target/X86/X86SelectionDAGInfo.cpp | 6 +----- lib/Transforms/IPO/ArgumentPromotion.cpp | 9 ++------- lib/Transforms/Utils/BasicBlockUtils.cpp | 5 ++--- lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 5 ++--- tools/llvm-xray/xray-graph-diff.cpp | 5 +---- tools/opt/opt.cpp | 10 +++------- 19 files changed, 30 insertions(+), 94 deletions(-) diff --git a/include/llvm/IR/DataLayout.h b/include/llvm/IR/DataLayout.h index eb031613a93..eae409e7529 100644 --- a/include/llvm/IR/DataLayout.h +++ b/include/llvm/IR/DataLayout.h @@ -260,10 +260,7 @@ public: /// /// 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/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index b79de83ac69..e75b7f01c86 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1568,9 +1568,7 @@ public: 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/lib/Analysis/AssumeBundleQueries.cpp b/lib/Analysis/AssumeBundleQueries.cpp index 0084e2f13f5..273b38a9567 100644 --- a/lib/Analysis/AssumeBundleQueries.cpp +++ b/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/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index da894ef45bb..b298c428550 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/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/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 5565b9ceded..0379dbd0dce 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/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/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index ed16ca20ace..dbdc20fb4f8 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/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/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index 2a6b3eb19de..5a0c8976cf5 100644 --- a/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/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/lib/Object/IRSymtab.cpp b/lib/Object/IRSymtab.cpp index e39cb732add..8e6b6a373a2 100644 --- a/lib/Object/IRSymtab.cpp +++ b/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/lib/Passes/StandardInstrumentations.cpp b/lib/Passes/StandardInstrumentations.cpp index 86aaab5a815..60195703448 100644 --- a/lib/Passes/StandardInstrumentations.cpp +++ b/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/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 18348b4c964..13212098514 100644 --- a/lib/TableGen/Record.cpp +++ b/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/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp b/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp index b6a69b2819e..4a9d5cded73 100644 --- a/lib/Target/AMDGPU/AMDGPUMachineCFGStructurizer.cpp +++ b/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/lib/Target/Hexagon/HexagonHardwareLoops.cpp b/lib/Target/Hexagon/HexagonHardwareLoops.cpp index 2f23e864372..7d5880de184 100644 --- a/lib/Target/Hexagon/HexagonHardwareLoops.cpp +++ b/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/lib/Target/Mips/MipsLegalizerInfo.cpp b/lib/Target/Mips/MipsLegalizerInfo.cpp index 2692c08b93d..03aa88d31e6 100644 --- a/lib/Target/Mips/MipsLegalizerInfo.cpp +++ b/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/lib/Target/X86/X86SelectionDAGInfo.cpp b/lib/Target/X86/X86SelectionDAGInfo.cpp index e76908ef4bc..a3238e6317a 100644 --- a/lib/Target/X86/X86SelectionDAGInfo.cpp +++ b/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/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index d34634111ec..7dd9e71aedc 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/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/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 0057c35570c..df44e5010c6 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/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/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 6dbfb0b61fe..518238d59e2 100644 --- a/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/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/tools/llvm-xray/xray-graph-diff.cpp b/tools/llvm-xray/xray-graph-diff.cpp index 11210e2004a..9ff84f22d82 100644 --- a/tools/llvm-xray/xray-graph-diff.cpp +++ b/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/tools/opt/opt.cpp b/tools/opt/opt.cpp index 765581bc462..e7ba330bb61 100644 --- a/tools/opt/opt.cpp +++ b/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.