<div dir="rtl"><div dir="ltr">following this commit a bot is failing:</div><div dir="ltr"><br></div><div dir="ltr"><a href="http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux">http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux</a><br></div><div dir="ltr"><a href="http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/41483">http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/41483</a><br></div><div dir="ltr"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">2016-08-13 22:40 GMT+03:00 Mehdi Amini via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span>:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mehdi_amini<br>
Date: Sat Aug 13 14:40:13 2016<br>
New Revision: 278600<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278600&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278600&view=rev</a><br>
Log:<br>
[ADT] Add a reserve method to DenseSet as well as an insert() for R-value<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/ADT/<wbr>DenseSet.h<br>
llvm/trunk/unittests/ADT/<wbr>DenseSetTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/<wbr>DenseSet.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseSet.h?rev=278600&r1=278599&r2=278600&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/ADT/DenseSet.h?rev=<wbr>278600&r1=278599&r2=278600&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/ADT/<wbr>DenseSet.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/<wbr>DenseSet.h Sat Aug 13 14:40:13 2016<br>
@@ -58,6 +58,10 @@ public:<br>
/// the Size of the set.<br>
void resize(size_t Size) { TheMap.resize(Size); }<br>
<br>
+ /// Grow the DenseSet so that it can contain at least \p NumEntries items<br>
+ /// before resizing again.<br>
+ void reserve(size_t Size) { TheMap.reserve(Size); }<br>
+<br>
void clear() {<br>
TheMap.clear();<br>
}<br>
@@ -154,6 +158,11 @@ public:<br>
return TheMap.insert(std::make_pair(<wbr>V, Empty));<br>
}<br>
<br>
+ std::pair<iterator, bool> insert(ValueT &&V) {<br>
+ detail::DenseSetEmpty Empty;<br>
+ return TheMap.insert(std::make_pair(<wbr>std::move(V), Empty));<br>
+ }<br>
+<br>
/// Alternative version of insert that uses a different (and possibly less<br>
/// expensive) key type.<br>
template <typename LookupKeyT><br>
<br>
Modified: llvm/trunk/unittests/ADT/<wbr>DenseSetTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/DenseSetTest.cpp?rev=278600&r1=278599&r2=278600&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/unittests/<wbr>ADT/DenseSetTest.cpp?rev=<wbr>278600&r1=278599&r2=278600&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/unittests/ADT/<wbr>DenseSetTest.cpp (original)<br>
+++ llvm/trunk/unittests/ADT/<wbr>DenseSetTest.cpp Sat Aug 13 14:40:13 2016<br>
@@ -65,4 +65,67 @@ TEST(DenseSetCustomTest, FindAsTest) {<br>
EXPECT_TRUE(set.find_as("d") == set.end());<br>
}<br>
<br>
+// Simple class that counts how many moves and copy happens when growing a map<br>
+struct CountCopyAndMove {<br>
+ static int Move;<br>
+ static int Copy;<br>
+ int Value;<br>
+ CountCopyAndMove(int Value) : Value(Value) {}<br>
+<br>
+ CountCopyAndMove(const CountCopyAndMove &) { Copy++; }<br>
+ CountCopyAndMove &operator=(const CountCopyAndMove &) {<br>
+ Copy++;<br>
+ return *this;<br>
+ }<br>
+ CountCopyAndMove(<wbr>CountCopyAndMove &&) { Move++; }<br>
+ CountCopyAndMove &operator=(const CountCopyAndMove &&) {<br>
+ Move++;<br>
+ return *this;<br>
+ }<br>
+};<br>
+int CountCopyAndMove::Copy = 0;<br>
+int CountCopyAndMove::Move = 0;<br>
+} // anonymous namespace<br>
+<br>
+namespace llvm {<br>
+// Specialization required to insert a CountCopyAndMove into a DenseSet.<br>
+template <> struct DenseMapInfo<CountCopyAndMove> {<br>
+ static inline CountCopyAndMove getEmptyKey() { return CountCopyAndMove(-1); };<br>
+ static inline CountCopyAndMove getTombstoneKey() {<br>
+ return CountCopyAndMove(-2);<br>
+ };<br>
+ static unsigned getHashValue(const CountCopyAndMove &Val) {<br>
+ return Val.Value;<br>
+ }<br>
+ static bool isEqual(const CountCopyAndMove &LHS,<br>
+ const CountCopyAndMove &RHS) {<br>
+ return LHS.Value == RHS.Value;<br>
+ }<br>
+};<br>
+}<br>
+<br>
+namespace {<br>
+// Make sure reserve actually gives us enough buckets to insert N items<br>
+// without increasing allocation size.<br>
+TEST(DenseSetCustomTest, ReserveTest) {<br>
+ // Test a few different size, 48 is *not* a random choice: we need a value<br>
+ // that is 2/3 of a power of two to stress the grow() condition, and the power<br>
+ // of two has to be at least 64 because of minimum size allocation in the<br>
+ // DenseMa. 66 is a value just above the 64 default init.<br>
+ for (auto Size : {1, 2, 48, 66}) {<br>
+ DenseSet<CountCopyAndMove> Set;<br>
+ Set.reserve(Size);<br>
+ unsigned MemorySize = Set.getMemorySize();<br>
+ CountCopyAndMove::Copy = 0;<br>
+ CountCopyAndMove::Move = 0;<br>
+ for (int i = 0; i < Size; ++i)<br>
+ Set.insert(CountCopyAndMove(i)<wbr>);<br>
+ // Check that we didn't grow<br>
+ EXPECT_EQ(MemorySize, Set.getMemorySize());<br>
+ // Check that move was called the expected number of times<br>
+ EXPECT_EQ(Size, CountCopyAndMove::Move);<br>
+ // Check that no copy occured<br>
+ EXPECT_EQ(0, CountCopyAndMove::Copy);<br>
+ }<br>
+}<br>
}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>