1 | //===- CtxInstrProfiling.cpp - contextual instrumented PGO ----------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "CtxInstrProfiling.h" |
10 | #include "sanitizer_common/sanitizer_allocator_internal.h" |
11 | #include "sanitizer_common/sanitizer_common.h" |
12 | #include "sanitizer_common/sanitizer_dense_map.h" |
13 | #include "sanitizer_common/sanitizer_mutex.h" |
14 | #include "sanitizer_common/sanitizer_placement_new.h" |
15 | #include "sanitizer_common/sanitizer_thread_safety.h" |
16 | |
17 | #include <assert.h> |
18 | |
19 | using namespace __ctx_profile; |
20 | |
21 | // FIXME(mtrofin): use malloc / mmap instead of sanitizer common APIs to reduce |
22 | // the dependency on the latter. |
23 | Arena *Arena::allocateNewArena(size_t Size, Arena *Prev) { |
24 | assert(!Prev || Prev->Next == nullptr); |
25 | Arena *NewArena = |
26 | new (__sanitizer::InternalAlloc(size: Size + sizeof(Arena))) Arena(Size); |
27 | if (Prev) |
28 | Prev->Next = NewArena; |
29 | return NewArena; |
30 | } |
31 | |
32 | void Arena::freeArenaList(Arena *&A) { |
33 | assert(A); |
34 | for (auto *I = A; I != nullptr;) { |
35 | auto *Current = I; |
36 | I = I->Next; |
37 | __sanitizer::InternalFree(p: Current); |
38 | } |
39 | A = nullptr; |
40 | } |
41 |