[compiler-rt] 8e1d9f2 - [ctxprof][nfc] Move 2 implementation functions up in `CtxInstrProfiling.cpp` (#133146)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 28 20:53:53 PDT 2025
Author: Mircea Trofin
Date: 2025-03-28T20:53:50-07:00
New Revision: 8e1d9f2d844a22f7d1cba93c604a9a094636f7a2
URL: https://github.com/llvm/llvm-project/commit/8e1d9f2d844a22f7d1cba93c604a9a094636f7a2
DIFF: https://github.com/llvm/llvm-project/commit/8e1d9f2d844a22f7d1cba93c604a9a094636f7a2.diff
LOG: [ctxprof][nfc] Move 2 implementation functions up in `CtxInstrProfiling.cpp` (#133146)
Added:
Modified:
compiler-rt/lib/ctx_profile/CtxInstrProfiling.cpp
Removed:
################################################################################
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 {
More information about the llvm-commits
mailing list