Skip to content

Commit ab1a9b5

Browse files
committed
[C-API] LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager
Allow C programs to use JITLink instead of RuntimeDyld. Modeled on LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager except that it has to deal with failure to create InProcessMemoryManager. In that case it returns nullptr.
1 parent bd643bc commit ab1a9b5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/include/llvm-c/OrcEE.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ typedef void (*LLVMMemoryManagerNotifyTerminatingCallback)(void *CtxCtx);
4343
* @{
4444
*/
4545

46+
/**
47+
* Create a ObjectLinkingLayer instance using the standard JITLink
48+
* InProcessMemoryManager for memory management. Result is NULL on failure to
49+
* determine system page size.
50+
*/
51+
LLVMOrcObjectLayerRef
52+
LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager(
53+
LLVMOrcExecutionSessionRef ES);
54+
4655
/**
4756
* Create a RTDyldObjectLinkingLayer instance using the standard
4857
* SectionMemoryManager for memory management.

llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
#include "llvm-c/OrcEE.h"
1212
#include "llvm-c/TargetMachine.h"
1313

14+
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
1415
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
1516
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
1617
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
18+
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
1719
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
1820
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
1921
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
@@ -1017,6 +1019,18 @@ LLVMOrcLLJITGetObjTransformLayer(LLVMOrcLLJITRef J) {
10171019
return wrap(&unwrap(J)->getObjTransformLayer());
10181020
}
10191021

1022+
LLVMOrcObjectLayerRef
1023+
LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager(
1024+
LLVMOrcExecutionSessionRef ES) {
1025+
assert(ES && "ES must not be null");
1026+
auto mm = jitlink::InProcessMemoryManager::Create();
1027+
if (!mm) {
1028+
unwrap(ES)->reportError(mm.takeError());
1029+
return nullptr;
1030+
}
1031+
return wrap(new ObjectLinkingLayer(*unwrap(ES), std::move(*mm)));
1032+
}
1033+
10201034
LLVMOrcObjectLayerRef
10211035
LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(
10221036
LLVMOrcExecutionSessionRef ES) {

0 commit comments

Comments
 (0)