[llvm] Use llvm::is_contained (NFC)

This commit is contained in:
Kazu Hirata 2021-02-14 08:36:20 -08:00
parent 955b5e24b3
commit ff49587cde
19 changed files with 30 additions and 94 deletions

View File

@ -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); }

View File

@ -1568,9 +1568,7 @@ public:
void getDirectSuperClasses(SmallVectorImpl<Record *> &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 {

View File

@ -157,9 +157,8 @@ llvm::getKnowledgeFromUse(const Use *U,
return RetainedKnowledge::none();
RetainedKnowledge RK =
getKnowledgeFromBundle(*cast<CallInst>(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();
}

View File

@ -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;
}
}

View File

@ -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);
}
/// \}

View File

@ -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)

View File

@ -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 {

View File

@ -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;

View File

@ -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(

View File

@ -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<UnsetInit>(RV->getValue())) {

View File

@ -1419,11 +1419,7 @@ void AMDGPUMachineCFGStructurizer::extractKilledPHIs(MachineBasicBlock *MBB) {
static bool isPHIRegionIndex(SmallVector<unsigned, 2> PHIRegionIndices,
unsigned Index) {
for (auto i : PHIRegionIndices) {
if (i == Index)
return true;
}
return false;
llvm::is_contained(PHIRegionIndices, Index);
}
bool AMDGPUMachineCFGStructurizer::shrinkPHI(MachineInstr &PHI,

View File

@ -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;

View File

@ -60,10 +60,7 @@ CheckTy0Ty1MemSizeAlign(const LegalityQuery &Query,
static bool CheckTyN(unsigned N, const LegalityQuery &Query,
std::initializer_list<LLT> 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) {

View File

@ -41,11 +41,7 @@ bool X86SelectionDAGInfo::isBaseRegConflictPossible(
const X86RegisterInfo *TRI = static_cast<const X86RegisterInfo *>(
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(

View File

@ -986,13 +986,8 @@ promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
// function, we could end up infinitely peeling the function argument.
if (isSelfRecursive) {
if (StructType *STy = dyn_cast<StructType>(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;
}

View File

@ -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");

View File

@ -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<SCEVUnknown>(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;
}

View File

@ -294,10 +294,7 @@ static Twine truncateString(const StringRef &S, size_t n) {
}
template <typename T> 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,

View File

@ -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<StringRef> 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.