Skip to content

Commit 9d40181

Browse files
authored
Only clean-up the IR after optimization. (#255)
Optimization can introduce calls to the GPU runtime library, so we can't remove its functions until after that.
1 parent e1807ec commit 9d40181

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/driver.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,6 @@ const __llvm_initialized = Ref(false)
261261
end
262262

263263
@timeit_debug to "IR post-processing" begin
264-
# some early clean-up to reduce the amount of code to optimize
265-
@timeit_debug to "clean-up" begin
266-
ModulePassManager() do pm
267-
# eliminate all unused internal functions
268-
global_optimizer!(pm)
269-
global_dce!(pm)
270-
strip_dead_prototypes!(pm)
271-
272-
# merge constants (such as exception messages)
273-
constant_merge!(pm)
274-
275-
run!(pm, ir)
276-
end
277-
end
278-
279264
if optimize
280265
@timeit_debug to "optimization" begin
281266
optimize!(job, ir)
@@ -304,6 +289,22 @@ const __llvm_initialized = Ref(false)
304289
entry = functions(ir)[entry_fn]
305290
end
306291

292+
@timeit_debug to "clean-up" begin
293+
# we can only clean-up now, as optimization may lower or introduce calls to
294+
# functions from the GPU runtime (e.g. julia.gc_alloc_obj -> gpu_gc_pool_alloc)
295+
ModulePassManager() do pm
296+
# eliminate all unused internal functions
297+
global_optimizer!(pm)
298+
global_dce!(pm)
299+
strip_dead_prototypes!(pm)
300+
301+
# merge constants (such as exception messages)
302+
constant_merge!(pm)
303+
304+
run!(pm, ir)
305+
end
306+
end
307+
307308
# replace non-entry function definitions with a declaration
308309
# NOTE: we can't do this before optimization, because the definitions of called
309310
# functions may affect optimization.

0 commit comments

Comments
 (0)