Skip to content

Commit e773e3b

Browse files
committed
separate local readonly
1 parent 1736545 commit e773e3b

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

src/llvm/attributes.jl

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,59 @@ function annotate!(mod::LLVM.Module)
716716
end
717717
end
718718

719+
for fname in (
720+
"julia.gc_alloc_obj",
721+
"jl_gc_alloc_typed",
722+
"ijl_gc_alloc_typed",
723+
"jl_alloc_genericmemory",
724+
"ijl_alloc_genericmemory",
725+
"jl_alloc_array_1d",
726+
"jl_alloc_array_2d",
727+
"jl_alloc_array_3d",
728+
"ijl_alloc_array_1d",
729+
"ijl_alloc_array_2d",
730+
"ijl_alloc_array_3d",
731+
"jl_alloc_genericmemory",
732+
"ijl_alloc_genericmemory",
733+
"ijl_new_array",
734+
"jl_new_array"
735+
)
736+
if haskey(funcs, fname)
737+
for fn in funcs[fname]
738+
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_ReadOnlyOrThrow"))
739+
end
740+
end
741+
end
742+
743+
for fname in (
744+
"jl_box_float32",
745+
"jl_box_float64",
746+
"jl_box_int32",
747+
"jl_box_int64",
748+
"ijl_box_float32",
749+
"ijl_box_float64",
750+
"ijl_box_int32",
751+
"ijl_box_int64",
752+
"jl_array_copy",
753+
"ijl_array_copy",
754+
"jl_genericmemory_slice",
755+
"ijl_genericmemory_slice",
756+
"jl_genericmemory_copy_slice",
757+
"ijl_genericmemory_copy_slice",
758+
"jl_f_tuple",
759+
"ijl_f_tuple",
760+
"jl_new_structv",
761+
"ijl_new_structv",
762+
"jl_idtable_rehash",
763+
"ijl_idtable_rehash",
764+
)
765+
if haskey(funcs, fname)
766+
for fn in funcs[fname]
767+
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_LocalReadOnlyOrThrow"))
768+
end
769+
end
770+
end
771+
719772
for fname in (
720773
"julia.gc_alloc_obj",
721774
"jl_gc_alloc_typed",
@@ -755,7 +808,6 @@ function annotate!(mod::LLVM.Module)
755808
)
756809
if haskey(funcs, fname)
757810
for fn in funcs[fname]
758-
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_ReadOnlyOrThrow"))
759811
push!(return_attributes(fn), LLVM.EnumAttribute("noalias", 0))
760812
push!(return_attributes(fn), LLVM.EnumAttribute("nonnull", 0))
761813
push!(function_attributes(fn), no_escaping_alloc)

test/runtests.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,6 @@ sqrtsumsq2(x) = (sum(abs2, x)*sum(abs2,x))
296296
Enzyme.autodiff(Reverse, sqrtsumsq2, Duplicated(x,dx))
297297
end
298298

299-
300-
function isherm(x)
301-
if LinearAlgebra.ishermitian(x)
302-
x[3]
303-
else
304-
x[2]
305-
end
306-
end
307-
308-
# We want to make sure we can detect ishermitian as inactive / readonly_or_throw
309-
@testset "Readonly optimization" begin
310-
fn = sprint() do io
311-
Enzyme.Compiler.enzyme_code_llvm(io, isherm, Active, Tuple{Duplicated{Matrix{Float64}}}; dump_module=true)
312-
end
313-
@test !occursin("diffejulia_ishermitian",fn)
314-
end
315-
316299
@noinline function prt_sret(A)
317300
A[1] *= 2
318301
return (A, A[2])

0 commit comments

Comments
 (0)