Skip to content

Commit 2cf9833

Browse files
committed
Add function deduplication and tests
1 parent 93bcc15 commit 2cf9833

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/StaticCompiler.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ function native_llvm_module(funcs::Array; mangle_names = false, kwargs...)
478478
end
479479
end
480480
end
481+
LLVM.ModulePassManager() do pass_manager #remove duplicate functions
482+
LLVM.merge_functions!(pass_manager)
483+
LLVM.run!(pass_manager, mod)
484+
end
481485
return mod
482486
end
483487

test/testcore.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,29 @@ end
292292
@test isa(r, Base.Process)
293293
@test r.exitcode == 0
294294
end
295+
296+
297+
@testset "Multiple Function Dylibs" begin
298+
299+
@noinline square(n) = n*n
300+
301+
function squaresquare(n)
302+
square(square(n))
303+
end
304+
305+
function squaresquaresquare(n)
306+
square(squaresquare(n))
307+
end
308+
309+
funcs = [(squaresquare,(Float64,)), (squaresquaresquare,(Float64,))]
310+
filepath = compile_shlib(funcs, mangle_names=true)
311+
312+
ptr = Libdl.dlopen(filepath, Libdl.RTLD_LOCAL)
313+
314+
fptr2 = Libdl.dlsym(ptr, "squaresquare")
315+
@test ccall(fptr2, Float64, (Float64,), 10.) == squaresquare(10.)
316+
317+
fptr = Libdl.dlsym(ptr, "squaresquaresquare")
318+
@test ccall(fptr2, Float64, (Float64,), 10.) == squaresquaresquare(10.)
319+
#Compile dylib
320+
end

0 commit comments

Comments
 (0)