[llvm] r345679 - ADT/STLExtras: Introduce llvm::empty; NFC
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 30 17:23:23 PDT 2018
Author: matze
Date: Tue Oct 30 17:23:23 2018
New Revision: 345679
URL: http://llvm.org/viewvc/llvm-project?rev=345679&view=rev
Log:
ADT/STLExtras: Introduce llvm::empty; NFC
This is modeled after C++17 std::empty().
Differential Revision: https://reviews.llvm.org/D53909
Modified:
llvm/trunk/include/llvm/ADT/STLExtras.h
llvm/trunk/lib/Analysis/LazyCallGraph.cpp
llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelector.cpp
llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
llvm/trunk/lib/IR/DebugInfo.cpp
llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
llvm/trunk/lib/Transforms/Utils/PredicateInfo.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/unittests/ADT/STLExtrasTest.cpp
Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Tue Oct 30 17:23:23 2018
@@ -195,6 +195,12 @@ void adl_swap(T &&lhs, T &&rhs) noexcept
adl_detail::adl_swap(std::forward<T>(lhs), std::forward<T>(rhs));
}
+/// Test whether \p RangeOrContainer is empty. Similar to C++17 std::empty.
+template <typename T>
+constexpr bool empty(const T &RangeOrContainer) {
+ return adl_begin(RangeOrContainer) == adl_end(RangeOrContainer);
+}
+
// mapped_iterator - This is a simple iterator adapter that causes a function to
// be applied whenever operator* is invoked on the iterator.
Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Tue Oct 30 17:23:23 2018
@@ -619,7 +619,7 @@ LazyCallGraph::RefSCC::switchInternalEdg
// If the merge range is empty, then adding the edge didn't actually form any
// new cycles. We're done.
- if (MergeRange.begin() == MergeRange.end()) {
+ if (empty(MergeRange)) {
// Now that the SCC structure is finalized, flip the kind to call.
SourceN->setEdgeKind(TargetN, Edge::Call);
return false; // No new cycle.
Modified: llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelector.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelector.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/InstructionSelector.cpp Tue Oct 30 17:23:23 2018
@@ -80,5 +80,5 @@ bool InstructionSelector::isObviouslySaf
return true;
return !MI.mayLoadOrStore() && !MI.hasUnmodeledSideEffects() &&
- MI.implicit_operands().begin() == MI.implicit_operands().end();
+ empty(MI.implicit_operands());
}
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerInfo.cpp Tue Oct 30 17:23:23 2018
@@ -298,8 +298,7 @@ LegalizeRuleSet &LegalizerInfo::getActio
std::initializer_list<unsigned> Opcodes) {
unsigned Representative = *Opcodes.begin();
- assert(Opcodes.begin() != Opcodes.end() &&
- Opcodes.begin() + 1 != Opcodes.end() &&
+ assert(!empty(Opcodes) && Opcodes.begin() + 1 != Opcodes.end() &&
"Initializer list must have at least two opcodes");
for (auto I = Opcodes.begin() + 1, E = Opcodes.end(); I != E; ++I)
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp Tue Oct 30 17:23:23 2018
@@ -140,7 +140,7 @@ bool RegBankSelect::repairReg(
return false;
assert(ValMapping.NumBreakDowns == 1 && "Not yet implemented");
// An empty range of new register means no repairing.
- assert(NewVRegs.begin() != NewVRegs.end() && "We should not have to repair");
+ assert(!empty(NewVRegs) && "We should not have to repair");
// Assume we are repairing a use and thus, the original reg will be
// the source of the repairing.
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Tue Oct 30 17:23:23 2018
@@ -426,7 +426,7 @@ void RegisterBankInfo::applyDefaultMappi
"This mapping is too complex for this function");
iterator_range<SmallVectorImpl<unsigned>::const_iterator> NewRegs =
OpdMapper.getVRegs(OpIdx);
- if (NewRegs.begin() == NewRegs.end()) {
+ if (empty(NewRegs)) {
LLVM_DEBUG(dbgs() << " has not been repaired, nothing to be done\n");
continue;
}
Modified: llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp Tue Oct 30 17:23:23 2018
@@ -88,7 +88,7 @@ iterator_range<CtorDtorIterator> getDest
}
void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) {
- if (CtorDtors.begin() == CtorDtors.end())
+ if (empty(CtorDtors))
return;
MangleAndInterner Mangle(
Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Tue Oct 30 17:23:23 2018
@@ -280,7 +280,7 @@ bool DebugInfoFinder::addScope(DIScope *
}
static MDNode *stripDebugLocFromLoopID(MDNode *N) {
- assert(N->op_begin() != N->op_end() && "Missing self reference?");
+ assert(!empty(N->operands()) && "Missing self reference?");
// if there is no debug location, we do not have to rewrite this MDNode.
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
Modified: llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PartialInlining.cpp Tue Oct 30 17:23:23 2018
@@ -1251,7 +1251,7 @@ std::pair<bool, Function *> PartialInlin
if (PSI->isFunctionEntryCold(F))
return {false, nullptr};
- if (F->user_begin() == F->user_end())
+ if (empty(F->users()))
return {false, nullptr};
OptimizationRemarkEmitter ORE(F);
@@ -1357,7 +1357,7 @@ bool PartialInlinerImpl::tryPartialInlin
return false;
}
- assert(Cloner.OrigFunc->user_begin() == Cloner.OrigFunc->user_end() &&
+ assert(empty(Cloner.OrigFunc->users()) &&
"F's users should all be replaced!");
std::vector<User *> Users(Cloner.ClonedFunc->user_begin(),
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Tue Oct 30 17:23:23 2018
@@ -1751,7 +1751,7 @@ NewGVN::performSymbolicPHIEvaluation(Arr
return true;
});
// If we are left with no operands, it's dead.
- if (Filtered.begin() == Filtered.end()) {
+ if (empty(Filtered)) {
// If it has undef at this point, it means there are no-non-undef arguments,
// and thus, the value of the phi node must be undef.
if (HasUndef) {
Modified: llvm/trunk/lib/Transforms/Utils/PredicateInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PredicateInfo.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/PredicateInfo.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/PredicateInfo.cpp Tue Oct 30 17:23:23 2018
@@ -522,7 +522,7 @@ Value *PredicateInfo::materializeStack(u
if (isa<PredicateWithEdge>(ValInfo)) {
IRBuilder<> B(getBranchTerminator(ValInfo));
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
- if (IF->user_begin() == IF->user_end())
+ if (empty(IF->users()))
CreatedDeclarations.insert(IF);
CallInst *PIC =
B.CreateCall(IF, Op, Op->getName() + "." + Twine(Counter++));
@@ -534,7 +534,7 @@ Value *PredicateInfo::materializeStack(u
"Should not have gotten here without it being an assume");
IRBuilder<> B(PAssume->AssumeInst);
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
- if (IF->user_begin() == IF->user_end())
+ if (empty(IF->users()))
CreatedDeclarations.insert(IF);
CallInst *PIC = B.CreateCall(IF, Op);
PredicateMap.insert({PIC, ValInfo});
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Oct 30 17:23:23 2018
@@ -5260,7 +5260,7 @@ static bool SwitchToLookupTable(SwitchIn
// Figure out the corresponding result for each case value and phi node in the
// common destination, as well as the min and max case values.
- assert(SI->case_begin() != SI->case_end());
+ assert(!empty(SI->cases()));
SwitchInst::CaseIt CI = SI->case_begin();
ConstantInt *MinCaseVal = CI->getCaseValue();
ConstantInt *MaxCaseVal = CI->getCaseValue();
Modified: llvm/trunk/unittests/ADT/STLExtrasTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/STLExtrasTest.cpp?rev=345679&r1=345678&r2=345679&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/STLExtrasTest.cpp (original)
+++ llvm/trunk/unittests/ADT/STLExtrasTest.cpp Tue Oct 30 17:23:23 2018
@@ -364,6 +364,23 @@ TEST(STLExtrasTest, ADLTest) {
EXPECT_EQ(5, count);
}
+TEST(STLExtrasTest, EmptyTest) {
+ std::vector<void*> V;
+ EXPECT_TRUE(empty(V));
+ V.push_back(nullptr);
+ EXPECT_FALSE(empty(V));
+
+ std::initializer_list<int> E = {};
+ std::initializer_list<int> NotE = {7, 13, 42};
+ EXPECT_TRUE(empty(E));
+ EXPECT_FALSE(empty(NotE));
+
+ auto R0 = make_range(V.begin(), V.begin());
+ EXPECT_TRUE(empty(R0));
+ auto R1 = make_range(V.begin(), V.end());
+ EXPECT_FALSE(empty(R1));
+}
+
TEST(STLExtrasTest, EarlyIncrementTest) {
std::list<int> L = {1, 2, 3, 4};
More information about the llvm-commits
mailing list