Retire llvm::array_endof in favor of non-member std::end.

While there make array_lengthof constexpr if we have support for it.

llvm-svn: 206112
This commit is contained in:
Benjamin Kramer 2014-04-12 16:15:53 +00:00
parent 336194addf
commit f6c0615b06
12 changed files with 36 additions and 44 deletions

View File

@ -45,7 +45,6 @@
#ifndef LLVM_ADT_HASHING_H
#define LLVM_ADT_HASHING_H
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/SwapByteOrder.h"
@ -412,7 +411,7 @@ template <typename InputIteratorT>
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) {
const size_t seed = get_execution_seed();
char buffer[64], *buffer_ptr = buffer;
char *const buffer_end = buffer_ptr + array_lengthof(buffer);
char *const buffer_end = std::end(buffer);
while (first != last && store_and_advance(buffer_ptr, buffer_end,
get_hashable_data(*first)))
++first;

View File

@ -165,17 +165,9 @@ struct less_second {
// Extra additions for arrays
//===----------------------------------------------------------------------===//
/// Find where an array ends (for ending iterators)
/// This returns a pointer to the byte immediately
/// after the end of an array.
template<class T, std::size_t N>
inline T *array_endof(T (&x)[N]) {
return x+N;
}
/// Find the length of an array.
template<class T, std::size_t N>
inline size_t array_lengthof(T (&)[N]) {
template <class T, std::size_t N>
LLVM_CONSTEXPR inline size_t array_lengthof(T (&)[N]) {
return N;
}

View File

@ -333,7 +333,7 @@ public:
public:
ValueTypeActionImpl() {
std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0);
std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions), 0);
}
LegalizeTypeAction getTypeAction(MVT VT) const {

View File

@ -38,7 +38,7 @@ INITIALIZE_PASS_END(MachineTraceMetrics,
MachineTraceMetrics::MachineTraceMetrics()
: MachineFunctionPass(ID), MF(0), TII(0), TRI(0), MRI(0), Loops(0) {
std::fill(Ensembles, array_endof(Ensembles), (Ensemble*)0);
std::fill(std::begin(Ensembles), std::end(Ensembles), nullptr);
}
void MachineTraceMetrics::getAnalysisUsage(AnalysisUsage &AU) const {

View File

@ -16,6 +16,7 @@
#include "llvm/IR/Attributes.h"
#include "AttributeImpl.h"
#include "LLVMContextImpl.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Atomic.h"

View File

@ -9,6 +9,7 @@
#include "llvm/MC/MCDwarf.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"

View File

@ -55,7 +55,7 @@ static std::vector<std::pair<void(*)(void*), void*> > CallBacksToRun;
static const int IntSigs[] = {
SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
};
static const int *const IntSigsEnd = array_endof(IntSigs);
static const int *const IntSigsEnd = std::end(IntSigs);
// KillSigs - Signals that represent that we have a bug, and our prompt
// termination has been ordered.
@ -74,7 +74,7 @@ static const int KillSigs[] = {
, SIGEMT
#endif
};
static const int *const KillSigsEnd = array_endof(KillSigs);
static const int *const KillSigsEnd = std::end(KillSigs);
static unsigned NumRegisteredSignals = 0;
static struct {

View File

@ -354,9 +354,8 @@ static const char *IntrinsicInline[] =
};
static bool isIntrinsicInline(Function *F) {
return std::binary_search(
IntrinsicInline, array_endof(IntrinsicInline),
F->getName());
return std::binary_search(std::begin(IntrinsicInline),
std::end(IntrinsicInline), F->getName());
}
//
// Returns of float, double and complex need to be handled with a helper

View File

@ -443,8 +443,8 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL, S->getSymbol() };
if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
Find))
if (std::binary_search(std::begin(HardFloatLibCalls),
std::end(HardFloatLibCalls), Find))
LookupHelper = false;
else {
const char *Symbol = S->getSymbol();
@ -471,13 +471,12 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
FuncInfo->setSaveS2();
}
// one more look at list of intrinsics
if (std::binary_search(Mips16IntrinsicHelper,
array_endof(Mips16IntrinsicHelper),
IntrinsicFind)) {
const Mips16IntrinsicHelperType *h =(std::find(Mips16IntrinsicHelper,
array_endof(Mips16IntrinsicHelper),
IntrinsicFind));
Mips16HelperFunction = h->Helper;
const Mips16IntrinsicHelperType *Helper =
std::lower_bound(std::begin(Mips16IntrinsicHelper),
std::end(Mips16IntrinsicHelper), IntrinsicFind);
if (Helper != std::end(Mips16IntrinsicHelper) &&
*Helper == IntrinsicFind) {
Mips16HelperFunction = Helper->Helper;
NeedMips16Helper = true;
LookupHelper = false;
}
@ -488,8 +487,8 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL,
G->getGlobal()->getName().data() };
if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
Find))
if (std::binary_search(std::begin(HardFloatLibCalls),
std::end(HardFloatLibCalls), Find))
LookupHelper = false;
}
if (LookupHelper) Mips16HelperFunction =

View File

@ -9,6 +9,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Allocator.h"

View File

@ -68,7 +68,7 @@ TEST(Option, OptionParsing) {
TestOptTable T;
unsigned MAI, MAC;
std::unique_ptr<InputArgList> AL(
T.ParseArgs(Args, array_endof(Args), MAI, MAC));
T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC));
// Check they all exist.
EXPECT_TRUE(AL->hasArg(OPT_A));
@ -114,7 +114,7 @@ TEST(Option, ParseWithFlagExclusions) {
std::unique_ptr<InputArgList> AL;
// Exclude flag3 to avoid parsing as OPT_SLASH_C.
AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
/*FlagsToInclude=*/0,
/*FlagsToExclude=*/OptFlag3));
EXPECT_TRUE(AL->hasArg(OPT_A));
@ -122,7 +122,7 @@ TEST(Option, ParseWithFlagExclusions) {
EXPECT_FALSE(AL->hasArg(OPT_SLASH_C));
// Exclude flag1 to avoid parsing as OPT_C.
AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
/*FlagsToInclude=*/0,
/*FlagsToExclude=*/OptFlag1));
EXPECT_TRUE(AL->hasArg(OPT_B));
@ -130,7 +130,7 @@ TEST(Option, ParseWithFlagExclusions) {
EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
const char *NewArgs[] = { "/C", "foo", "--C=bar" };
AL.reset(T.ParseArgs(NewArgs, array_endof(NewArgs), MAI, MAC));
AL.reset(T.ParseArgs(std::begin(NewArgs), std::end(NewArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
EXPECT_TRUE(AL->hasArg(OPT_C));
EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo");
@ -143,7 +143,7 @@ TEST(Option, ParseAliasInGroup) {
const char *MyArgs[] = { "-I" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_H));
}
@ -153,7 +153,7 @@ TEST(Option, AliasArgs) {
const char *MyArgs[] = { "-J", "-Joo" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_B));
EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo");
EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar");
@ -165,7 +165,7 @@ TEST(Option, IgnoreCase) {
const char *MyArgs[] = { "-a", "-joo" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_A));
EXPECT_TRUE(AL->hasArg(OPT_B));
}
@ -176,7 +176,7 @@ TEST(Option, DoNotIgnoreCase) {
const char *MyArgs[] = { "-a", "-joo" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_FALSE(AL->hasArg(OPT_A));
EXPECT_FALSE(AL->hasArg(OPT_B));
}
@ -187,7 +187,7 @@ TEST(Option, SlurpEmpty) {
const char *MyArgs[] = { "-A", "-slurp" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_TRUE(AL->hasArg(OPT_A));
EXPECT_TRUE(AL->hasArg(OPT_Slurp));
EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 0U);
@ -199,7 +199,7 @@ TEST(Option, Slurp) {
const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
std::unique_ptr<InputArgList> AL(
T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
EXPECT_EQ(AL->size(), 2U);
EXPECT_TRUE(AL->hasArg(OPT_A));
EXPECT_FALSE(AL->hasArg(OPT_B));

View File

@ -2881,8 +2881,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
for (unsigned VC = 0; VC != VariantCount; ++VC) {
Record *AsmVariant = Target.getAsmParserVariant(VC);
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC
<< "; End = array_endof(MatchTable" << VC << "); break;\n";
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
<< "); End = std::end(MatchTable" << VC << "); break;\n";
}
OS << " }\n";
OS << " // Search the table.\n";
@ -2936,8 +2936,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
for (unsigned VC = 0; VC != VariantCount; ++VC) {
Record *AsmVariant = Target.getAsmParserVariant(VC);
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC
<< "; End = array_endof(MatchTable" << VC << "); break;\n";
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
<< "); End = std::end(MatchTable" << VC << "); break;\n";
}
OS << " }\n";
OS << " // Search the table.\n";