@@ -325,10 +325,18 @@ const __llvm_initialized = Ref(false)
325325 end
326326
327327 @tracepoint " IR post-processing" begin
328- # mark everything internal except for entrypoints and any exported
329- # global variables. this makes sure that the optimizer can, e.g.,
330- # rewrite function signatures.
328+ # mark the kernel entry-point functions (optimization may need it)
329+ if job. config. kernel
330+ push! (metadata (ir)[" julia.kernel" ], MDNode ([entry]))
331+
332+ # IDEA: save all jobs, not only kernels, and save other attributes
333+ # so that we can reconstruct the CompileJob instead of setting it globally
334+ end
335+
331336 if job. config. toplevel
337+ # mark everything internal except for entrypoints and any exported
338+ # global variables. this makes sure that the optimizer can, e.g.,
339+ # rewrite function signatures.
332340 preserved_gvs = collect (values (jobs))
333341 for gvar in globals (ir)
334342 if linkage (gvar) == LLVM. API. LLVMExternalLinkage
@@ -344,64 +352,55 @@ const __llvm_initialized = Ref(false)
344352 run! (pm, ir)
345353 end
346354 end
347- end
348-
349- # mark the kernel entry-point functions (optimization may need it)
350- if job. config. kernel
351- push! (metadata (ir)[" julia.kernel" ], MDNode ([entry]))
352-
353- # IDEA: save all jobs, not only kernels, and save other attributes
354- # so that we can reconstruct the CompileJob instead of setting it globally
355- end
356355
357- if job. config. toplevel && job. config. optimize
358- @tracepoint " optimization" begin
359- optimize! (job, ir; job. config. opt_level)
356+ finish_linked_module! (job, ir)
357+
358+ if job. config. optimize
359+ @tracepoint " optimization" begin
360+ optimize! (job, ir; job. config. opt_level)
361+
362+ # deferred codegen has some special optimization requirements,
363+ # which also need to happen _after_ regular optimization.
364+ # XXX : make these part of the optimizer pipeline?
365+ if has_deferred_jobs
366+ @dispose pb= NewPMPassBuilder () begin
367+ add! (pb, NewPMFunctionPassManager ()) do fpm
368+ add! (fpm, InstCombinePass ())
369+ end
370+ add! (pb, AlwaysInlinerPass ())
371+ add! (pb, NewPMFunctionPassManager ()) do fpm
372+ add! (fpm, SROAPass ())
373+ add! (fpm, GVNPass ())
374+ end
375+ add! (pb, MergeFunctionsPass ())
376+ run! (pb, ir, llvm_machine (job. config. target))
377+ end
378+ end
379+ end
380+ end
360381
361- # deferred codegen has some special optimization requirements,
362- # which also need to happen _after_ regular optimization.
363- # XXX : make these part of the optimizer pipeline?
364- if has_deferred_jobs
382+ if job. config. cleanup
383+ @tracepoint " clean-up" begin
365384 @dispose pb= NewPMPassBuilder () begin
366- add! (pb, NewPMFunctionPassManager ()) do fpm
367- add! (fpm, InstCombinePass ())
368- end
369- add! (pb, AlwaysInlinerPass ())
370- add! (pb, NewPMFunctionPassManager ()) do fpm
371- add! (fpm, SROAPass ())
372- add! (fpm, GVNPass ())
373- end
374- add! (pb, MergeFunctionsPass ())
385+ add! (pb, RecomputeGlobalsAAPass ())
386+ add! (pb, GlobalOptPass ())
387+ add! (pb, GlobalDCEPass ())
388+ add! (pb, StripDeadPrototypesPass ())
389+ add! (pb, ConstantMergePass ())
375390 run! (pb, ir, llvm_machine (job. config. target))
376391 end
377392 end
378393 end
379394
380395 # optimization may have replaced functions, so look the entry point up again
381396 entry = functions (ir)[entry_fn]
382- end
383397
384- if job. config. toplevel && job. config. cleanup
385- @tracepoint " clean-up" begin
386- @dispose pb= NewPMPassBuilder () begin
387- add! (pb, RecomputeGlobalsAAPass ())
388- add! (pb, GlobalOptPass ())
389- add! (pb, GlobalDCEPass ())
390- add! (pb, StripDeadPrototypesPass ())
391- add! (pb, ConstantMergePass ())
392- run! (pb, ir, llvm_machine (job. config. target))
393- end
394- end
395- end
396-
397- # finish the module
398- #
399- # we want to finish the module after optimization, so we cannot do so
400- # during deferred code generation. instead, process the deferred jobs
401- # here.
402- if job. config. toplevel
398+ # finish the module
399+ #
400+ # we want to finish the module after optimization, so we cannot do so
401+ # during deferred code generation. instead, process the deferred jobs
402+ # here.
403403 entry = finish_ir! (job, ir, entry)
404-
405404 for (job′, fn′) in jobs
406405 job′ == job && continue
407406 finish_ir! (job′, ir, functions (ir)[fn′])
@@ -422,7 +421,7 @@ const __llvm_initialized = Ref(false)
422421 end
423422
424423 if job. config. toplevel && job. config. validate
425- @tracepoint " Validation " begin
424+ @tracepoint " validation " begin
426425 check_ir (job, ir)
427426 end
428427 end
0 commit comments