Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deps/LLVMExtra/include/LLVMExtra.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "llvm/Config/llvm-config.h"
#include <llvm-c/Core.h>
#include <llvm-c/Orc.h>
#include <llvm-c/LLJIT.h>
#include <llvm-c/Target.h>
#include <llvm-c/Transforms/PassBuilder.h>
#include <llvm-c/Types.h>
Expand Down Expand Up @@ -109,6 +110,7 @@ void LLVMOrcIRCompileLayerEmit(LLVMOrcIRCompileLayerRef IRLayer,
LLVMOrcMaterializationResponsibilityRef MR,
LLVMOrcThreadSafeModuleRef TSM);
char *LLVMDumpJitDylibToString(LLVMOrcJITDylibRef JD);
LLVMOrcObjectLayerRef LLVMOrcLLJITGetObjectLinkingLayer(LLVMOrcLLJITRef J);

// Cloning functionality
typedef enum {
Expand Down
13 changes: 13 additions & 0 deletions deps/LLVMExtra/lib/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/CodeGen/Passes.h>
#include <llvm/ExecutionEngine/Orc/LLJIT.h>
#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DebugInfo.h>
Expand Down Expand Up @@ -384,6 +385,18 @@ char *LLVMDumpJitDylibToString(LLVMOrcJITDylibRef JD) {
return strdup(str.c_str());
}

DEFINE_SIMPLE_CONVERSION_FUNCTIONS(orc::ObjectLayer, LLVMOrcObjectLayerRef)

DEFINE_SIMPLE_CONVERSION_FUNCTIONS(orc::LLJIT, LLVMOrcLLJITRef)

// expose JITLink
LLVMOrcObjectLayerRef LLVMOrcLLJITGetObjectLinkingLayer(LLVMOrcLLJITRef J) {
if (!J)
return nullptr;
orc::LLJIT *LLJITInstance = unwrap(J);
return wrap(&LLJITInstance->getObjLinkingLayer());
}


//
// Cloning functionality
Expand Down
4 changes: 4 additions & 0 deletions lib/16/libLLVM_extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ function LLVMDumpJitDylibToString(JD)
ccall((:LLVMDumpJitDylibToString, libLLVMExtra), Cstring, (LLVMOrcJITDylibRef,), JD)
end

function LLVMOrcLLJITGetObjectLinkingLayer(J)
ccall((:LLVMOrcLLJITGetObjectLinkingLayer, libLLVMExtra), LLVMOrcObjectLayerRef, (LLVMOrcLLJITRef,), J)
end

@cenum LLVMCloneFunctionChangeType::UInt32 begin
LLVMCloneFunctionChangeTypeLocalChangesOnly = 0
LLVMCloneFunctionChangeTypeGlobalChanges = 1
Expand Down
16 changes: 16 additions & 0 deletions src/orc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,27 @@ end
end
Base.unsafe_convert(::Type{API.LLVMOrcObjectLayerRef}, oll::ObjectLinkingLayer) = oll.ref

# RTDyld
function ObjectLinkingLayer(es::ExecutionSession)
ref = API.LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(es)
ObjectLinkingLayer(ref)
end

"""
JITLinkObjectLayer(lljit::LLJIT)

Gets the default JITLink-based ObjectLinkingLayer from an LLJIT instance.
The lifetime of this layer is tied to the LLJIT instance.
"""
function JITLinkObjectLayer(lljit::LLJIT) # Takes LLJIT instance
ref = API.LLVMOrcLLJITGetObjectLinkingLayer(lljit)
if ref == C_NULL
error("Failed to get ObjectLinkingLayer from LLJIT instance.")
end
# XXX: owned by the JIT, so can't dispose
return ObjectLinkingLayer(ref)
end

function dispose(oll::ObjectLinkingLayer)
API.LLVMOrcDisposeObjectLayer(oll)
end
Expand Down
Loading