[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341599: Provide a method for generating deterministic IDs 
for pointers allocated in… (authored by george.karpenkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51393?vs=164294=164309#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51393

Files:
  llvm/trunk/include/llvm/Support/Allocator.h


Index: llvm/trunk/include/llvm/Support/Allocator.h
===
--- llvm/trunk/include/llvm/Support/Allocator.h
+++ llvm/trunk/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/trunk/include/llvm/Support/Allocator.h
===
--- llvm/trunk/include/llvm/Support/Allocator.h
+++ llvm/trunk/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I'm happy with the code.




Comment at: llvm/include/llvm/Support/Allocator.h:298
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));

Two spaces here.


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164294.
george.karpenkov added a comment.

More casts.


https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164292.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164291.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164255.
george.karpenkov marked 2 inline comments as done.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-04 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/include/llvm/Support/Allocator.h:295
+int64_t TotalSlabOffset = 0;
+for (size_t Idx = 0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);

for (size_t Idx = 0, e = Slabs.size(); Idx < e; Idx++) {


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-04 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: llvm/include/llvm/Support/Allocator.h:304
+// Use negative index to denote custom sized slabs.
+int64_t CustomSlabOffset = 0;
+for (size_t Idx = 0; Idx < CustomSizedSlabs.size(); Idx++) {

We should start with -1 because otherwise the first standard-slab object and 
the first custom-slab object would both have id 0.


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-30 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 163383.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,35 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t TotalSlabOffset = 0;
+for (size_t Idx = 0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  size_t IdxSlabSize = computeSlabSize(Idx);
+  if (P >= S && P < S + IdxSlabSize)
+return TotalSlabOffset + (P - S);
+  TotalSlabOffset += IdxSlabSize;
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t CustomSlabOffset = 0;
+for (size_t Idx = 0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return CustomSlabOffset - (P - S);
+  CustomSlabOffset -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,35 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t TotalSlabOffset = 0;
+for (size_t Idx = 0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  size_t IdxSlabSize = computeSlabSize(Idx);
+  if (P >= S && P < S + IdxSlabSize)
+return TotalSlabOffset + (P - S);
+  TotalSlabOffset += IdxSlabSize;
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t CustomSlabOffset = 0;
+for (size_t Idx = 0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return CustomSlabOffset - (P - S);
+  CustomSlabOffset -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D51393#1218544, @george.karpenkov wrote:

> In fact, generating a single "long" seems even better.


`ptrdiff_t` seems to express what we're trying to say pretty accurately.


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-29 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 163224.
george.karpenkov edited the summary of this revision.
george.karpenkov added a comment.

In fact, generating a single "long" seems even better.


https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = 0;
+for (size_t Idx = 0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = 0;
+for (size_t Idx = 0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D51393#1217644, @aprantl wrote:

> Just for consideration: The raw pointers in dumps are sometimes useful while 
> in a debugger session, because you can cast a pointer and dump the object in 
> the debugger.


Yup, i use that as well from time to time, so i guess we can either dump both 
or make a flag.




Comment at: llvm/include/llvm/Support/Allocator.h:290
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional> identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);

I'd much rather have the first element signed, because it's the only one that 
can actually carry "negative" values. Maybe just let's do two `int64_t`s or 
`intptr_t`s?



Comment at: llvm/include/llvm/Support/Allocator.h:295
+  if (P >= S && P < S + computeSlabSize(Idx))
+return std::make_pair(Idx, P - S);
+}

aprantl wrote:
> `return {Idx, P - S};`
And, well, let's make integral casts explicit here.


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-29 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Just for consideration: The raw pointers in dumps are sometimes useful while in 
a debugger session, because you can cast a pointer and dump the object in the 
debugger.


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-29 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: llvm/include/llvm/Support/Allocator.h:292
+const char *P = reinterpret_cast(Ptr);
+for (size_t Idx=0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);

clang-format?



Comment at: llvm/include/llvm/Support/Allocator.h:295
+  if (P >= S && P < S + computeSlabSize(Idx))
+return std::make_pair(Idx, P - S);
+}

`return {Idx, P - S};`


https://reviews.llvm.org/D51393



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-08-28 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
george.karpenkov added reviewers: NoQ, bogner, chandlerc, zturner, aprantl.
Herald added a subscriber: mgrang.

There are many "dumping" actions available from the compiler: Clang dumps AST, 
Clang static analyzer dumps generated nodes in the "exploded graph" it 
generates.

However, in many of those dumps raw pointer values are printed for the objects 
of interest, which can considerably complicate debugging due to those values 
being non-reproducible.
This patch adds a method for converting a pointer generated through an 
allocator to a deterministic (up to an architecture) pair of integers, which 
can make the debugging experience much more pleasant. 
(E.g. compare hunting for a value "0xa9273f732" which changes every run to 
hunting for "(1, 23)").

Discussion started at 
http://lists.llvm.org/pipermail/cfe-dev/2018-August/059178.html

Code in collaboration with @NoQ


https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,28 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return A reproducible pair of objects, uniquely identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional> identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+for (size_t Idx=0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return std::make_pair(Idx, P - S);
+}
+for (size_t Idx=0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+
+  // Use negative index to denote custom sized slabs.
+  if (P >= S && P < S + Size)
+return std::make_pair(-Idx - 1, P - S);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,28 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return A reproducible pair of objects, uniquely identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional> identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+for (size_t Idx=0; Idx < Slabs.size(); Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return std::make_pair(Idx, P - S);
+}
+for (size_t Idx=0; Idx < CustomSizedSlabs.size(); Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+
+  // Use negative index to denote custom sized slabs.
+  if (P >= S && P < S + Size)
+return std::make_pair(-Idx - 1, P - S);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits