diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md index 73ae2ee599640..c42470bbcc03d 100644 --- a/llvm/docs/ReleaseNotes.md +++ b/llvm/docs/ReleaseNotes.md @@ -256,6 +256,9 @@ Changes to the C API * Added ``LLVMGetICmpSameSign`` and ``LLVMSetICmpSameSign`` for the `samesign` flag on `icmp` instructions. +* Added `LLVMOrcThreadSafeContextGetLock` and `LLVMOrcThreadSafeContextReleaseLock` + for acquiring and releasing locks associated with `ThreadSafeContext` instances. + Changes to the CodeGen infrastructure ------------------------------------- diff --git a/llvm/include/llvm-c/Orc.h b/llvm/include/llvm-c/Orc.h index 743ba1d581782..5f07a069cfd5b 100644 --- a/llvm/include/llvm-c/Orc.h +++ b/llvm/include/llvm-c/Orc.h @@ -385,6 +385,12 @@ typedef int (*LLVMOrcSymbolPredicate)(void *Ctx, */ typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef; +/** + * A reference to an orc::ThreadSafeContext::Lock instance. + */ +typedef struct LLVMOrcOpaqueThreadSafeContextLock + *LLVMOrcThreadSafeContextLockRef; + /** * A reference to an orc::ThreadSafeModule instance. */ @@ -1082,6 +1088,18 @@ LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx); */ void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx); +/** + * Acquire the lock associated with a ThreadSafeContext. + */ +LLVMOrcThreadSafeContextLockRef +LLVMOrcThreadSafeContextGetLock(LLVMOrcThreadSafeContextRef TSCtx); + +/** + * Release the lock associated with a ThreadSafeContext. + */ +void LLVMOrcThreadSafeContextReleaseLock( + LLVMOrcThreadSafeContextLockRef TSCtxLock); + /** * Create a ThreadSafeModule wrapper around the given LLVM module. This takes * ownership of the M argument which should not be disposed of or referenced diff --git a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp index 9999e1ff3bf00..b8dd411bc0b8b 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp @@ -61,6 +61,8 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DefinitionGenerator, DEFINE_SIMPLE_CONVERSION_FUNCTIONS(InProgressLookupState, LLVMOrcLookupStateRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeContext, LLVMOrcThreadSafeContextRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeContext::Lock, + LLVMOrcThreadSafeContextLockRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITTargetMachineBuilder, LLVMOrcJITTargetMachineBuilderRef) @@ -738,6 +740,16 @@ void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx) { delete unwrap(TSCtx); } +LLVMOrcThreadSafeContextLockRef +LLVMOrcThreadSafeContextGetLock(LLVMOrcThreadSafeContextRef TSCtx) { + return wrap(new ThreadSafeContext::Lock(std::move(unwrap(TSCtx)->getLock()))); +} + +void LLVMOrcThreadSafeContextReleaseLock( + LLVMOrcThreadSafeContextLockRef TSCtxLock) { + delete unwrap(TSCtxLock); +} + LLVMErrorRef LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM, LLVMOrcGenericIRModuleOperationFunction F,