[compiler-rt] [compiler-rt][ctx_instr] Add `ctx_profile` component (PR #89304)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 13:06:35 PDT 2024


================
@@ -0,0 +1,55 @@
+/*===- CtxInstrProfiling.h- Contextual instrumentation-based PGO  ---------===*\
+|*
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+|* See https://llvm.org/LICENSE.txt for license information.
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+|*
+\*===----------------------------------------------------------------------===*/
+
+#ifndef CTX_PROFILE_CTXINSTRPROFILING_H_
+#define CTX_PROFILE_CTXINSTRPROFILING_H_
+
+#include <sanitizer/common_interface_defs.h>
+
+namespace __ctx_profile {
+
+/// Arena (bump allocator) forming a linked list. Intentionally not thread safe.
+/// Allocation and de-allocation happen using sanitizer APIs. We make that
+/// explicit.
+class Arena final {
----------------
mtrofin wrote:

Re. `LowLevelAllocator` (LLA), it does look similar, but IIUC the difference is that LLA's use seems to be meant to be global, and I don't want that, i.e. I want to keep the guarantee that contextual profiling is the only thing using these arenas. There's also the aspect about keeping track of them (the linked list bit), but really the global-ness is the bigger issue.

Re. common library: the tradeoff is between scenario specificity and reuse. I'd prefer starting with the Arena specifically tailored for my scenario - especially since the implementation is not particularly difficult. If later we find a second scenario needing something like this, we can refactor.

https://github.com/llvm/llvm-project/pull/89304


More information about the llvm-commits mailing list