[llvm] Use x.empty() instead of llvm::empty(x) (NFC)

I'm planning to deprecate and eventually remove llvm::empty.

I thought about replacing llvm::empty(x) with std::empty(x), but it
turns out that all uses can be converted to x.empty().  That is, no
use requires the ability of std::empty to accept C arrays and
std::initializer_list.

Differential Revision: https://reviews.llvm.org/D133677
This commit is contained in:
Kazu Hirata 2022-09-12 13:34:35 -07:00
parent 481a32f587
commit 9606608474
14 changed files with 23 additions and 28 deletions

View File

@ -774,7 +774,7 @@ class SectionRange {
public: public:
SectionRange() = default; SectionRange() = default;
SectionRange(const Section &Sec) { SectionRange(const Section &Sec) {
if (llvm::empty(Sec.blocks())) if (Sec.blocks().empty())
return; return;
First = Last = *Sec.blocks().begin(); First = Last = *Sec.blocks().begin();
for (auto *B : Sec.blocks()) { for (auto *B : Sec.blocks()) {

View File

@ -42,7 +42,7 @@ void DwarfFile::emitUnit(DwarfUnit *TheU, bool UseOffsets) {
// Skip CUs that ended up not being needed (split CUs that were abandoned // Skip CUs that ended up not being needed (split CUs that were abandoned
// because they added no information beyond the non-split CU) // because they added no information beyond the non-split CU)
if (llvm::empty(TheU->getUnitDie().values())) if (TheU->getUnitDie().values().empty())
return; return;
Asm->OutStreamer->switchSection(S); Asm->OutStreamer->switchSection(S);
@ -66,7 +66,7 @@ void DwarfFile::computeSizeAndOffsets() {
// Skip CUs that ended up not being needed (split CUs that were abandoned // Skip CUs that ended up not being needed (split CUs that were abandoned
// because they added no information beyond the non-split CU) // because they added no information beyond the non-split CU)
if (llvm::empty(TheU->getUnitDie().values())) if (TheU->getUnitDie().values().empty())
return; return;
TheU->setDebugSectionOffset(SecOffset); TheU->setDebugSectionOffset(SecOffset);

View File

@ -309,14 +309,14 @@ void LinkGraph::dump(raw_ostream &OS) {
} }
OS << "Absolute symbols:\n"; OS << "Absolute symbols:\n";
if (!llvm::empty(absolute_symbols())) { if (!absolute_symbols().empty()) {
for (auto *Sym : absolute_symbols()) for (auto *Sym : absolute_symbols())
OS << " " << Sym->getAddress() << ": " << *Sym << "\n"; OS << " " << Sym->getAddress() << ": " << *Sym << "\n";
} else } else
OS << " none\n"; OS << " none\n";
OS << "\nExternal symbols:\n"; OS << "\nExternal symbols:\n";
if (!llvm::empty(external_symbols())) { if (!external_symbols().empty()) {
for (auto *Sym : external_symbols()) for (auto *Sym : external_symbols())
OS << " " << Sym->getAddress() << ": " << *Sym << "\n"; OS << " " << Sym->getAddress() << ": " << *Sym << "\n";
} else } else

View File

@ -25,7 +25,7 @@ BasicLayout::BasicLayout(LinkGraph &G) : G(G) {
for (auto &Sec : G.sections()) { for (auto &Sec : G.sections()) {
// Skip empty sections. // Skip empty sections.
if (empty(Sec.blocks())) if (Sec.blocks().empty())
continue; continue;
auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemDeallocPolicy()}]; auto &Seg = Segments[{Sec.getMemProt(), Sec.getMemDeallocPolicy()}];

View File

@ -137,7 +137,7 @@ public:
SmallVector<DebugSectionInfo, 12> DebugSecInfos; SmallVector<DebugSectionInfo, 12> DebugSecInfos;
size_t NumSections = 0; size_t NumSections = 0;
for (auto &Sec : G.sections()) { for (auto &Sec : G.sections()) {
if (llvm::empty(Sec.blocks())) if (Sec.blocks().empty())
continue; continue;
++NumSections; ++NumSections;
@ -189,7 +189,7 @@ public:
// Copy debug section blocks and symbols. // Copy debug section blocks and symbols.
orc::ExecutorAddr NextBlockAddr(MachOContainerBlock->getSize()); orc::ExecutorAddr NextBlockAddr(MachOContainerBlock->getSize());
for (auto &SI : DebugSecInfos) { for (auto &SI : DebugSecInfos) {
assert(!llvm::empty(SI.Sec->blocks()) && "Empty debug info section?"); assert(!SI.Sec->blocks().empty() && "Empty debug info section?");
// Update addresses in debug section. // Update addresses in debug section.
LLVM_DEBUG({ LLVM_DEBUG({

View File

@ -81,7 +81,7 @@ IRMaterializationUnit::IRMaterializationUnit(
} }
// If we need an init symbol for this module then create one. // If we need an init symbol for this module then create one.
if (!llvm::empty(getStaticInitGVs(M))) { if (!getStaticInitGVs(M).empty()) {
size_t Counter = 0; size_t Counter = 0;
do { do {

View File

@ -744,7 +744,7 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
auto ObjCImageInfoBlocks = ObjCImageInfo->blocks(); auto ObjCImageInfoBlocks = ObjCImageInfo->blocks();
// Check that the section is not empty if present. // Check that the section is not empty if present.
if (llvm::empty(ObjCImageInfoBlocks)) if (ObjCImageInfoBlocks.empty())
return make_error<StringError>("Empty " + ObjCImageInfoSectionName + return make_error<StringError>("Empty " + ObjCImageInfoSectionName +
" section in " + G.getName(), " section in " + G.getName(),
inconvertibleErrorCode()); inconvertibleErrorCode());

View File

@ -2539,7 +2539,7 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
LLT SrcTy = MRI.getType(SrcReg); LLT SrcTy = MRI.getType(SrcReg);
const bool Signed = Opc == AMDGPU::G_SEXT; const bool Signed = Opc == AMDGPU::G_SEXT;
assert(empty(OpdMapper.getVRegs(1))); assert(OpdMapper.getVRegs(1).empty());
MachineIRBuilder B(MI); MachineIRBuilder B(MI);
const RegisterBank *SrcBank = const RegisterBank *SrcBank =

View File

@ -274,9 +274,7 @@ bool X86FastISel::foldX86XALUIntrinsic(X86::CondCode &CC, const Instruction *I,
// Make sure no potentially eflags clobbering phi moves can be inserted in // Make sure no potentially eflags clobbering phi moves can be inserted in
// between. // between.
auto HasPhis = [](const BasicBlock *Succ) { auto HasPhis = [](const BasicBlock *Succ) { return !Succ->phis().empty(); };
return !llvm::empty(Succ->phis());
};
if (I->isTerminator() && llvm::any_of(successors(I), HasPhis)) if (I->isTerminator() && llvm::any_of(successors(I), HasPhis))
return false; return false;

View File

@ -1843,7 +1843,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop &L,
if (L.contains(Succ)) if (L.contains(Succ))
continue; continue;
Info.PathIsNoop &= llvm::empty(Succ->phis()) && Info.PathIsNoop &= Succ->phis().empty() &&
(!Info.ExitForPath || Info.ExitForPath == Succ); (!Info.ExitForPath || Info.ExitForPath == Succ);
if (!Info.PathIsNoop) if (!Info.PathIsNoop)
break; break;

View File

@ -80,13 +80,12 @@ Error registerCOFFGraphInfo(Session &S, LinkGraph &G) {
for (auto &Sec : G.sections()) { for (auto &Sec : G.sections()) {
LLVM_DEBUG({ LLVM_DEBUG({
dbgs() << " Section \"" << Sec.getName() << "\": " dbgs() << " Section \"" << Sec.getName() << "\": "
<< (llvm::empty(Sec.symbols()) ? "empty. skipping." << (Sec.symbols().empty() ? "empty. skipping." : "processing...")
: "processing...")
<< "\n"; << "\n";
}); });
// Skip empty sections. // Skip empty sections.
if (llvm::empty(Sec.symbols())) if (Sec.symbols().empty())
continue; continue;
if (FileInfo.SectionInfos.count(Sec.getName())) if (FileInfo.SectionInfos.count(Sec.getName()))

View File

@ -82,13 +82,12 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
for (auto &Sec : G.sections()) { for (auto &Sec : G.sections()) {
LLVM_DEBUG({ LLVM_DEBUG({
dbgs() << " Section \"" << Sec.getName() << "\": " dbgs() << " Section \"" << Sec.getName() << "\": "
<< (llvm::empty(Sec.symbols()) ? "empty. skipping." << (Sec.symbols().empty() ? "empty. skipping." : "processing...")
: "processing...")
<< "\n"; << "\n";
}); });
// Skip empty sections. // Skip empty sections.
if (llvm::empty(Sec.symbols())) if (Sec.symbols().empty())
continue; continue;
if (FileInfo.SectionInfos.count(Sec.getName())) if (FileInfo.SectionInfos.count(Sec.getName()))

View File

@ -84,13 +84,12 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) {
for (auto &Sec : G.sections()) { for (auto &Sec : G.sections()) {
LLVM_DEBUG({ LLVM_DEBUG({
dbgs() << " Section \"" << Sec.getName() << "\": " dbgs() << " Section \"" << Sec.getName() << "\": "
<< (llvm::empty(Sec.symbols()) ? "empty. skipping." << (Sec.symbols().empty() ? "empty. skipping." : "processing...")
: "processing...")
<< "\n"; << "\n";
}); });
// Skip empty sections. // Skip empty sections.
if (llvm::empty(Sec.symbols())) if (Sec.symbols().empty())
continue; continue;
if (FileInfo.SectionInfos.count(Sec.getName())) if (FileInfo.SectionInfos.count(Sec.getName()))

View File

@ -403,11 +403,11 @@ static void dumpSectionContents(raw_ostream &OS, LinkGraph &G) {
Sections.push_back(&S); Sections.push_back(&S);
llvm::sort(Sections, [](const Section *LHS, const Section *RHS) { llvm::sort(Sections, [](const Section *LHS, const Section *RHS) {
if (llvm::empty(LHS->symbols()) && llvm::empty(RHS->symbols())) if (LHS->symbols().empty() && RHS->symbols().empty())
return false; return false;
if (llvm::empty(LHS->symbols())) if (LHS->symbols().empty())
return false; return false;
if (llvm::empty(RHS->symbols())) if (RHS->symbols().empty())
return true; return true;
SectionRange LHSRange(*LHS); SectionRange LHSRange(*LHS);
SectionRange RHSRange(*RHS); SectionRange RHSRange(*RHS);
@ -416,7 +416,7 @@ static void dumpSectionContents(raw_ostream &OS, LinkGraph &G) {
for (auto *S : Sections) { for (auto *S : Sections) {
OS << S->getName() << " content:"; OS << S->getName() << " content:";
if (llvm::empty(S->symbols())) { if (S->symbols().empty()) {
OS << "\n section empty\n"; OS << "\n section empty\n";
continue; continue;
} }