Skip to content

Commit fdaa742

Browse files
committed
Second attempt to add iterator_range::empty()
Doing this makes MSVC complain that `empty(someRange)` could refer to either C++17's std::empty or LLVM's llvm::empty, which previously we avoided via SFINAE because std::empty is defined in terms of an empty member rather than begin and end. So, switch callers over to the new method as it is added. https://reviews.llvm.org/D68439 llvm-svn: 373935
1 parent f385a38 commit fdaa742

19 files changed

+33
-32
lines changed

llvm/include/llvm/ADT/iterator_range.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class iterator_range {
4444

4545
IteratorT begin() const { return begin_iterator; }
4646
IteratorT end() const { return end_iterator; }
47+
bool empty() const { return begin_iterator == end_iterator; }
4748
};
4849

4950
/// Convenience function for iterating over sub-ranges.

llvm/lib/Analysis/LazyCallGraph.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ LazyCallGraph::RefSCC::switchInternalEdgeToCall(
632632

633633
// If the merge range is empty, then adding the edge didn't actually form any
634634
// new cycles. We're done.
635-
if (empty(MergeRange)) {
635+
if (MergeRange.empty()) {
636636
// Now that the SCC structure is finalized, flip the kind to call.
637637
SourceN->setEdgeKind(TargetN, Edge::Call);
638638
return false; // No new cycle.

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ void DwarfDebug::finalizeModuleInfo() {
10541054
// If we're splitting the dwarf out now that we've got the entire
10551055
// CU then add the dwo id to it.
10561056
auto *SkCU = TheCU.getSkeleton();
1057-
if (useSplitDwarf() && !empty(TheCU.getUnitDie().children())) {
1057+
if (useSplitDwarf() && !TheCU.getUnitDie().children().empty()) {
10581058
finishUnitAttributes(TheCU.getCUNode(), TheCU);
10591059
TheCU.addString(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_name,
10601060
Asm->TM.Options.MCOptions.SplitDwarfFile);
@@ -1106,7 +1106,7 @@ void DwarfDebug::finalizeModuleInfo() {
11061106
// is a bit pessimistic under LTO.
11071107
if (!AddrPool.isEmpty() &&
11081108
(getDwarfVersion() >= 5 ||
1109-
(SkCU && !empty(TheCU.getUnitDie().children()))))
1109+
(SkCU && !TheCU.getUnitDie().children().empty())))
11101110
U.addAddrTableBase();
11111111

11121112
if (getDwarfVersion() >= 5) {

llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ bool InstructionSelector::isObviouslySafeToFold(MachineInstr &MI,
7979
return true;
8080

8181
return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
82-
!MI.hasUnmodeledSideEffects() && empty(MI.implicit_operands());
82+
!MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty();
8383
}

llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ LegalizeRuleSet &LegalizerInfo::getActionDefinitionsBuilder(
433433
std::initializer_list<unsigned> Opcodes) {
434434
unsigned Representative = *Opcodes.begin();
435435

436-
assert(!empty(Opcodes) && Opcodes.begin() + 1 != Opcodes.end() &&
436+
assert(!llvm::empty(Opcodes) && Opcodes.begin() + 1 != Opcodes.end() &&
437437
"Initializer list must have at least two opcodes");
438438

439439
for (auto I = Opcodes.begin() + 1, E = Opcodes.end(); I != E; ++I)

llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool RegBankSelect::repairReg(
139139
"need new vreg for each breakdown");
140140

141141
// An empty range of new register means no repairing.
142-
assert(!empty(NewVRegs) && "We should not have to repair");
142+
assert(!NewVRegs.empty() && "We should not have to repair");
143143

144144
MachineInstr *MI;
145145
if (ValMapping.NumBreakDowns == 1) {

llvm/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void RegisterBankInfo::applyDefaultMapping(const OperandsMapper &OpdMapper) {
455455
"This mapping is too complex for this function");
456456
iterator_range<SmallVectorImpl<Register>::const_iterator> NewRegs =
457457
OpdMapper.getVRegs(OpIdx);
458-
if (empty(NewRegs)) {
458+
if (NewRegs.empty()) {
459459
LLVM_DEBUG(dbgs() << " has not been repaired, nothing to be done\n");
460460
continue;
461461
}

llvm/lib/CodeGen/MachineModuleInfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ char MachineModuleInfoWrapperPass::ID = 0;
346346
bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
347347
MMI.initialize();
348348
MMI.TheModule = &M;
349-
MMI.DbgInfoAvailable = !empty(M.debug_compile_units());
349+
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
350350
return false;
351351
}
352352

@@ -361,6 +361,6 @@ MachineModuleInfo MachineModuleAnalysis::run(Module &M,
361361
ModuleAnalysisManager &) {
362362
MachineModuleInfo MMI(TM);
363363
MMI.TheModule = &M;
364-
MMI.DbgInfoAvailable = !empty(M.debug_compile_units());
364+
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
365365
return MMI;
366366
}

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ iterator_range<CtorDtorIterator> getDestructors(const Module &M) {
8888
}
8989

9090
void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) {
91-
if (empty(CtorDtors))
91+
if (CtorDtors.empty())
9292
return;
9393

9494
MangleAndInterner Mangle(

llvm/lib/IR/DebugInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ bool DebugInfoFinder::addScope(DIScope *Scope) {
279279
}
280280

281281
static MDNode *stripDebugLocFromLoopID(MDNode *N) {
282-
assert(!empty(N->operands()) && "Missing self reference?");
282+
assert(!N->operands().empty() && "Missing self reference?");
283283

284284
// if there is no debug location, we do not have to rewrite this MDNode.
285285
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {

llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
15881588
if (DstTy != LLT::vector(2, 16))
15891589
break;
15901590

1591-
assert(MI.getNumOperands() == 3 && empty(OpdMapper.getVRegs(0)));
1591+
assert(MI.getNumOperands() == 3 && OpdMapper.getVRegs(0).empty());
15921592
substituteSimpleCopyRegs(OpdMapper, 1);
15931593
substituteSimpleCopyRegs(OpdMapper, 2);
15941594

@@ -1644,7 +1644,7 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
16441644
case AMDGPU::G_EXTRACT_VECTOR_ELT: {
16451645
SmallVector<Register, 2> DstRegs(OpdMapper.getVRegs(0));
16461646

1647-
assert(empty(OpdMapper.getVRegs(1)) && empty(OpdMapper.getVRegs(2)));
1647+
assert(OpdMapper.getVRegs(1).empty() && OpdMapper.getVRegs(2).empty());
16481648

16491649
if (DstRegs.empty()) {
16501650
applyDefaultMapping(OpdMapper);
@@ -1708,9 +1708,9 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
17081708
case AMDGPU::G_INSERT_VECTOR_ELT: {
17091709
SmallVector<Register, 2> InsRegs(OpdMapper.getVRegs(2));
17101710

1711-
assert(empty(OpdMapper.getVRegs(0)));
1712-
assert(empty(OpdMapper.getVRegs(1)));
1713-
assert(empty(OpdMapper.getVRegs(3)));
1711+
assert(OpdMapper.getVRegs(0).empty());
1712+
assert(OpdMapper.getVRegs(1).empty());
1713+
assert(OpdMapper.getVRegs(3).empty());
17141714

17151715
if (InsRegs.empty()) {
17161716
applyDefaultMapping(OpdMapper);
@@ -1785,18 +1785,18 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
17851785
case Intrinsic::amdgcn_readlane: {
17861786
substituteSimpleCopyRegs(OpdMapper, 2);
17871787

1788-
assert(empty(OpdMapper.getVRegs(0)));
1789-
assert(empty(OpdMapper.getVRegs(3)));
1788+
assert(OpdMapper.getVRegs(0).empty());
1789+
assert(OpdMapper.getVRegs(3).empty());
17901790

17911791
// Make sure the index is an SGPR. It doesn't make sense to run this in a
17921792
// waterfall loop, so assume it's a uniform value.
17931793
constrainOpWithReadfirstlane(MI, MRI, 3); // Index
17941794
return;
17951795
}
17961796
case Intrinsic::amdgcn_writelane: {
1797-
assert(empty(OpdMapper.getVRegs(0)));
1798-
assert(empty(OpdMapper.getVRegs(2)));
1799-
assert(empty(OpdMapper.getVRegs(3)));
1797+
assert(OpdMapper.getVRegs(0).empty());
1798+
assert(OpdMapper.getVRegs(2).empty());
1799+
assert(OpdMapper.getVRegs(3).empty());
18001800

18011801
substituteSimpleCopyRegs(OpdMapper, 4); // VGPR input val
18021802
constrainOpWithReadfirstlane(MI, MRI, 2); // Source value
@@ -1818,7 +1818,7 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
18181818
case Intrinsic::amdgcn_ds_ordered_add:
18191819
case Intrinsic::amdgcn_ds_ordered_swap: {
18201820
// This is only allowed to execute with 1 lane, so readfirstlane is safe.
1821-
assert(empty(OpdMapper.getVRegs(0)));
1821+
assert(OpdMapper.getVRegs(0).empty());
18221822
substituteSimpleCopyRegs(OpdMapper, 3);
18231823
constrainOpWithReadfirstlane(MI, MRI, 2); // M0
18241824
return;

llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ bool BPFAbstractMemberAccess::runOnModule(Module &M) {
147147
LLVM_DEBUG(dbgs() << "********** Abstract Member Accesses **********\n");
148148

149149
// Bail out if no debug info.
150-
if (empty(M.debug_compile_units()))
150+
if (M.debug_compile_units().empty())
151151
return false;
152152

153153
return doTransformation(M);

llvm/lib/Target/BPF/BPFAsmPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool BPFAsmPrinter::doInitialization(Module &M) {
5959
AsmPrinter::doInitialization(M);
6060

6161
// Only emit BTF when debuginfo available.
62-
if (MAI->doesSupportDebugInformation() && !empty(M.debug_compile_units())) {
62+
if (MAI->doesSupportDebugInformation() && !M.debug_compile_units().empty()) {
6363
BTF = new BTFDebug(this);
6464
Handlers.push_back(HandlerInfo(std::unique_ptr<BTFDebug>(BTF), "emit",
6565
"Debug Info Emission", "BTF",

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ void PPCInstrInfo::replaceInstrOperandWithImm(MachineInstr &MI,
22732273
Register InUseReg = MI.getOperand(OpNo).getReg();
22742274
MI.getOperand(OpNo).ChangeToImmediate(Imm);
22752275

2276-
if (empty(MI.implicit_operands()))
2276+
if (MI.implicit_operands().empty())
22772277
return;
22782278

22792279
// We need to make sure that the MI didn't have any implicit use

llvm/lib/Transforms/IPO/PartialInlining.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ std::pair<bool, Function *> PartialInlinerImpl::unswitchFunction(Function *F) {
12641264
if (PSI->isFunctionEntryCold(F))
12651265
return {false, nullptr};
12661266

1267-
if (empty(F->users()))
1267+
if (F->users().empty())
12681268
return {false, nullptr};
12691269

12701270
OptimizationRemarkEmitter ORE(F);
@@ -1370,7 +1370,7 @@ bool PartialInlinerImpl::tryPartialInline(FunctionCloner &Cloner) {
13701370
return false;
13711371
}
13721372

1373-
assert(empty(Cloner.OrigFunc->users()) &&
1373+
assert(Cloner.OrigFunc->users().empty() &&
13741374
"F's users should all be replaced!");
13751375

13761376
std::vector<User *> Users(Cloner.ClonedFunc->user_begin(),

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,7 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
27892789
// have already been removed; TODO: generalize
27902790
BasicBlock *ExitBlock =
27912791
BI->getSuccessor(L->contains(BI->getSuccessor(0)) ? 1 : 0);
2792-
if (!empty(ExitBlock->phis()))
2792+
if (!ExitBlock->phis().empty())
27932793
return true;
27942794

27952795
const SCEV *ExitCount = SE->getExitCount(L, ExitingBB);

llvm/lib/Transforms/Scalar/NewGVN.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ NewGVN::performSymbolicPHIEvaluation(ArrayRef<ValPair> PHIOps,
17541754
return true;
17551755
});
17561756
// If we are left with no operands, it's dead.
1757-
if (empty(Filtered)) {
1757+
if (Filtered.empty()) {
17581758
// If it has undef at this point, it means there are no-non-undef arguments,
17591759
// and thus, the value of the phi node must be undef.
17601760
if (HasUndef) {

llvm/lib/Transforms/Utils/PredicateInfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ Value *PredicateInfo::materializeStack(unsigned int &Counter,
556556
if (isa<PredicateWithEdge>(ValInfo)) {
557557
IRBuilder<> B(getBranchTerminator(ValInfo));
558558
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
559-
if (empty(IF->users()))
559+
if (IF->users().empty())
560560
CreatedDeclarations.insert(IF);
561561
CallInst *PIC =
562562
B.CreateCall(IF, Op, Op->getName() + "." + Twine(Counter++));
@@ -568,7 +568,7 @@ Value *PredicateInfo::materializeStack(unsigned int &Counter,
568568
"Should not have gotten here without it being an assume");
569569
IRBuilder<> B(PAssume->AssumeInst);
570570
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
571-
if (empty(IF->users()))
571+
if (IF->users().empty())
572572
CreatedDeclarations.insert(IF);
573573
CallInst *PIC = B.CreateCall(IF, Op);
574574
PredicateMap.insert({PIC, ValInfo});

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5314,7 +5314,7 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
53145314

53155315
// Figure out the corresponding result for each case value and phi node in the
53165316
// common destination, as well as the min and max case values.
5317-
assert(!empty(SI->cases()));
5317+
assert(!SI->cases().empty());
53185318
SwitchInst::CaseIt CI = SI->case_begin();
53195319
ConstantInt *MinCaseVal = CI->getCaseValue();
53205320
ConstantInt *MaxCaseVal = CI->getCaseValue();

0 commit comments

Comments
 (0)