Skip to content
Merged
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
20 changes: 16 additions & 4 deletions lib/libLLVM_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ function JLJITGetLLVMOrcExecutionSession(JIT)
ccall(:JLJITGetLLVMOrcExecutionSession, LLVMOrcExecutionSessionRef, (JuliaOJITRef,), JIT)
end

function JLJITGetExternalJITDylib(JIT)
ccall(:JLJITGetExternalJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef,), JIT)
@static if VERSION >= v"1.14.0-DEV.2171"
function JLJITCreateJITDylib(JIT, Name)
ccall(:JLJITCreateJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef, Cstring), JIT, Name)
end
else
function JLJITGetExternalJITDylib(JIT)
ccall(:JLJITGetExternalJITDylib, LLVMOrcJITDylibRef, (JuliaOJITRef,), JIT)
end
end

function JLJITAddObjectFile(JIT, JD, ObjBuffer)
Expand All @@ -103,8 +109,14 @@ function JLJITAddLLVMIRModule(JIT, JD, TSM)
ccall(:JLJITAddLLVMIRModule, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, LLVMOrcThreadSafeModuleRef), JIT, JD, TSM)
end

function JLJITLookup(JIT, Result, Name, ExternalJDOnly)
ccall(:JLJITLookup, LLVMErrorRef, (JuliaOJITRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, Result, Name, ExternalJDOnly)
@static if VERSION >= v"1.14.0-DEV.2171"
function JLJITJDLookup(JIT, JD, Result, Name, ExternalJDOnly)
ccall(:JLJITJDLookup, LLVMErrorRef, (JuliaOJITRef, LLVMOrcJITDylibRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, JD, Result, Name, ExternalJDOnly)
end
else
function JLJITLookup(JIT, Result, Name, ExternalJDOnly)
ccall(:JLJITLookup, LLVMErrorRef, (JuliaOJITRef, Ptr{LLVMOrcExecutorAddress}, Cstring, Cint), JIT, Result, Name, ExternalJDOnly)
end
end

function JLJITMangleAndIntern(JIT, UnmangledName)
Expand Down
6 changes: 6 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# deprecated methods

# lookup(jljit, name) without an explicit JD was removed in Julia 1.14.0-DEV.2171
# (JuliaLang/julia#60988). On older Julia the JD is ignored internally; on newer
# Julia users must create a JD explicitly.
@deprecate(lookup(jljit::JuliaOJIT, name, external_jd_only=false),
lookup(jljit, JITDylib(jljit), name, external_jd_only), false)

@deprecate called_value(inst::CallBase) called_operand(inst)

@deprecate has_orc_v1() false false
Expand Down
28 changes: 21 additions & 7 deletions src/orc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,23 @@ function mangle(jljit::JuliaOJIT, name)
end

"""
JITDylib(jljit::JuliaOJIT)
JITDylib(jljit::JuliaOJIT[, name])

Get the external JITDylib from the Julia JIT
Get or create a JITDylib from the Julia JIT.
On Julia >= 1.14.0-DEV.2171 (JuliaLang/julia#60988), creates a new JITDylib with
the given name prefix, linked to GlobalJD and SessionJD. On older Julia, returns
the shared external JITDylib (name parameter is ignored).
"""
function JITDylib(jljit::JuliaOJIT)
ref = API.JLJITGetExternalJITDylib(jljit)
JITDylib(ref)
@static if VERSION >= v"1.14.0-DEV.2171"
function JITDylib(jljit::JuliaOJIT, name::String="")
ref = API.JLJITCreateJITDylib(jljit, name)
JITDylib(ref)
end
else
function JITDylib(jljit::JuliaOJIT, name::String="")
ref = API.JLJITGetExternalJITDylib(jljit)
JITDylib(ref)
end
end

function add!(jljit::JuliaOJIT, jd::JITDylib, obj::MemoryBuffer)
Expand Down Expand Up @@ -436,9 +446,13 @@ function add!(jljit::JuliaOJIT, jd::JITDylib, tsm::ThreadSafeModule)
return
end

function lookup(jljit::JuliaOJIT, name, external_jd=true)
function lookup(jljit::JuliaOJIT, jd::JITDylib, name, external_jd_only=false)
result = Ref{API.LLVMOrcJITTargetAddress}()
@check API.JLJITLookup(jljit, result, name, external_jd)
@static if VERSION >= v"1.14.0-DEV.2171"
@check API.JLJITJDLookup(jljit, jd, result, name, external_jd_only)
else
@check API.JLJITLookup(jljit, result, name, external_jd_only)
end
OrcTargetAddress(result[])
end

Expand Down
30 changes: 14 additions & 16 deletions test/jljit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,25 @@ end

@test LLVM.lookup_dylib(es, "my.so") === jd

jd_main = JITDylib(jljit)
jd_main = JITDylib(jljit, "main")

prefix = LLVM.get_prefix(jljit)
dg = LLVM.CreateDynamicLibrarySearchGeneratorForProcess(prefix)
add!(jd_main, dg)

addr = lookup(jljit, "jl_apply_generic")
addr = lookup(jljit, jd_main, "jl_apply_generic")
@test pointer(addr) != C_NULL
end
end

@testset "Undefined Symbol" begin
@dispose jljit=JuliaOJIT() begin
@test_throws LLVMException lookup(jljit, string(gensym()))
jd = JITDylib(jljit, "test")
@test_throws LLVMException lookup(jljit, jd, string(gensym()))
end

@dispose ts_ctx=ThreadSafeContext() jljit=JuliaOJIT() begin
jd = JITDylib(jljit)
jd = JITDylib(jljit, "test")

ts_mod = ThreadSafeModule("jit")

Expand Down Expand Up @@ -100,7 +101,7 @@ end

@testset "Loading ObjectFile" begin
@dispose jljit=JuliaOJIT() begin
jd = JITDylib(jljit)
jd = JITDylib(jljit, "objfile1")

sym = "SomeFunction"
obj = @dispose ctx=Context() mod=LLVM.Module("jit") begin
Expand All @@ -120,16 +121,14 @@ end
end
add!(jljit, jd, MemoryBuffer(obj))

addr = lookup(jljit, sym)

addr = lookup(jljit, jd, sym)
@test pointer(addr) != C_NULL

empty!(jd)
@test_throws LLVMException lookup(jljit, sym)
@test_throws LLVMException lookup(jljit, jd, sym)
end

@dispose jljit=JuliaOJIT() begin
jd = JITDylib(jljit)
jd = JITDylib(jljit, "objfile2")

sym = "SomeFunction"
obj = @dispose ctx=Context() mod=LLVM.Module("jit") begin
Expand Down Expand Up @@ -167,22 +166,21 @@ end

add!(jljit, jd, MemoryBuffer(obj))

addr = lookup(jljit, sym)
addr = lookup(jljit, jd, sym)
@test pointer(addr) != C_NULL

@test ccall(pointer(addr), Int32, ()) == 42
data[] = -1
@test ccall(pointer(addr), Int32, ()) == -1
empty!(jd)
@test_throws LLVMException lookup(jljit, jd, sym)
end
empty!(jd)
@test_throws LLVMException lookup(jljit, sym)
end
end


@testset "Lazy" begin
@dispose ts_ctx=ThreadSafeContext() jljit=JuliaOJIT() begin
jd = JITDylib(jljit)
jd = JITDylib(jljit, "lazy")
es = ExecutionSession(jljit)

lctm = LLVM.LocalLazyCallThroughManager(triple(jljit), es)
Expand All @@ -202,7 +200,7 @@ end
LLVM.define(jd, mu)

# 2. Lookup address of entry symbol
addr = lookup(jljit, entry_sym)
addr = lookup(jljit, jd, entry_sym)
@test pointer(addr) != C_NULL

# 3. add MU that will call back into the compiler
Expand Down
Loading