Skip to content

Commit

Permalink
reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Dec 4, 2024
1 parent 47d8813 commit d38f1a4
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions src/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ end
function run_jl_pipeline(pm::ModulePassManager, tm::LLVM.TargetMachine; kwargs...)
config = Ref(pipeline_options(; kwargs...))
function jl_pipeline(m)
if tm.ref != C_NULL
@dispose pb = NewPMPassBuilder() begin
add!(pb, NewPMModulePassManager()) do mpm
@ccall jl_build_newpm_pipeline(
mpm.ref::Ptr{Cvoid},
pb.ref::Ptr{Cvoid},
config::Ptr{PipelineConfig},
)::Cvoid
end
LLVM.run!(mpm, m, tm)
@dispose pb = NewPMPassBuilder() begin
add!(pb, NewPMModulePassManager()) do mpm
@ccall jl_build_newpm_pipeline(
mpm.ref::Ptr{Cvoid},
pb.ref::Ptr{Cvoid},
config::Ptr{PipelineConfig},
)::Cvoid
end
LLVM.run!(mpm, m, tm)
end
return true
end
Expand Down Expand Up @@ -209,9 +207,7 @@ end

function loop_optimizations_tm!(pm::LLVM.ModulePassManager, tm::LLVM.TargetMachine)
@static if true || VERSION < v"1.11-"
if tm.ref != C_NULL
lower_simdloop_tm!(pm, tm)
end
lower_simdloop_tm!(pm, tm)
licm!(pm)
if LLVM.version() >= v"15"
simple_loop_unswitch_legacy!(pm)
Expand Down Expand Up @@ -246,10 +242,8 @@ function more_loop_optimizations_tm!(pm::LLVM.ModulePassManager, tm::LLVM.Target
loop_idiom!(pm)

# LoopRotate strips metadata from terminator, so run LowerSIMD afterwards
if tm.ref != C_NULL
lower_simdloop_tm!(pm, tm) # Annotate loop marked with "loopinfo" as LLVM parallel loop
licm!(pm)
end
lower_simdloop_tm!(pm, tm) # Annotate loop marked with "loopinfo" as LLVM parallel loop
licm!(pm)
julia_licm_tm!(pm, tm)
# Subsequent passes not stripping metadata from terminator
instruction_combining!(pm) # TODO: createInstSimplifyLegacy
Expand Down Expand Up @@ -462,20 +456,19 @@ function optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
# then finish Julia GC
ModulePassManager() do pm
add_library_info!(pm, triple(mod))
if tm.ref != C_NULL
#add_transform_info!(pm, tm)
end
#propagate_julia_addrsp_tm!(pm, tm)
add_transform_info!(pm, tm)

propagate_julia_addrsp_tm!(pm, tm)
scoped_no_alias_aa!(pm)
type_based_alias_analysis!(pm)
basic_alias_analysis!(pm)
cfgsimplification!(pm)
dce!(pm)
#cpu_features_tm!(pm, tm)
cpu_features_tm!(pm, tm)
scalar_repl_aggregates_ssa!(pm) # SSA variant?
mem_cpy_opt!(pm)
always_inliner!(pm)
#alloc_opt_tm!(pm, tm)
alloc_opt_tm!(pm, tm)
LLVM.run!(pm, mod)
end

Expand All @@ -484,9 +477,7 @@ function optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
ModulePassManager() do pm

add_library_info!(pm, triple(mod))
if tm.ref != C_NULL
add_transform_info!(pm, tm)
end
add_transform_info!(pm, tm)

scoped_no_alias_aa!(pm)
type_based_alias_analysis!(pm)
Expand All @@ -500,9 +491,8 @@ function optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)

ModulePassManager() do pm
add_library_info!(pm, triple(mod))
if tm.ref != C_NULL
add_transform_info!(pm, tm)
end
add_transform_info!(pm, tm)

scoped_no_alias_aa!(pm)
type_based_alias_analysis!(pm)
basic_alias_analysis!(pm)
Expand Down Expand Up @@ -576,9 +566,7 @@ function optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
# known functions
ModulePassManager() do pm
add_library_info!(pm, triple(mod))
if tm.ref != C_NULL
add_transform_info!(pm, tm)
end
add_transform_info!(pm, tm)

scoped_no_alias_aa!(pm)
type_based_alias_analysis!(pm)
Expand All @@ -597,9 +585,7 @@ end
# https://github.com/JuliaLang/julia/blob/2eb5da0e25756c33d1845348836a0a92984861ac/src/aotcompile.cpp#L603
function addTargetPasses!(pm::LLVM.ModulePassManager, tm::LLVM.TargetMachine, trip::String)
add_library_info!(pm, trip)
if tm.ref != C_NULL
add_transform_info!(pm, tm)
end
add_transform_info!(pm, tm)
end

# https://github.com/JuliaLang/julia/blob/2eb5da0e25756c33d1845348836a0a92984861ac/src/aotcompile.cpp#L620
Expand Down

0 comments on commit d38f1a4

Please sign in to comment.