@@ -23,6 +23,7 @@ The following keyword arguments are supported:
23
23
- `libraries`: link the GPU runtime and `libdevice` libraries (if required)
24
24
- `deferred_codegen`: resolve deferred compiler invocations (if required)
25
25
- `optimize`: optimize the code (default: true)
26
+ - `cleanup`: run cleanup passes on the code (default: true)
26
27
- `strip`: strip non-functional metadata and debug information (default: false)
27
28
- `validate`: validate the generated IR before emitting machine code (default: true)
28
29
- `only_entry`: only keep the entry function, remove all others (default: false).
@@ -32,14 +33,15 @@ Other keyword arguments can be found in the documentation of [`cufunction`](@ref
32
33
"""
33
34
function compile (target:: Symbol , @nospecialize (job:: CompilerJob );
34
35
libraries:: Bool = true , deferred_codegen:: Bool = true ,
35
- optimize:: Bool = true , strip:: Bool = false , validate:: Bool = true ,
36
- only_entry:: Bool = false , ctx:: Union{JuliaContextType,Nothing} = nothing )
36
+ optimize:: Bool = true , cleanup:: Bool = true , strip:: Bool = false ,
37
+ validate:: Bool = true , only_entry:: Bool = false ,
38
+ ctx:: Union{JuliaContextType,Nothing} = nothing )
37
39
if compile_hook[] != = nothing
38
40
compile_hook[](job)
39
41
end
40
42
41
43
return codegen (target, job;
42
- libraries, deferred_codegen, optimize, strip, validate, only_entry, ctx)
44
+ libraries, deferred_codegen, optimize, cleanup, strip, validate, only_entry, ctx)
43
45
end
44
46
45
47
# transitionary feature to deal versions of Julia that rely on a global context
@@ -83,8 +85,8 @@ unwrap_context(ctx::Context) = ctx
83
85
84
86
function codegen (output:: Symbol , @nospecialize (job:: CompilerJob );
85
87
libraries:: Bool = true , deferred_codegen:: Bool = true , optimize:: Bool = true ,
86
- strip :: Bool = false , validate :: Bool = true , only_entry :: Bool = false ,
87
- parent_job:: Union{Nothing, CompilerJob} = nothing ,
88
+ cleanup :: Bool = true , strip :: Bool = false , validate :: Bool = true ,
89
+ only_entry :: Bool = false , parent_job:: Union{Nothing, CompilerJob} = nothing ,
88
90
ctx:: Union{JuliaContextType,Nothing} = nothing )
89
91
# # Julia IR
90
92
@@ -110,7 +112,7 @@ function codegen(output::Symbol, @nospecialize(job::CompilerJob);
110
112
Use a JuliaContext instead.""" )
111
113
end
112
114
113
- ir, ir_meta = emit_llvm (job, mi; libraries, deferred_codegen, optimize, only_entry, ctx)
115
+ ir, ir_meta = emit_llvm (job, mi; libraries, deferred_codegen, optimize, cleanup, only_entry, ctx)
114
116
115
117
if output == :llvm
116
118
if strip
@@ -199,7 +201,7 @@ const __llvm_initialized = Ref(false)
199
201
200
202
@locked function emit_llvm (@nospecialize (job:: CompilerJob ), @nospecialize (method_instance);
201
203
libraries:: Bool = true , deferred_codegen:: Bool = true , optimize:: Bool = true ,
202
- only_entry:: Bool = false , ctx:: JuliaContextType )
204
+ cleanup :: Bool = true , only_entry:: Bool = false , ctx:: JuliaContextType )
203
205
if ! __llvm_initialized[]
204
206
InitializeAllTargets ()
205
207
InitializeAllTargetInfos ()
@@ -319,7 +321,7 @@ const __llvm_initialized = Ref(false)
319
321
@compiler_assert isempty (uses (dyn_marker)) job
320
322
unsafe_delete! (ir, dyn_marker)
321
323
end
322
-
324
+
323
325
@timeit_debug to " IR post-processing" begin
324
326
# mark the kernel entry-point functions (optimization may need it)
325
327
if job. source. kernel
@@ -332,7 +334,7 @@ const __llvm_initialized = Ref(false)
332
334
if optimize
333
335
@timeit_debug to " optimization" begin
334
336
optimize! (job, ir)
335
-
337
+
336
338
# deferred codegen has some special optimization requirements,
337
339
# which also need to happen _after_ regular optimization.
338
340
# XXX : make these part of the optimizer pipeline?
@@ -357,22 +359,24 @@ const __llvm_initialized = Ref(false)
357
359
entry = functions (ir)[entry_fn]
358
360
end
359
361
360
- @timeit_debug to " clean-up" begin
361
- # we can only clean-up now, as optimization may lower or introduce calls to
362
- # functions from the GPU runtime (e.g. julia.gc_alloc_obj -> gpu_gc_pool_alloc)
363
- @dispose pm= ModulePassManager () begin
364
- # eliminate all unused internal functions
365
- global_optimizer! (pm)
366
- global_dce! (pm)
367
- strip_dead_prototypes! (pm)
362
+ if cleanup
363
+ @timeit_debug to " clean-up" begin
364
+ # we can only clean-up now, as optimization may lower or introduce calls to
365
+ # functions from the GPU runtime (e.g. julia.gc_alloc_obj -> gpu_gc_pool_alloc)
366
+ @dispose pm= ModulePassManager () begin
367
+ # eliminate all unused internal functions
368
+ global_optimizer! (pm)
369
+ global_dce! (pm)
370
+ strip_dead_prototypes! (pm)
368
371
369
- # merge constants (such as exception messages)
370
- constant_merge! (pm)
372
+ # merge constants (such as exception messages)
373
+ constant_merge! (pm)
371
374
372
- run! (pm, ir)
375
+ run! (pm, ir)
376
+ end
373
377
end
374
378
end
375
-
379
+
376
380
# finish the module
377
381
#
378
382
# we want to finish the module after optimization, so we cannot do so during
0 commit comments