Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate backtraces using the juliaojit #863

Merged
merged 2 commits into from
Jul 13, 2023
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ CEnum = "0.4"
EnzymeCore = "0.5.1"
Enzyme_jll = "0.0.75"
GPUCompiler = "0.21"
LLVM = "6"
LLVM = "6.1"
ObjectFile = "0.4"
julia = "1.6"
2 changes: 1 addition & 1 deletion src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6634,7 +6634,7 @@ GPUCompiler.llvm_triple(::EnzymeTarget) = Sys.MACHINE
# GPUCompiler.llvm_datalayout(::EnzymeTarget) = nothing

function GPUCompiler.llvm_machine(::EnzymeTarget)
return tm[]
return JIT.get_tm()
end

module Runtime
Expand Down
82 changes: 50 additions & 32 deletions src/compiler/orcv2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ import ..Compiler: API, cpu_name, cpu_features

export get_trampoline

struct CompilerInstance
jit::LLVM.LLJIT
lctm::Union{LLVM.LazyCallThroughManager, Nothing}
ism::Union{LLVM.IndirectStubsManager, Nothing}
@static if LLVM.has_julia_ojit()
struct CompilerInstance
jit::LLVM.JuliaOJIT
lctm::Union{LLVM.LazyCallThroughManager, Nothing}
ism::Union{LLVM.IndirectStubsManager, Nothing}
end
else
struct CompilerInstance
jit::LLVM.LLJIT
lctm::Union{LLVM.LazyCallThroughManager, Nothing}
ism::Union{LLVM.IndirectStubsManager, Nothing}
end
end

function LLVM.dispose(ci::CompilerInstance)
Expand Down Expand Up @@ -63,34 +71,37 @@ function __init__()
tempTM = LLVM.JITTargetMachine(LLVM.triple(), cpu_name(), cpu_features(); optlevel)
LLVM.asm_verbosity!(tempTM, true)
tm[] = tempTM

tempTM = LLVM.JITTargetMachine(LLVM.triple(), cpu_name(), cpu_features(); optlevel)
LLVM.asm_verbosity!(tempTM, true)

gdb = haskey(ENV, "ENABLE_GDBLISTENER")
perf = haskey(ENV, "ENABLE_JITPROFILING")
if gdb || perf
ollc = LLVM.ObjectLinkingLayerCreator() do es, triple
oll = ObjectLinkingLayer(es)
if gdb
register!(oll, GDBRegistrationListener())

lljit = if !LLVM.has_julia_ojit()
tempTM = LLVM.JITTargetMachine(LLVM.triple(), cpu_name(), cpu_features(); optlevel)
LLVM.asm_verbosity!(tempTM, true)

gdb = haskey(ENV, "ENABLE_GDBLISTENER")
perf = haskey(ENV, "ENABLE_JITPROFILING")
if gdb || perf
ollc = LLVM.ObjectLinkingLayerCreator() do es, triple
oll = ObjectLinkingLayer(es)
if gdb
register!(oll, GDBRegistrationListener())
end
if perf
register!(oll, IntelJITEventListener())
register!(oll, PerfJITEventListener())
end
return oll
end
if perf
register!(oll, IntelJITEventListener())
register!(oll, PerfJITEventListener())
GC.@preserve ollc begin
builder = LLJITBuilder()
LLVM.linkinglayercreator!(builder, ollc)
tmb = TargetMachineBuilder(tempTM)
LLVM.targetmachinebuilder!(builder, tmb)
LLJIT(builder)
end
return oll
end

GC.@preserve ollc begin
builder = LLJITBuilder()
LLVM.linkinglayercreator!(builder, ollc)
tmb = TargetMachineBuilder(tempTM)
LLVM.targetmachinebuilder!(builder, tmb)
lljit = LLJIT(builder)
else
LLJIT(;tm=tempTM)
end
else
lljit = LLJIT(;tm=tempTM)
JuliaOJIT()
end

jd_main = JITDylib(lljit)
Expand All @@ -115,8 +126,10 @@ function __init__()
end

atexit() do
ci = jit[]
dispose(ci)
if !LLVM.has_julia_ojit()
ci = jit[]
dispose(ci)
end
dispose(tm[])
end
end
Expand Down Expand Up @@ -146,7 +159,7 @@ function add_trampoline!(jd, (lljit, lctm, ism), entry, target)

mu = LLVM.reexports(lctm, ism, jd, [alias])
LLVM.define(jd, mu)

LLVM.lookup(lljit, entry)
end

Expand Down Expand Up @@ -202,7 +215,12 @@ function get_trampoline(job)
end

tsm = move_to_threadsafe(mod)
il = LLVM.IRTransformLayer(lljit)

il = if LLVM.has_julia_ojit()
LLVM.IRCompileLayer(lljit)
else
LLVM.IRTransformLayer(lljit)
end
LLVM.emit(il, mr, tsm)
end
return nothing
Expand Down