diff --git a/src/interop/passes.jl b/src/interop/passes.jl index 70102477..271438f2 100644 --- a/src/interop/passes.jl +++ b/src/interop/passes.jl @@ -45,27 +45,54 @@ Base.string(options::GCInvariantVerifierPassOptions) = options.strong ? "" + final_options = String[] + push!(final_options, "level=$(options.opt_level)") + + function handle_option(name::Symbol) + val = getfield(options, name) + if val !== nothing + push!(final_options, val ? String(name) : "no_$name") + end + end + handle_option(:lower_intrinsics) + handle_option(:dump_native) + handle_option(:external_use) + handle_option(:llvm_only) + if VERSION >= v"1.12.0-DEV.1029" || # JuliaLang/julia#55407 + (v"1.11.0-rc3" <= VERSION < v"1.12-") # backport + handle_option(:always_inline) + handle_option(:enable_early_simplifications) + handle_option(:enable_early_optimizations) + handle_option(:enable_scalar_optimizations) + handle_option(:enable_loop_optimizations) + handle_option(:enable_vector_pipeline) + handle_option(:remove_ni) + handle_option(:cleanup) + handle_option(:warn_missed_transformations) + end + + "<" * join(final_options, ";") * ">" end + @pipeline "julia" JuliaPipeline JuliaPipelineOptions # XXX: if we go through the PassBuilder parser, Julia won't insert the PassBuilder's diff --git a/test/interop_tests.jl b/test/interop_tests.jl index 09d93d2a..7c038b4c 100644 --- a/test/interop_tests.jl +++ b/test/interop_tests.jl @@ -160,35 +160,71 @@ end end +function test_module() + mod = LLVM.Module("test") + ft = LLVM.FunctionType(LLVM.VoidType()) + fn = LLVM.Function(mod, "SomeFunction", ft) -VERSION < v"1.11.0-DEV.428" && @testset "passes" begin - -@dispose ctx=Context() mod=LLVM.Module("SomeModule") pm=ModulePassManager() begin - -demote_float16!(pm) -julia_licm!(pm) -alloc_opt!(pm) -barrier_noop!(pm) -gc_invariant_verifier!(pm) -gc_invariant_verifier!(pm, true) -lower_exc_handlers!(pm) -combine_mul_add!(pm) -multi_versioning!(pm) -propagate_julia_addrsp!(pm) -lower_ptls!(pm) -lower_ptls!(pm, true) -lower_simdloop!(pm) -remove_ni!(pm) -late_lower_gc_frame!(pm) -final_lower_gc!(pm) -cpu_features!(pm) + @dispose builder=IRBuilder() begin + entry = BasicBlock(fn, "entry") + position!(builder, entry) + ret!(builder) + end + + return mod end -@test "we didn't crash!" != "" +@testset "passes" begin + if VERSION < v"1.11.0-DEV.428" + @dispose ctx=Context() mod=test_module() pm=ModulePassManager() begin + + demote_float16!(pm) + julia_licm!(pm) + alloc_opt!(pm) + barrier_noop!(pm) + gc_invariant_verifier!(pm) + gc_invariant_verifier!(pm, true) + lower_exc_handlers!(pm) + combine_mul_add!(pm) + multi_versioning!(pm) + propagate_julia_addrsp!(pm) + lower_ptls!(pm) + lower_ptls!(pm, true) + lower_simdloop!(pm) + remove_ni!(pm) + late_lower_gc_frame!(pm) + final_lower_gc!(pm) + cpu_features!(pm) -end + end + @test "we didn't crash!" != "" + end + + @dispose ctx=Context() mod=test_module() begin + # by string + @test run!("julia", mod) === nothing + # by object + @test run!(JuliaPipeline(), mod) === nothing + + # by object with options + pipeline = JuliaPipeline(opt_level=2) + @test run!(pipeline, mod) === nothing + + if VERSION >= v"1.12.0-DEV.1029" || # JuliaLang/julia#55407 + (v"1.11.0-rc3" <= VERSION < v"1.12-") # backport + pipeline = JuliaPipeline(opt_level=3, enable_vector_pipeline=false) + @test run!(pipeline, mod) === nothing + # TODO: check that the vector pipeline didn't run + + pipeline = JuliaPipeline(enable_early_simplifications=false, + enable_early_optimizations=false) + @test contains(string(pipeline), "no_enable_early_simplifications") + @test contains(string(pipeline), "no_enable_early_optimizations") + end + end +end @testset "intrinsics" begin @test assume(true) === nothing diff --git a/test/newpm_tests.jl b/test/newpm_tests.jl index 4a4183a2..8c1d2a37 100644 --- a/test/newpm_tests.jl +++ b/test/newpm_tests.jl @@ -230,19 +230,6 @@ end end @testset "julia" begin - @testset "pipeline" begin - @dispose ctx=Context() mod=test_module() begin - # by string - @test run!("julia", mod) === nothing - - # by object - @test run!(JuliaPipeline(), mod) === nothing - - # by object with options - @test run!(JuliaPipeline(opt_level=2), mod) === nothing - end - end - @testset "passes" begin @dispose ctx=Context() pb=NewPMPassBuilder() begin basicSimplifyCFGOptions =