<div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 7, 2012 at 9:25 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank" class="cremed">kremenek@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kremenek<br>
Date: Fri Sep  7 23:25:29 2012<br>
New Revision: 163454<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=163454&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=163454&view=rev</a><br>
Log:<br>
Add operator< for FoldingSetNodeID.<br></blockquote><div><br></div><div>While I'm good with adding this if there are good use cases (such as places where a sort-based container is more efficient), I think it needs comments: the order isn't really any more deterministic than the folding set's order. See my reply to your commit using this for more here.</div>
<div><br></div><div>In the general case, we have lots of pointers that are inputs to a FoldingSetNodeID. The hashing function in use doesn't guarantee any stability from run-to-run either. While the current implementation happens to be stable from run-to-run, I've proposed and would still like to implement a change that ensures each execution is seeded differently so that inherently non-deterministic behavior is discovered early and reliably rather than late and sometimes only on systems with ASLR.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/FoldingSet.h<br>
    llvm/trunk/lib/Support/FoldingSet.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/FoldingSet.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FoldingSet.h?rev=163454&r1=163453&r2=163454&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/FoldingSet.h?rev=163454&r1=163453&r2=163454&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/FoldingSet.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/FoldingSet.h Fri Sep  7 23:25:29 2012<br>
@@ -278,6 +278,10 @@<br>
<br>
   bool operator==(FoldingSetNodeIDRef) const;<br>
<br>
+  /// Used to compare the "ordering" of two nodes as defined by the<br>
+  /// profiled bits and their ordering defined by memcmp().<br>
+  bool operator<(FoldingSetNodeIDRef) const;<br>
+<br>
   const unsigned *getData() const { return Data; }<br>
   size_t getSize() const { return Size; }<br>
 };<br>
@@ -327,6 +331,11 @@<br>
   bool operator==(const FoldingSetNodeID &RHS) const;<br>
   bool operator==(const FoldingSetNodeIDRef RHS) const;<br>
<br>
+  /// Used to compare the "ordering" of two nodes as defined by the<br>
+  /// profiled bits and their ordering defined by memcmp().<br>
+  bool operator<(const FoldingSetNodeID &RHS) const;<br>
+  bool operator<(const FoldingSetNodeIDRef RHS) const;<br>
+<br>
   /// Intern - Copy this node's data to a memory region allocated from the<br>
   /// given allocator and return a FoldingSetNodeIDRef describing the<br>
   /// interned data.<br>
<br>
Modified: llvm/trunk/lib/Support/FoldingSet.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=163454&r1=163453&r2=163454&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=163454&r1=163453&r2=163454&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Support/FoldingSet.cpp (original)<br>
+++ llvm/trunk/lib/Support/FoldingSet.cpp Fri Sep  7 23:25:29 2012<br>
@@ -38,6 +38,14 @@<br>
   return memcmp(Data, RHS.Data, Size*sizeof(*Data)) == 0;<br>
 }<br>
<br>
+/// Used to compare the "ordering" of two nodes as defined by the<br>
+/// profiled bits and their ordering defined by memcmp().<br>
+bool FoldingSetNodeIDRef::operator<(FoldingSetNodeIDRef RHS) const {<br>
+  if (Size != RHS.Size)<br>
+    return Size < RHS.Size;<br>
+  return memcmp(Data, RHS.Data, Size*sizeof(*Data)) < 0;<br>
+}<br>
+<br>
 //===----------------------------------------------------------------------===//<br>
 // FoldingSetNodeID Implementation<br>
<br>
@@ -152,6 +160,16 @@<br>
   return FoldingSetNodeIDRef(Bits.data(), Bits.size()) == RHS;<br>
 }<br>
<br>
+/// Used to compare the "ordering" of two nodes as defined by the<br>
+/// profiled bits and their ordering defined by memcmp().<br>
+bool FoldingSetNodeID::operator<(const FoldingSetNodeID &RHS)const{<br>
+  return *this < FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size());<br>
+}<br>
+<br>
+bool FoldingSetNodeID::operator<(FoldingSetNodeIDRef RHS) const {<br>
+  return FoldingSetNodeIDRef(Bits.data(), Bits.size()) < RHS;<br>
+}<br>
+<br>
 /// Intern - Copy this node's data to a memory region allocated from the<br>
 /// given allocator and return a FoldingSetNodeIDRef describing the<br>
 /// interned data.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" class="cremed">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>