Retire llvm::array_endof in favor of non-member std::end.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 12 Apr 2014 16:15:53 +0000 (16:15 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 12 Apr 2014 16:15:53 +0000 (16:15 +0000)
While there make array_lengthof constexpr if we have support for it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206112 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/llvm/ADT/Hashing.h
include/llvm/ADT/STLExtras.h
include/llvm/Target/TargetLowering.h
lib/CodeGen/MachineTraceMetrics.cpp
lib/IR/Attributes.cpp
lib/MC/MCDwarf.cpp
lib/Support/Unix/Signals.inc
lib/Target/Mips/Mips16HardFloat.cpp
lib/Target/Mips/Mips16ISelLowering.cpp
unittests/ADT/StringRefTest.cpp
unittests/Option/OptionParsingTest.cpp
utils/TableGen/AsmMatcherEmitter.cpp

index 4bffd8e6e2670d91b476271c1957c74f53dc60c1..1b84b45675edf8126df78fdeb5788eec61738532 100644 (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;
index ab6884ffb50df01e0c356e096e1b251609dd1728..fc45a6645ef0c280c4b1ffd4e09e9fc572ac0a98 100644 (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;
 }
 
index f31fd9f2338beeb5724b5e065108a9460ecb3c99..30024ec19da933065383438c914dc1b988dc1cfe 100644 (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 {
index d07178e71f0e82edcdde0ee983ce2b1b7ce4dd65..f1c6bb85de904d0bb6056af86f5d7d1455cf22b8 100644 (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 {
index 65bdc75b0f632dfbd4ae78d4f28401c43c20b8e5..96ba7670e4793b5c527d5d1e567a889e8af3aadd 100644 (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"
index 88cb6236232ccdb23c6bba43ab070bcd0a82c40d..1ea9ac16fe449fef32f6e45567ab2a430e2c9e65 100644 (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"
index b4c78d69f77e954d15ef152a445e734cee8761aa..ef62d52a349b9aa3d6ff809d436f112768fe8b7d 100644 (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 {
index d321e2192ad982e07be1599f03ec06d8b1faa5de..c4fca2742ef8d357005e71b30d7abd29a23beacb 100644 (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
index 5c6f3028de4db7de89932ff76240f3aba8a5fa93..eb07e02dd67f7d06a9c6c04e74a825fc9e9fe097 100644 (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 =
index c7fd9d0f155d098fd8ce0ae7541e398c81e34284..d80179bd78738e2b2aa869a253736f54eedf3570 100644 (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"
index 6beb286cabfc23f1c95d5e9f9225885eb0833987..aa32da3a595fdad88575e05378936dc89194b82c 100644 (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));
index 4169f8d0a8cbb71902f40a82386b5c7cb1810fa9..f32daff417ed3e242b61a9ab2fc9d5cafc0df3a4 100644 (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";