@@ -313,6 +313,7 @@ const __llvm_initialized = Ref(false)
313313 # global variables. this makes sure that the optimizer can, e.g.,
314314 # rewrite function signatures.
315315 if toplevel
316+ # TODO : there's no good API to use internalize with the new pass manager yet
316317 @dispose pm= ModulePassManager () begin
317318 exports = collect (values (jobs))
318319 for gvar in globals (ir)
@@ -340,20 +341,37 @@ const __llvm_initialized = Ref(false)
340341 # deferred codegen has some special optimization requirements,
341342 # which also need to happen _after_ regular optimization.
342343 # XXX : make these part of the optimizer pipeline?
343- has_deferred_jobs && @dispose pm= ModulePassManager () begin
344- # inline and optimize the call to e deferred code. in particular we want
345- # to remove unnecessary alloca's created by pass-by-ref semantics.
346- instruction_combining! (pm)
347- always_inliner! (pm)
348- scalar_repl_aggregates_ssa! (pm)
349- promote_memory_to_register! (pm)
350- gvn! (pm)
351-
352- # merge duplicate functions, since each compilation invocation emits everything
353- # XXX : ideally we want to avoid emitting these in the first place
354- merge_functions! (pm)
355-
356- run! (pm, ir)
344+ if has_deferred_jobs
345+ if use_newpm
346+ @dispose pb= PassBuilder () mpm= NewPMModulePassManager (pb) begin
347+ add! (mpm, NewPMFunctionPassManager) do fpm
348+ add! (fpm, InstCombinePass ())
349+ end
350+ add! (mpm, AlwaysInlinerPass ())
351+ add! (mpm, NewPMFunctionPassManager) do fpm
352+ add! (fpm, SROAPass ())
353+ add! (fpm, GVNPass ())
354+ end
355+ add! (mpm, MergeFunctionsPass ())
356+ run! (mpm, ir)
357+ end
358+ else
359+ @dispose pm= ModulePassManager () begin
360+ # inline and optimize the call to e deferred code. in particular we want
361+ # to remove unnecessary alloca's created by pass-by-ref semantics.
362+ instruction_combining! (pm)
363+ always_inliner! (pm)
364+ scalar_repl_aggregates_ssa! (pm)
365+ promote_memory_to_register! (pm)
366+ gvn! (pm)
367+
368+ # merge duplicate functions, since each compilation invocation emits everything
369+ # XXX : ideally we want to avoid emitting these in the first place
370+ merge_functions! (pm)
371+
372+ run! (pm, ir)
373+ end
374+ end
357375 end
358376 end
359377
@@ -363,18 +381,29 @@ const __llvm_initialized = Ref(false)
363381
364382 if cleanup
365383 @timeit_debug to " clean-up" begin
366- # we can only clean-up now, as optimization may lower or introduce calls to
367- # functions from the GPU runtime (e.g. julia.gc_alloc_obj -> gpu_gc_pool_alloc)
368- @dispose pm= ModulePassManager () begin
369- # eliminate all unused internal functions
370- global_optimizer! (pm)
371- global_dce! (pm)
372- strip_dead_prototypes! (pm)
373-
374- # merge constants (such as exception messages)
375- constant_merge! (pm)
376-
377- run! (pm, ir)
384+ if use_newpm
385+ @dispose pb= PassBuilder () mpm= NewPMModulePassManager (pb) begin
386+ add! (mpm, RecomputeGlobalsAAPass ())
387+ add! (mpm, GlobalOptPass ())
388+ add! (mpm, GlobalDCEPass ())
389+ add! (mpm, StripDeadPrototypesPass ())
390+ add! (mpm, ConstantMergePass ())
391+ run! (mpm, ir)
392+ end
393+ else
394+ # we can only clean-up now, as optimization may lower or introduce calls to
395+ # functions from the GPU runtime (e.g. julia.gc_alloc_obj -> gpu_gc_pool_alloc)
396+ @dispose pm= ModulePassManager () begin
397+ # eliminate all unused internal functions
398+ global_optimizer! (pm)
399+ global_dce! (pm)
400+ strip_dead_prototypes! (pm)
401+
402+ # merge constants (such as exception messages)
403+ constant_merge! (pm)
404+
405+ run! (pm, ir)
406+ end
378407 end
379408 end
380409 end
0 commit comments