From: Lang Hames Date: Fri, 2 Oct 2020 04:12:19 +0000 (-0700) Subject: [ORC] Add C API functions to obtain and clear the symbol string pool. X-Git-Tag: llvmorg-13-init~8927 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35e48d7b91735136e423f71c1d7406eb07a03e89;p=platform%2Fupstream%2Fllvm.git [ORC] Add C API functions to obtain and clear the symbol string pool. Symbol string pool entries are ref counted, but not automatically cleared. This can cause the size of the pool to grow without bound if it's not periodically cleared. These functions allow that to be done via the C API. --- diff --git a/llvm/include/llvm-c/Orc.h b/llvm/include/llvm-c/Orc.h index 50caae1..e808746 100644 --- a/llvm/include/llvm-c/Orc.h +++ b/llvm/include/llvm-c/Orc.h @@ -44,6 +44,11 @@ typedef uint64_t LLVMOrcJITTargetAddress; typedef struct LLVMOrcOpaqueExecutionSession *LLVMOrcExecutionSessionRef; /** + * A reference to an orc::SymbolStringPool. + */ +typedef struct LLVMOrcOpaqueSymbolStringPool *LLVMOrcSymbolStringPoolRef; + +/** * A reference to an orc::SymbolStringPool table entry. */ typedef struct LLVMOrcOpaqueSymbolStringPoolEntry @@ -111,6 +116,27 @@ void LLVMOrcExecutionSessionSetErrorReporter( void *Ctx); /** + * Return a reference to the SymbolStringPool for an ExecutionSession. + * + * Ownership of the pool remains with the ExecutionSession: The caller is + * not required to free the pool. + */ +LLVMOrcSymbolStringPoolRef +LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES); + +/** + * Clear all unreferenced symbol string pool entries. + * + * This can be called at any time to release unused entries in the + * ExecutionSession's string pool. Since it locks the pool (preventing + * interning of any new strings) it is recommended that it only be called + * infrequently, ideally when the caller has reason to believe that some + * entries will have become unreferenced, e.g. after removing a module or + * closing a JITDylib. + */ +void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP); + +/** * Intern a string in the ExecutionSession's SymbolStringPool and return a * reference to it. This increments the ref-count of the pool entry, and the * returned value should be released once the client is done with it by diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp index 1179f67..91b90bc 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp @@ -43,6 +43,7 @@ public: } // end namespace llvm DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionSession, LLVMOrcExecutionSessionRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry, LLVMOrcSymbolStringPoolEntryRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITDylib, LLVMOrcJITDylibRef) @@ -65,6 +66,15 @@ void LLVMOrcExecutionSessionSetErrorReporter( [=](Error Err) { ReportError(Ctx, wrap(std::move(Err))); }); } +LLVMOrcSymbolStringPoolRef +LLVMOrcExecutionSessionGetSymbolStringPool(LLVMOrcExecutionSessionRef ES) { + return wrap(unwrap(ES)->getSymbolStringPool().get()); +} + +void LLVMOrcSymbolStringPoolClearDeadEntries(LLVMOrcSymbolStringPoolRef SSP) { + unwrap(SSP)->clearDeadEntries(); +} + LLVMOrcSymbolStringPoolEntryRef LLVMOrcExecutionSessionIntern(LLVMOrcExecutionSessionRef ES, const char *Name) { return wrap(