[ctxprof][nfc] Move 2 implementation functions up in CtxInstrProfiling.cpp (#133146)

This commit is contained in:
Mircea Trofin 2025-03-28 20:53:50 -07:00 committed by GitHub
parent ba2de8f22d
commit 8e1d9f2d84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {