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

Benjamin Kramer benny.kra at googlemail.com
Sat Apr 12 09:15:53 PDT 2014


Author: d0k
Date: Sat Apr 12 11:15:53 2014
New Revision: 206112

URL: http://llvm.org/viewvc/llvm-project?rev=206112&view=rev
Log:
Retire llvm::array_endof in favor of non-member std::end.

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

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

Modified: llvm/trunk/include/llvm/ADT/Hashing.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Hashing.h?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Hashing.h (original)
+++ llvm/trunk/include/llvm/ADT/Hashing.h Sat Apr 12 11:15:53 2014
@@ -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;

Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Sat Apr 12 11:15:53 2014
@@ -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;
 }
 

Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLowering.h Sat Apr 12 11:15:53 2014
@@ -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 {

Modified: llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp Sat Apr 12 11:15:53 2014
@@ -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 {

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Sat Apr 12 11:15:53 2014
@@ -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"

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Sat Apr 12 11:15:53 2014
@@ -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"

Modified: llvm/trunk/lib/Support/Unix/Signals.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Signals.inc?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Signals.inc (original)
+++ llvm/trunk/lib/Support/Unix/Signals.inc Sat Apr 12 11:15:53 2014
@@ -55,7 +55,7 @@ static std::vector<std::pair<void(*)(voi
 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 {

Modified: llvm/trunk/lib/Target/Mips/Mips16HardFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Mips16HardFloat.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Mips16HardFloat.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Mips16HardFloat.cpp Sat Apr 12 11:15:53 2014
@@ -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

Modified: llvm/trunk/lib/Target/Mips/Mips16ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Mips16ISelLowering.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Mips16ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Mips16ISelLowering.cpp Sat Apr 12 11:15:53 2014
@@ -443,8 +443,8 @@ getOpndList(SmallVectorImpl<SDValue> &Op
     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> &Op
             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> &Op
       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 =

Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Sat Apr 12 11:15:53 2014
@@ -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"

Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)
+++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Sat Apr 12 11:15:53 2014
@@ -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));

Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=206112&r1=206111&r2=206112&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Sat Apr 12 11:15:53 2014
@@ -2881,8 +2881,8 @@ void AsmMatcherEmitter::run(raw_ostream
   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
   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";





More information about the llvm-commits mailing list