Skip to content

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

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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 {
Expand Down
Loading