Skip to content

Commit 6e4cfc9

Browse files
committed
Link the runtime earlier, and allow re-optimizing it.
1 parent 725443d commit 6e4cfc9

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/driver.jl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ const __llvm_initialized = Ref(false)
171171
# target-specific libraries
172172
undefined_fns = LLVM.name.(decls(ir))
173173
@timeit_debug to "target libraries" link_libraries!(job, ir, undefined_fns)
174+
175+
# GPU run-time library
176+
if any(fn -> fn in runtime_fns, undefined_fns)
177+
@timeit_debug to "runtime library" link_library!(ir, runtime)
178+
end
174179
end
175180
end
176181

@@ -263,20 +268,6 @@ const __llvm_initialized = Ref(false)
263268
entry = functions(ir)[entry_fn]
264269
end
265270

266-
if libraries
267-
# GPU run-time library
268-
#
269-
# we do this late for multiple reasons:
270-
# - the runtime library is already optimized, so we don't want to re-optimize
271-
# - if `malloc(...) = 0`, the consequent stores are reduced to a trap, which
272-
# results in e.g. every `box` function just trapping. this breaks our test
273-
# suite, which runs without malloc, but expects actual code being generated.
274-
undefined_fns = LLVM.name.(decls(ir))
275-
if any(fn -> fn in runtime_fns, undefined_fns)
276-
@timeit_debug to "runtime library" link_library!(ir, runtime)
277-
end
278-
end
279-
280271
if ccall(:jl_is_debugbuild, Cint, ()) == 1
281272
@timeit_debug to "verification" verify(ir)
282273
end

test/util.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ end
3535
module TestRuntime
3636
# dummy methods
3737
signal_exception() = return
38-
malloc(sz) = C_NULL
38+
# HACK: if malloc returns 0 or traps, all calling functions (like jl_box_*)
39+
# get reduced to a trap, which really messes with our test suite.
40+
malloc(sz) = Ptr{Cvoid}(Int(0xDEADBEEF))
3941
report_oom(sz) = return
4042
report_exception(ex) = return
4143
report_exception_name(ex) = return

0 commit comments

Comments
 (0)