Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 4dd8558

Browse files
authored
Second attempt to add iterator_range::empty() (#174)
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373935 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ffbe03a commit 4dd8558

File tree

15 files changed

+18
-17
lines changed

15 files changed

+18
-17
lines changed

include/llvm/ADT/iterator_range.h

Lines changed: 1 addition & 0 deletions
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.

lib/Analysis/LazyCallGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ LazyCallGraph::RefSCC::switchInternalEdgeToCall(
631631

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

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ void DwarfDebug::finalizeModuleInfo() {
902902
// If we're splitting the dwarf out now that we've got the entire
903903
// CU then add the dwo id to it.
904904
auto *SkCU = TheCU.getSkeleton();
905-
if (useSplitDwarf() && !empty(TheCU.getUnitDie().children())) {
905+
if (useSplitDwarf() && !TheCU.getUnitDie().children().empty()) {
906906
finishUnitAttributes(TheCU.getCUNode(), TheCU);
907907
TheCU.addString(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_name,
908908
Asm->TM.Options.MCOptions.SplitDwarfFile);
@@ -954,7 +954,7 @@ void DwarfDebug::finalizeModuleInfo() {
954954
// is a bit pessimistic under LTO.
955955
if (!AddrPool.isEmpty() &&
956956
(getDwarfVersion() >= 5 ||
957-
(SkCU && !empty(TheCU.getUnitDie().children()))))
957+
(SkCU && !TheCU.getUnitDie().children().empty())))
958958
U.addAddrTableBase();
959959

960960
if (getDwarfVersion() >= 5) {

lib/CodeGen/GlobalISel/InstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
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
}

lib/CodeGen/GlobalISel/LegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ LegalizeRuleSet &LegalizerInfo::getActionDefinitionsBuilder(
412412
std::initializer_list<unsigned> Opcodes) {
413413
unsigned Representative = *Opcodes.begin();
414414

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

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

lib/CodeGen/GlobalISel/RegBankSelect.cpp

Lines changed: 1 addition & 1 deletion
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) {

lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

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

lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ iterator_range<CtorDtorIterator> getDestructors(const Module &M) {
8787
}
8888

8989
void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) {
90-
if (empty(CtorDtors))
90+
if (CtorDtors.empty())
9191
return;
9292

9393
MangleAndInterner Mangle(

lib/IR/DebugInfo.cpp

Lines changed: 1 addition & 1 deletion
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) {

lib/Target/BPF/BPFAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool BPFAsmPrinter::doInitialization(Module &M) {
5656
AsmPrinter::doInitialization(M);
5757

5858
// Only emit BTF when debuginfo available.
59-
if (MAI->doesSupportDebugInformation() && !empty(M.debug_compile_units())) {
59+
if (MAI->doesSupportDebugInformation() && !M.debug_compile_units().empty()) {
6060
Handlers.emplace_back(llvm::make_unique<BTFDebug>(this), "emit",
6161
"Debug Info Emission", "BTF", "BTF Emission");
6262
}

lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ void PPCInstrInfo::replaceInstrOperandWithImm(MachineInstr &MI,
22822282
unsigned InUseReg = MI.getOperand(OpNo).getReg();
22832283
MI.getOperand(OpNo).ChangeToImmediate(Imm);
22842284

2285-
if (empty(MI.implicit_operands()))
2285+
if (MI.implicit_operands().empty())
22862286
return;
22872287

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

lib/Transforms/IPO/PartialInlining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ std::pair<bool, Function *> PartialInlinerImpl::unswitchFunction(Function *F) {
12681268
if (PSI->isFunctionEntryCold(F))
12691269
return {false, nullptr};
12701270

1271-
if (empty(F->users()))
1271+
if (F->users().empty())
12721272
return {false, nullptr};
12731273

12741274
OptimizationRemarkEmitter ORE(F);
@@ -1374,7 +1374,7 @@ bool PartialInlinerImpl::tryPartialInline(FunctionCloner &Cloner) {
13741374
return false;
13751375
}
13761376

1377-
assert(empty(Cloner.OrigFunc->users()) &&
1377+
assert(Cloner.OrigFunc->users().empty() &&
13781378
"F's users should all be replaced!");
13791379

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

lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 1 addition & 1 deletion
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) {

lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ Value *PredicateInfo::materializeStack(unsigned int &Counter,
524524
if (isa<PredicateWithEdge>(ValInfo)) {
525525
IRBuilder<> B(getBranchTerminator(ValInfo));
526526
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
527-
if (empty(IF->users()))
527+
if (IF->users().empty())
528528
CreatedDeclarations.insert(IF);
529529
CallInst *PIC =
530530
B.CreateCall(IF, Op, Op->getName() + "." + Twine(Counter++));
@@ -536,7 +536,7 @@ Value *PredicateInfo::materializeStack(unsigned int &Counter,
536536
"Should not have gotten here without it being an assume");
537537
IRBuilder<> B(PAssume->AssumeInst);
538538
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
539-
if (empty(IF->users()))
539+
if (IF->users().empty())
540540
CreatedDeclarations.insert(IF);
541541
CallInst *PIC = B.CreateCall(IF, Op);
542542
PredicateMap.insert({PIC, ValInfo});

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5260,7 +5260,7 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
52605260

52615261
// Figure out the corresponding result for each case value and phi node in the
52625262
// common destination, as well as the min and max case values.
5263-
assert(!empty(SI->cases()));
5263+
assert(!SI->cases().empty());
52645264
SwitchInst::CaseIt CI = SI->case_begin();
52655265
ConstantInt *MinCaseVal = CI->getCaseValue();
52665266
ConstantInt *MaxCaseVal = CI->getCaseValue();

0 commit comments

Comments
 (0)