Skip to content

Commit 042f036

Browse files
committed
Invoke the new interface method after kernel metadata is set.
1 parent e082201 commit 042f036

File tree

1 file changed

+51
-52
lines changed

1 file changed

+51
-52
lines changed

src/driver.jl

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,18 @@ const __llvm_initialized = Ref(false)
320320
end
321321

322322
@tracepoint "IR post-processing" begin
323-
# mark everything internal except for entrypoints and any exported
324-
# global variables. this makes sure that the optimizer can, e.g.,
325-
# rewrite function signatures.
323+
# mark the kernel entry-point functions (optimization may need it)
324+
if job.config.kernel
325+
push!(metadata(ir)["julia.kernel"], MDNode([entry]))
326+
327+
# IDEA: save all jobs, not only kernels, and save other attributes
328+
# so that we can reconstruct the CompileJob instead of setting it globally
329+
end
330+
326331
if job.config.toplevel
332+
# mark everything internal except for entrypoints and any exported
333+
# global variables. this makes sure that the optimizer can, e.g.,
334+
# rewrite function signatures.
327335
preserved_gvs = collect(values(jobs))
328336
for gvar in globals(ir)
329337
if linkage(gvar) == LLVM.API.LLVMExternalLinkage
@@ -339,64 +347,55 @@ const __llvm_initialized = Ref(false)
339347
run!(pm, ir)
340348
end
341349
end
342-
end
343-
344-
# mark the kernel entry-point functions (optimization may need it)
345-
if job.config.kernel
346-
push!(metadata(ir)["julia.kernel"], MDNode([entry]))
347-
348-
# IDEA: save all jobs, not only kernels, and save other attributes
349-
# so that we can reconstruct the CompileJob instead of setting it globally
350-
end
351-
352-
if job.config.toplevel && job.config.optimize
353-
@tracepoint "optimization" begin
354-
optimize!(job, ir; job.config.opt_level)
355350

356-
# deferred codegen has some special optimization requirements,
357-
# which also need to happen _after_ regular optimization.
358-
# XXX: make these part of the optimizer pipeline?
359-
if has_deferred_jobs
360-
@dispose pb=NewPMPassBuilder() begin
361-
add!(pb, NewPMFunctionPassManager()) do fpm
362-
add!(fpm, InstCombinePass())
363-
end
364-
add!(pb, AlwaysInlinerPass())
365-
add!(pb, NewPMFunctionPassManager()) do fpm
366-
add!(fpm, SROAPass())
367-
add!(fpm, GVNPass())
351+
finish_linked_module!(job, ir)
352+
353+
if job.config.optimize
354+
@tracepoint "optimization" begin
355+
optimize!(job, ir; job.config.opt_level)
356+
357+
# deferred codegen has some special optimization requirements,
358+
# which also need to happen _after_ regular optimization.
359+
# XXX: make these part of the optimizer pipeline?
360+
if has_deferred_jobs
361+
@dispose pb=NewPMPassBuilder() begin
362+
add!(pb, NewPMFunctionPassManager()) do fpm
363+
add!(fpm, InstCombinePass())
364+
end
365+
add!(pb, AlwaysInlinerPass())
366+
add!(pb, NewPMFunctionPassManager()) do fpm
367+
add!(fpm, SROAPass())
368+
add!(fpm, GVNPass())
369+
end
370+
add!(pb, MergeFunctionsPass())
371+
run!(pb, ir, llvm_machine(job.config.target))
368372
end
369-
add!(pb, MergeFunctionsPass())
370-
run!(pb, ir, llvm_machine(job.config.target))
371373
end
372374
end
373-
end
374375

375-
# optimization may have replaced functions, so look the entry point up again
376-
entry = functions(ir)[entry_fn]
377-
end
376+
# optimization may have replaced functions, so look the entry point up again
377+
entry = functions(ir)[entry_fn]
378+
end
378379

379-
if job.config.toplevel && job.config.cleanup
380-
@tracepoint "clean-up" begin
381-
@dispose pb=NewPMPassBuilder() begin
382-
add!(pb, RecomputeGlobalsAAPass())
383-
add!(pb, GlobalOptPass())
384-
add!(pb, GlobalDCEPass())
385-
add!(pb, StripDeadPrototypesPass())
386-
add!(pb, ConstantMergePass())
387-
run!(pb, ir, llvm_machine(job.config.target))
380+
if job.config.cleanup
381+
@tracepoint "clean-up" begin
382+
@dispose pb=NewPMPassBuilder() begin
383+
add!(pb, RecomputeGlobalsAAPass())
384+
add!(pb, GlobalOptPass())
385+
add!(pb, GlobalDCEPass())
386+
add!(pb, StripDeadPrototypesPass())
387+
add!(pb, ConstantMergePass())
388+
run!(pb, ir, llvm_machine(job.config.target))
389+
end
388390
end
389391
end
390-
end
391392

392-
# finish the module
393-
#
394-
# we want to finish the module after optimization, so we cannot do so
395-
# during deferred code generation. instead, process the deferred jobs
396-
# here.
397-
if job.config.toplevel
393+
# finish the module
394+
#
395+
# we want to finish the module after optimization, so we cannot do so
396+
# during deferred code generation. instead, process the deferred jobs
397+
# here.
398398
entry = finish_ir!(job, ir, entry)
399-
400399
for (job′, fn′) in jobs
401400
job′ == job && continue
402401
finish_ir!(job′, ir, functions(ir)[fn′])
@@ -417,7 +416,7 @@ const __llvm_initialized = Ref(false)
417416
end
418417

419418
if job.config.toplevel && job.config.validate
420-
@tracepoint "Validation" begin
419+
@tracepoint "validation" begin
421420
check_ir(job, ir)
422421
end
423422
end

0 commit comments

Comments
 (0)