@@ -244,6 +244,39 @@ ContextNode *getFlatProfile(FunctionData &Data, GUID Guid,
244
244
return Data.FlatCtx ;
245
245
}
246
246
247
+ // This should be called once for a Root. Allocate the first arena, set up the
248
+ // first context.
249
+ void setupContext (ContextRoot *Root, GUID Guid, uint32_t NumCounters,
250
+ uint32_t NumCallsites) {
251
+ __sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock (
252
+ &AllContextsMutex);
253
+ // Re-check - we got here without having had taken a lock.
254
+ if (Root->FirstMemBlock )
255
+ return ;
256
+ const auto Needed = ContextNode::getAllocSize (NumCounters, NumCallsites);
257
+ auto *M = Arena::allocateNewArena (getArenaAllocSize (Needed));
258
+ Root->FirstMemBlock = M;
259
+ Root->CurrentMem = M;
260
+ Root->FirstNode = allocContextNode (M->tryBumpAllocate (Needed), Guid,
261
+ NumCounters, NumCallsites);
262
+ AllContextRoots.PushBack (Root);
263
+ }
264
+
265
+ ContextRoot *FunctionData::getOrAllocateContextRoot () {
266
+ auto *Root = CtxRoot;
267
+ if (Root)
268
+ return Root;
269
+ __sanitizer::GenericScopedLock<__sanitizer::StaticSpinMutex> L (&Mutex);
270
+ Root = CtxRoot;
271
+ if (!Root) {
272
+ Root = new (__sanitizer::InternalAlloc (sizeof (ContextRoot))) ContextRoot ();
273
+ CtxRoot = Root;
274
+ }
275
+
276
+ assert (Root);
277
+ return Root;
278
+ }
279
+
247
280
ContextNode *getUnhandledContext (FunctionData &Data, GUID Guid,
248
281
uint32_t NumCounters) {
249
282
@@ -333,39 +366,6 @@ ContextNode *__llvm_ctx_profile_get_context(FunctionData *Data, void *Callee,
333
366
return Ret;
334
367
}
335
368
336
- // This should be called once for a Root. Allocate the first arena, set up the
337
- // first context.
338
- void setupContext (ContextRoot *Root, GUID Guid, uint32_t NumCounters,
339
- uint32_t NumCallsites) {
340
- __sanitizer::GenericScopedLock<__sanitizer::SpinMutex> Lock (
341
- &AllContextsMutex);
342
- // Re-check - we got here without having had taken a lock.
343
- if (Root->FirstMemBlock )
344
- return ;
345
- const auto Needed = ContextNode::getAllocSize (NumCounters, NumCallsites);
346
- auto *M = Arena::allocateNewArena (getArenaAllocSize (Needed));
347
- Root->FirstMemBlock = M;
348
- Root->CurrentMem = M;
349
- Root->FirstNode = allocContextNode (M->tryBumpAllocate (Needed), Guid,
350
- NumCounters, NumCallsites);
351
- AllContextRoots.PushBack (Root);
352
- }
353
-
354
- ContextRoot *FunctionData::getOrAllocateContextRoot () {
355
- auto *Root = CtxRoot;
356
- if (Root)
357
- return Root;
358
- __sanitizer::GenericScopedLock<__sanitizer::StaticSpinMutex> L (&Mutex);
359
- Root = CtxRoot;
360
- if (!Root) {
361
- Root = new (__sanitizer::InternalAlloc (sizeof (ContextRoot))) ContextRoot ();
362
- CtxRoot = Root;
363
- }
364
-
365
- assert (Root);
366
- return Root;
367
- }
368
-
369
369
ContextNode *__llvm_ctx_profile_start_context (
370
370
FunctionData *FData, GUID Guid, uint32_t Counters,
371
371
uint32_t Callsites) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
0 commit comments