Skip to content

[MemProf][NFC] Clean up runtime code #80581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2024
Merged

Conversation

Enna1
Copy link
Contributor

@Enna1 Enna1 commented Feb 4, 2024

No description provided.

@llvmbot llvmbot added compiler-rt PGO Profile Guided Optimizations labels Feb 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2024

@llvm/pr-subscribers-pgo

Author: Enna1 (Enna1)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/80581.diff

5 Files Affected:

  • (modified) compiler-rt/lib/memprof/memprof_allocator.cpp (+8-8)
  • (modified) compiler-rt/lib/memprof/memprof_allocator.h (+1-1)
  • (modified) compiler-rt/lib/memprof/memprof_interceptors.cpp (+1-1)
  • (modified) compiler-rt/lib/memprof/memprof_internal.h (-4)
  • (modified) compiler-rt/lib/memprof/memprof_malloc_linux.cpp (+1-3)
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

@Enna1 Enna1 merged commit bd13241 into main Feb 7, 2024
@Enna1 Enna1 deleted the users/Enna1/memprof-runtime-cleanup branch February 7, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants