[compiler-rt] bd13241 - [MemProf][NFC] Clean up runtime code (#80581)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 17:55:37 PST 2024


Author: Enna1
Date: 2024-02-07T09:55:32+08:00
New Revision: bd1324113e90884a4a83d6232ecf0c623e2e113e

URL: https://github.com/llvm/llvm-project/commit/bd1324113e90884a4a83d6232ecf0c623e2e113e
DIFF: https://github.com/llvm/llvm-project/commit/bd1324113e90884a4a83d6232ecf0c623e2e113e.diff

LOG: [MemProf][NFC] Clean up runtime code (#80581)

Added: 
    

Modified: 
    compiler-rt/lib/memprof/memprof_allocator.cpp
    compiler-rt/lib/memprof/memprof_allocator.h
    compiler-rt/lib/memprof/memprof_interceptors.cpp
    compiler-rt/lib/memprof/memprof_internal.h
    compiler-rt/lib/memprof/memprof_malloc_linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index af46ffdb248e2..35e941228525a 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -515,8 +515,7 @@ struct Allocator {
     return ptr;
   }
 
-  void CommitBack(MemprofThreadLocalMallocStorage *ms,
-                  BufferedStackTrace *stack) {
+  void CommitBack(MemprofThreadLocalMallocStorage *ms) {
     AllocatorCache *ac = GetAllocatorCache(ms);
     allocator.SwallowCache(ac);
   }
@@ -561,7 +560,7 @@ struct Allocator {
     return reinterpret_cast<MemprofChunk *>(p - kChunkHeaderSize)->UsedSize();
   }
 
-  void Purge(BufferedStackTrace *stack) { allocator.ForceReleaseToOS(); }
+  void Purge() { allocator.ForceReleaseToOS(); }
 
   void PrintStats() { allocator.PrintStats(); }
 
@@ -583,8 +582,7 @@ static MemprofAllocator &get_allocator() { return instance.allocator; }
 void InitializeAllocator() { instance.InitLinkerInitialized(); }
 
 void MemprofThreadLocalMallocStorage::CommitBack() {
-  GET_STACK_TRACE_MALLOC;
-  instance.CommitBack(this, &stack);
+  instance.CommitBack(this);
 }
 
 void PrintInternalAllocatorStats() { instance.PrintStats(); }
@@ -699,7 +697,7 @@ static const void *memprof_malloc_begin(const void *p) {
   return (const void *)m->Beg();
 }
 
-uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp) {
+uptr memprof_malloc_usable_size(const void *ptr) {
   if (!ptr)
     return 0;
   uptr usable_size = instance.AllocationSize(reinterpret_cast<uptr>(ptr));
@@ -714,7 +712,7 @@ using namespace __memprof;
 uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
 
 int __sanitizer_get_ownership(const void *p) {
-  return memprof_malloc_usable_size(p, 0, 0) != 0;
+  return memprof_malloc_usable_size(p) != 0;
 }
 
 const void *__sanitizer_get_allocated_begin(const void *p) {
@@ -722,7 +720,7 @@ const void *__sanitizer_get_allocated_begin(const void *p) {
 }
 
 uptr __sanitizer_get_allocated_size(const void *p) {
-  return memprof_malloc_usable_size(p, 0, 0);
+  return memprof_malloc_usable_size(p);
 }
 
 uptr __sanitizer_get_allocated_size_fast(const void *p) {
@@ -732,6 +730,8 @@ uptr __sanitizer_get_allocated_size_fast(const void *p) {
   return ret;
 }
 
+void __sanitizer_purge_allocator() { instance.Purge(); }
+
 int __memprof_profile_dump() {
   instance.FinishAndWrite();
   // In the future we may want to return non-zero if there are any errors

diff  --git a/compiler-rt/lib/memprof/memprof_allocator.h b/compiler-rt/lib/memprof/memprof_allocator.h
index 14c61c7325e3f..f583cee020e4f 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.h
+++ b/compiler-rt/lib/memprof/memprof_allocator.h
@@ -99,7 +99,7 @@ void *memprof_aligned_alloc(uptr alignment, uptr size,
                             BufferedStackTrace *stack);
 int memprof_posix_memalign(void **memptr, uptr alignment, uptr size,
                            BufferedStackTrace *stack);
-uptr memprof_malloc_usable_size(const void *ptr, uptr pc, uptr bp);
+uptr memprof_malloc_usable_size(const void *ptr);
 
 void PrintInternalAllocatorStats();
 

diff  --git a/compiler-rt/lib/memprof/memprof_interceptors.cpp b/compiler-rt/lib/memprof/memprof_interceptors.cpp
index 8925ec5bbaa37..a267f6d3d6717 100644
--- a/compiler-rt/lib/memprof/memprof_interceptors.cpp
+++ b/compiler-rt/lib/memprof/memprof_interceptors.cpp
@@ -163,7 +163,7 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
 }
 
 INTERCEPTOR(int, pthread_join, void *t, void **arg) {
-  return real_pthread_join(t, arg);
+  return REAL(pthread_join)(t, arg);
 }
 
 DEFINE_REAL_PTHREAD_FUNCTIONS

diff  --git a/compiler-rt/lib/memprof/memprof_internal.h b/compiler-rt/lib/memprof/memprof_internal.h
index 990e62ce1a55d..423ffac5ef73a 100644
--- a/compiler-rt/lib/memprof/memprof_internal.h
+++ b/compiler-rt/lib/memprof/memprof_internal.h
@@ -20,10 +20,6 @@
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_stacktrace.h"
 
-#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
-#error "The MemProfiler run-time should not be instrumented by MemProfiler"
-#endif
-
 // Build-time configuration options.
 
 // If set, memprof will intercept C++ exception api call(s).

diff  --git a/compiler-rt/lib/memprof/memprof_malloc_linux.cpp b/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
index ef753fcaa4add..aba6295a4a049 100644
--- a/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
+++ b/compiler-rt/lib/memprof/memprof_malloc_linux.cpp
@@ -104,9 +104,7 @@ INTERCEPTOR(void *, aligned_alloc, uptr boundary, uptr size) {
 #endif // SANITIZER_INTERCEPT_ALIGNED_ALLOC
 
 INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
-  GET_CURRENT_PC_BP_SP;
-  (void)sp;
-  return memprof_malloc_usable_size(ptr, pc, bp);
+  return memprof_malloc_usable_size(ptr);
 }
 
 #if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO


        


More information about the llvm-commits mailing list