https://github.com/mtrofin created https://github.com/llvm/llvm-project/pull/133146
None >From bbe97a86d8cc94b484420db54f735dac8bc818cf Mon Sep 17 00:00:00 2001 From: Mircea Trofin <mtro...@google.com> Date: Wed, 26 Mar 2025 10:10:43 -0700 Subject: [PATCH] [ctxprof][nfc] Move 2 implementation functions up in `CtxInstrProfiling.cpp` --- .../lib/ctx_profile/CtxInstrProfiling.cpp | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp b/compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp index b0e63a8861d86..da291e0bbabdd 100644 --- a/compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp +++ b/compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp @@ -244,6 +244,39 @@ ContextNode *getFlatProfile(FunctionData &Data, GUID Guid, return Data.FlatCtx; } +// This should be called once for a Root. Allocate the first arena, set up the +// first context. +void setupContext(ContextRoot *Root, GUID Guid, uint32_t NumCounters, + uint32_t NumCallsites) { + __sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock( + &AllContextsMutex); + // Re-check - we got here without having had taken a lock. + if (Root->FirstMemBlock) + return; + const auto Needed = ContextNode::getAllocSize(NumCounters, NumCallsites); + auto *M = Arena::allocateNewArena(getArenaAllocSize(Needed)); + Root->FirstMemBlock = M; + Root->CurrentMem = M; + Root->FirstNode = allocContextNode(M->tryBumpAllocate(Needed), Guid, + NumCounters, NumCallsites); + AllContextRoots.PushBack(Root); +} + +ContextRoot *FunctionData::getOrAllocateContextRoot() { + auto *Root = CtxRoot; + if (Root) + return Root; + __sanitizer::GenericScopedLock<__sanitizer::StaticSpinMutex> L(&Mutex); + Root = CtxRoot; + if (!Root) { + Root = new (__sanitizer::InternalAlloc(sizeof(ContextRoot))) ContextRoot(); + CtxRoot = Root; + } + + assert(Root); + return Root; +} + ContextNode *getUnhandledContext(FunctionData &Data, GUID Guid, uint32_t NumCounters) { @@ -333,39 +366,6 @@ ContextNode *__llvm_ctx_profile_get_context(FunctionData *Data, void *Callee, return Ret; } -// This should be called once for a Root. Allocate the first arena, set up the -// first context. -void setupContext(ContextRoot *Root, GUID Guid, uint32_t NumCounters, - uint32_t NumCallsites) { - __sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock( - &AllContextsMutex); - // Re-check - we got here without having had taken a lock. - if (Root->FirstMemBlock) - return; - const auto Needed = ContextNode::getAllocSize(NumCounters, NumCallsites); - auto *M = Arena::allocateNewArena(getArenaAllocSize(Needed)); - Root->FirstMemBlock = M; - Root->CurrentMem = M; - Root->FirstNode = allocContextNode(M->tryBumpAllocate(Needed), Guid, - NumCounters, NumCallsites); - AllContextRoots.PushBack(Root); -} - -ContextRoot *FunctionData::getOrAllocateContextRoot() { - auto *Root = CtxRoot; - if (Root) - return Root; - __sanitizer::GenericScopedLock<__sanitizer::StaticSpinMutex> L(&Mutex); - Root = CtxRoot; - if (!Root) { - Root = new (__sanitizer::InternalAlloc(sizeof(ContextRoot))) ContextRoot(); - CtxRoot = Root; - } - - assert(Root); - return Root; -} - ContextNode *__llvm_ctx_profile_start_context( FunctionData *FData, GUID Guid, uint32_t Counters, uint32_t Callsites) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits