[PATCH] D54486: BumpPtrAllocator: Add a couple of fancy wrapper methods around identifyObject().
Artem Dergachev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 13 12:02:44 PST 2018
NoQ created this revision.
NoQ added reviewers: george.karpenkov, chandlerc.
Herald added subscribers: llvm-commits, kristina.
So far all 5 uses of the API introduced in https://reviews.llvm.org/D51393 looked exactly like the proposed `idenfityKnownAlignedObject()`.
Repository:
rL LLVM
https://reviews.llvm.org/D54486
Files:
include/llvm/Support/Allocator.h
Index: include/llvm/Support/Allocator.h
===================================================================
--- include/llvm/Support/Allocator.h
+++ include/llvm/Support/Allocator.h
@@ -311,6 +311,27 @@
return None;
}
+ /// A convenient wrapper around identifyObject that additionally
+ /// asserts that the object is indeed within the allocator.
+ int64_t identifyKnownObject(const void *Ptr) {
+ Optional<int64_t> Out = identifyObject(Ptr);
+ assert(Out && "Wrong allocator used");
+ return *Out;
+ }
+
+ /// A convenient wrapper around identifyKnownObject. Accepts type information
+ /// about the object and produces a smaller identifier by relying on
+ /// the alignment information. Note that sub-classes may have different
+ /// alignment, so the most base class should be passed as template parameter
+ /// in order to obtain correct results. For that reason automatic template
+ /// parameter deduction is disabled.
+ template <typename T>
+ int64_t identifyKnownAlignedObject(const void *Ptr) {
+ int64_t Out = identifyKnownObject(Ptr);
+ assert(Out % alignof(T) == 0 && "Wrong alignment information");
+ return Out / alignof(T);
+ }
+
size_t getTotalMemory() const {
size_t TotalMemory = 0;
for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54486.173899.patch
Type: text/x-patch
Size: 1315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181113/d708dfbc/attachment.bin>
More information about the llvm-commits
mailing list