llvm.org GIT mirror llvm / 15c435a
Retire llvm::array_endof in favor of non-member std::end. 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 Benjamin Kramer 5 years ago
12 changed file(s) with 36 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
4444 #ifndef LLVM_ADT_HASHING_H
4545 #define LLVM_ADT_HASHING_H
4646
47 #include "llvm/ADT/STLExtras.h"
4847 #include "llvm/Support/DataTypes.h"
4948 #include "llvm/Support/Host.h"
5049 #include "llvm/Support/SwapByteOrder.h"
411410 hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) {
412411 const size_t seed = get_execution_seed();
413412 char buffer[64], *buffer_ptr = buffer;
414 char *const buffer_end = buffer_ptr + array_lengthof(buffer);
413 char *const buffer_end = std::end(buffer);
415414 while (first != last && store_and_advance(buffer_ptr, buffer_end,
416415 get_hashable_data(*first)))
417416 ++first;
164164 // Extra additions for arrays
165165 //===----------------------------------------------------------------------===//
166166
167 /// Find where an array ends (for ending iterators)
168 /// This returns a pointer to the byte immediately
169 /// after the end of an array.
170 template
171 inline T *array_endof(T (&x)[N]) {
172 return x+N;
173 }
174
175167 /// Find the length of an array.
176 template
177 inline size_t array_lengthof(T (&)[N]) {
168 template
169 LLVM_CONSTEXPR inline size_t array_lengthof(T (&)[N]) {
178170 return N;
179171 }
180172
332332
333333 public:
334334 ValueTypeActionImpl() {
335 std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0);
335 std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions), 0);
336336 }
337337
338338 LegalizeTypeAction getTypeAction(MVT VT) const {
3737
3838 MachineTraceMetrics::MachineTraceMetrics()
3939 : MachineFunctionPass(ID), MF(0), TII(0), TRI(0), MRI(0), Loops(0) {
40 std::fill(Ensembles, array_endof(Ensembles), (Ensemble*)0);
40 std::fill(std::begin(Ensembles), std::end(Ensembles), nullptr);
4141 }
4242
4343 void MachineTraceMetrics::getAnalysisUsage(AnalysisUsage &AU) const {
1515 #include "llvm/IR/Attributes.h"
1616 #include "AttributeImpl.h"
1717 #include "LLVMContextImpl.h"
18 #include "llvm/ADT/STLExtras.h"
1819 #include "llvm/ADT/StringExtras.h"
1920 #include "llvm/IR/Type.h"
2021 #include "llvm/Support/Atomic.h"
88
99 #include "llvm/MC/MCDwarf.h"
1010 #include "llvm/ADT/Hashing.h"
11 #include "llvm/ADT/STLExtras.h"
1112 #include "llvm/ADT/SmallString.h"
1213 #include "llvm/ADT/Twine.h"
1314 #include "llvm/Config/config.h"
5454 static const int IntSigs[] = {
5555 SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
5656 };
57 static const int *const IntSigsEnd = array_endof(IntSigs);
57 static const int *const IntSigsEnd = std::end(IntSigs);
5858
5959 // KillSigs - Signals that represent that we have a bug, and our prompt
6060 // termination has been ordered.
7373 , SIGEMT
7474 #endif
7575 };
76 static const int *const KillSigsEnd = array_endof(KillSigs);
76 static const int *const KillSigsEnd = std::end(KillSigs);
7777
7878 static unsigned NumRegisteredSignals = 0;
7979 static struct {
353353 };
354354
355355 static bool isIntrinsicInline(Function *F) {
356 return std::binary_search(
357 IntrinsicInline, array_endof(IntrinsicInline),
358 F->getName());
356 return std::binary_search(std::begin(IntrinsicInline),
357 std::end(IntrinsicInline), F->getName());
359358 }
360359 //
361360 // Returns of float, double and complex need to be handled with a helper
442442 if (ExternalSymbolSDNode *S = dyn_cast(CLI.Callee)) {
443443 Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL, S->getSymbol() };
444444
445 if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
446 Find))
445 if (std::binary_search(std::begin(HardFloatLibCalls),
446 std::end(HardFloatLibCalls), Find))
447447 LookupHelper = false;
448448 else {
449449 const char *Symbol = S->getSymbol();
470470 FuncInfo->setSaveS2();
471471 }
472472 // one more look at list of intrinsics
473 if (std::binary_search(Mips16IntrinsicHelper,
474 array_endof(Mips16IntrinsicHelper),
475 IntrinsicFind)) {
476 const Mips16IntrinsicHelperType *h =(std::find(Mips16IntrinsicHelper,
477 array_endof(Mips16IntrinsicHelper),
478 IntrinsicFind));
479 Mips16HelperFunction = h->Helper;
473 const Mips16IntrinsicHelperType *Helper =
474 std::lower_bound(std::begin(Mips16IntrinsicHelper),
475 std::end(Mips16IntrinsicHelper), IntrinsicFind);
476 if (Helper != std::end(Mips16IntrinsicHelper) &&
477 *Helper == IntrinsicFind) {
478 Mips16HelperFunction = Helper->Helper;
480479 NeedMips16Helper = true;
481480 LookupHelper = false;
482481 }
487486 Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL,
488487 G->getGlobal()->getName().data() };
489488
490 if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
491 Find))
489 if (std::binary_search(std::begin(HardFloatLibCalls),
490 std::end(HardFloatLibCalls), Find))
492491 LookupHelper = false;
493492 }
494493 if (LookupHelper) Mips16HelperFunction =
88
99 #include "llvm/ADT/StringRef.h"
1010 #include "llvm/ADT/Hashing.h"
11 #include "llvm/ADT/STLExtras.h"
1112 #include "llvm/ADT/SmallVector.h"
1213 #include "llvm/ADT/StringExtras.h"
1314 #include "llvm/Support/Allocator.h"
6767 TestOptTable T;
6868 unsigned MAI, MAC;
6969 std::unique_ptr AL(
70 T.ParseArgs(Args, array_endof(Args), MAI, MAC));
70 T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC));
7171
7272 // Check they all exist.
7373 EXPECT_TRUE(AL->hasArg(OPT_A));
113113 std::unique_ptr AL;
114114
115115 // Exclude flag3 to avoid parsing as OPT_SLASH_C.
116 AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
116 AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
117117 /*FlagsToInclude=*/0,
118118 /*FlagsToExclude=*/OptFlag3));
119119 EXPECT_TRUE(AL->hasArg(OPT_A));
121121 EXPECT_FALSE(AL->hasArg(OPT_SLASH_C));
122122
123123 // Exclude flag1 to avoid parsing as OPT_C.
124 AL.reset(T.ParseArgs(Args, array_endof(Args), MAI, MAC,
124 AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
125125 /*FlagsToInclude=*/0,
126126 /*FlagsToExclude=*/OptFlag1));
127127 EXPECT_TRUE(AL->hasArg(OPT_B));
129129 EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
130130
131131 const char *NewArgs[] = { "/C", "foo", "--C=bar" };
132 AL.reset(T.ParseArgs(NewArgs, array_endof(NewArgs), MAI, MAC));
132 AL.reset(T.ParseArgs(std::begin(NewArgs), std::end(NewArgs), MAI, MAC));
133133 EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
134134 EXPECT_TRUE(AL->hasArg(OPT_C));
135135 EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo");
142142
143143 const char *MyArgs[] = { "-I" };
144144 std::unique_ptr AL(
145 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
145 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
146146 EXPECT_TRUE(AL->hasArg(OPT_H));
147147 }
148148
152152
153153 const char *MyArgs[] = { "-J", "-Joo" };
154154 std::unique_ptr AL(
155 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
155 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
156156 EXPECT_TRUE(AL->hasArg(OPT_B));
157157 EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo");
158158 EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar");
164164
165165 const char *MyArgs[] = { "-a", "-joo" };
166166 std::unique_ptr AL(
167 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
167 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
168168 EXPECT_TRUE(AL->hasArg(OPT_A));
169169 EXPECT_TRUE(AL->hasArg(OPT_B));
170170 }
175175
176176 const char *MyArgs[] = { "-a", "-joo" };
177177 std::unique_ptr AL(
178 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
178 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
179179 EXPECT_FALSE(AL->hasArg(OPT_A));
180180 EXPECT_FALSE(AL->hasArg(OPT_B));
181181 }
186186
187187 const char *MyArgs[] = { "-A", "-slurp" };
188188 std::unique_ptr AL(
189 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
189 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
190190 EXPECT_TRUE(AL->hasArg(OPT_A));
191191 EXPECT_TRUE(AL->hasArg(OPT_Slurp));
192192 EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 0U);
198198
199199 const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
200200 std::unique_ptr AL(
201 T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
201 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
202202 EXPECT_EQ(AL->size(), 2U);
203203 EXPECT_TRUE(AL->hasArg(OPT_A));
204204 EXPECT_FALSE(AL->hasArg(OPT_B));
28802880 for (unsigned VC = 0; VC != VariantCount; ++VC) {
28812881 Record *AsmVariant = Target.getAsmParserVariant(VC);
28822882 int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
2883 OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC
2884 << "; End = array_endof(MatchTable" << VC << "); break;\n";
2883 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
2884 << "); End = std::end(MatchTable" << VC << "); break;\n";
28852885 }
28862886 OS << " }\n";
28872887 OS << " // Search the table.\n";
29352935 for (unsigned VC = 0; VC != VariantCount; ++VC) {
29362936 Record *AsmVariant = Target.getAsmParserVariant(VC);
29372937 int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
2938 OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC
2939 << "; End = array_endof(MatchTable" << VC << "); break;\n";
2938 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
2939 << "); End = std::end(MatchTable" << VC << "); break;\n";
29402940 }
29412941 OS << " }\n";
29422942 OS << " // Search the table.\n";