@@ -25,7 +25,7 @@ The following keyword arguments are supported:
25
25
- `optimize`: optimize the code (default: true)
26
26
- `cleanup`: run cleanup passes on the code (default: true)
27
27
- `strip`: strip non-functional metadata and debug information (default: false)
28
- - `validate`: validate the generated IR before emitting machine code (default: true)
28
+ - `validate`: enable optional validation of input and outputs (default: true)
29
29
- `only_entry`: only keep the entry function, remove all others (default: false).
30
30
This option is only for internal use, to implement reflection's `dump_module`.
31
31
@@ -90,7 +90,7 @@ function codegen(output::Symbol, @nospecialize(job::CompilerJob);
90
90
ctx:: Union{JuliaContextType,Nothing} = nothing )
91
91
# # Julia IR
92
92
93
- mi, mi_meta = emit_julia (job)
93
+ mi, mi_meta = emit_julia (job; validate )
94
94
95
95
if output == :julia
96
96
return mi, mi_meta
@@ -112,7 +112,7 @@ function codegen(output::Symbol, @nospecialize(job::CompilerJob);
112
112
Use a JuliaContext instead.""" )
113
113
end
114
114
115
- ir, ir_meta = emit_llvm (job, mi; libraries, deferred_codegen, optimize, cleanup, only_entry, ctx)
115
+ ir, ir_meta = emit_llvm (job, mi; libraries, deferred_codegen, optimize, cleanup, only_entry, validate, ctx)
116
116
117
117
if output == :llvm
118
118
if strip
@@ -148,8 +148,11 @@ function codegen(output::Symbol, @nospecialize(job::CompilerJob);
148
148
end
149
149
end
150
150
151
- @locked function emit_julia (@nospecialize (job:: CompilerJob ))
152
- @timeit_debug to " validation" check_method (job)
151
+ @locked function emit_julia (@nospecialize (job:: CompilerJob ); validate:: Bool = true )
152
+ @timeit_debug to " Validation" begin
153
+ check_method (job) # not optional
154
+ validate && check_invocation (job)
155
+ end
153
156
154
157
@timeit_debug to " Julia front-end" begin
155
158
@@ -201,7 +204,8 @@ const __llvm_initialized = Ref(false)
201
204
202
205
@locked function emit_llvm (@nospecialize (job:: CompilerJob ), @nospecialize (method_instance);
203
206
libraries:: Bool = true , deferred_codegen:: Bool = true , optimize:: Bool = true ,
204
- cleanup:: Bool = true , only_entry:: Bool = false , ctx:: JuliaContextType )
207
+ cleanup:: Bool = true , only_entry:: Bool = false , validate:: Bool = true ,
208
+ ctx:: JuliaContextType )
205
209
if ! __llvm_initialized[]
206
210
InitializeAllTargets ()
207
211
InitializeAllTargetInfos ()
@@ -293,8 +297,10 @@ const __llvm_initialized = Ref(false)
293
297
for dyn_job in keys (worklist)
294
298
# cached compilation
295
299
dyn_entry_fn = get! (deferred_jobs, dyn_job) do
296
- dyn_ir, dyn_meta = codegen (:llvm , dyn_job; optimize= false ,
297
- deferred_codegen= false , parent_job= job, ctx)
300
+ dyn_ir, dyn_meta = codegen (:llvm , dyn_job; validate= false ,
301
+ optimize= false ,
302
+ deferred_codegen= false ,
303
+ parent_job= job, ctx)
298
304
dyn_entry_fn = LLVM. name (dyn_meta. entry)
299
305
merge! (compiled, dyn_meta. compiled)
300
306
@assert context (dyn_ir) == unwrap_context (ctx)
@@ -407,18 +413,17 @@ const __llvm_initialized = Ref(false)
407
413
end
408
414
end
409
415
410
- return ir, (; entry, compiled)
411
- end
412
-
413
- @locked function emit_asm (@nospecialize (job:: CompilerJob ), ir:: LLVM.Module ;
414
- strip:: Bool = false , validate:: Bool = true , format:: LLVM.API.LLVMCodeGenFileType )
415
416
if validate
416
417
@timeit_debug to " Validation" begin
417
- check_invocation (job)
418
418
check_ir (job, ir)
419
419
end
420
420
end
421
421
422
+ return ir, (; entry, compiled)
423
+ end
424
+
425
+ @locked function emit_asm (@nospecialize (job:: CompilerJob ), ir:: LLVM.Module ;
426
+ strip:: Bool = false , validate:: Bool = true , format:: LLVM.API.LLVMCodeGenFileType )
422
427
# NOTE: strip after validation to get better errors
423
428
if strip
424
429
@timeit_debug to " Debug info removal" strip_debuginfo! (ir)
0 commit comments