Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ end
StringAttribute("enzyme_inactive"),
EnumAttribute("readnone"),
EnumAttribute("speculatable"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
EnumAttribute("nounwind"),
StringAttribute("enzyme_shouldrecompute"),
],
)
Expand All @@ -662,6 +666,10 @@ end
StringAttribute("enzyme_inactive"),
EnumAttribute("memory", NoEffects.data),
EnumAttribute("speculatable"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
EnumAttribute("nounwind"),
StringAttribute("enzyme_shouldrecompute"),
],
)
Expand All @@ -680,6 +688,9 @@ end
EnumAttribute("readonly"),
EnumAttribute("inaccessiblememonly", 0),
EnumAttribute("speculatable", 0),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
StringAttribute("enzyme_shouldrecompute"),
StringAttribute("enzyme_inactive"),
],
Expand All @@ -700,6 +711,9 @@ end
(MRI_NoModRef << getLocationPos(Other)),
).data,
),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
EnumAttribute("inaccessiblememonly", 0),
EnumAttribute("speculatable", 0),
StringAttribute("enzyme_shouldrecompute"),
Expand All @@ -722,6 +736,8 @@ end
StringAttribute("enzyme_shouldrecompute"),
StringAttribute("enzyme_inactive"),
StringAttribute("enzyme_no_escaping_allocation"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
StringAttribute("enzyme_ta_norecur"),
],
Expand All @@ -740,6 +756,8 @@ end
StringAttribute("enzyme_shouldrecompute"),
StringAttribute("enzyme_inactive"),
StringAttribute("enzyme_no_escaping_allocation"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
StringAttribute("enzyme_ta_norecur"),
],
Expand All @@ -762,6 +780,10 @@ end
EnumAttribute("readonly"),
EnumAttribute("inaccessiblememonly"),
EnumAttribute("speculatable"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
EnumAttribute("nounwind"),
StringAttribute("enzyme_shouldrecompute"),
StringAttribute("enzyme_inactive"),
StringAttribute("enzyme_no_escaping_allocation"),
Expand All @@ -784,6 +806,10 @@ end
).data,
),
EnumAttribute("speculatable"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nofree"),
EnumAttribute("nounwind"),
StringAttribute("enzyme_shouldrecompute"),
StringAttribute("enzyme_inactive"),
StringAttribute("enzyme_no_escaping_allocation"),
Expand Down Expand Up @@ -994,9 +1020,18 @@ end
name = T == Float32 ? name * "f" : name

attrs = if LLVM.version().major <= 15
LLVM.Attribute[LLVM.EnumAttribute("readnone"), StringAttribute("enzyme_shouldrecompute")]
LLVM.Attribute[LLVM.EnumAttribute("readnone"), StringAttribute("enzyme_shouldrecompute"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nounwind"),
EnumAttribute("nofree"),
]
else
LLVM.Attribute[EnumAttribute("memory", NoEffects.data), StringAttribute("enzyme_shouldrecompute")]
LLVM.Attribute[EnumAttribute("memory", NoEffects.data), StringAttribute("enzyme_shouldrecompute"),
EnumAttribute("willreturn"),
EnumAttribute("nosync"),
EnumAttribute("nounwind"),
EnumAttribute("nofree")]
end
handleCustom(state, custom, k_name, llvmfn, name, attrs)
return
Expand Down
64 changes: 64 additions & 0 deletions src/llvm/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ function annotate!(mod::LLVM.Module)
push!(function_attributes(fn), EnumAttribute("memory", NoEffects.data))
end
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_shouldrecompute"))
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand Down Expand Up @@ -466,6 +470,10 @@ function annotate!(mod::LLVM.Module)
),
)
end
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand All @@ -488,6 +496,10 @@ function annotate!(mod::LLVM.Module)
)
end
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_shouldrecompute"))
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand All @@ -500,6 +512,10 @@ function annotate!(mod::LLVM.Module)
if LLVM.version().major <= 15
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_math", "__dynamic_cast"))
end
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand Down Expand Up @@ -529,6 +545,9 @@ function annotate!(mod::LLVM.Module)
)
)
end
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
for u in LLVM.uses(fn)
c = LLVM.user(u)
if !isa(c, LLVM.CallInst)
Expand Down Expand Up @@ -579,6 +598,8 @@ function annotate!(mod::LLVM.Module)
push!(function_attributes(fn), EnumAttribute("memory", NoEffects.data))
end
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_shouldrecompute"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand All @@ -588,6 +609,10 @@ function annotate!(mod::LLVM.Module)
for fn in funcs[fname]
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_shouldrecompute"))
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_nocache"))
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
if LLVM.version().major <= 15
push!(function_attributes(fn), LLVM.EnumAttribute("readonly", 0))
else
Expand All @@ -605,6 +630,19 @@ function annotate!(mod::LLVM.Module)
end
end
end

for fname in (
"julia.safepoint",
)
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end

for fname in (
"julia.safepoint",
Expand Down Expand Up @@ -680,6 +718,9 @@ function annotate!(mod::LLVM.Module)
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), no_escaping_alloc)
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand All @@ -694,6 +735,7 @@ function annotate!(mod::LLVM.Module)
else
push!(function_attributes(fn), EnumAttribute("memory", NoEffects.data))
end
push!(function_attributes(fn), EnumAttribute("nounwind"))
end
end
end
Expand All @@ -712,6 +754,10 @@ function annotate!(mod::LLVM.Module)
)
push!(function_attributes(fn), no_escaping_alloc)
push!(function_attributes(fn), LLVM.EnumAttribute("allockind", (AllocFnKind(AFKE_Alloc) | AllocFnKind(AFKE_Uninitialized)).data))
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand All @@ -736,6 +782,10 @@ function annotate!(mod::LLVM.Module)
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_ReadOnlyOrThrow"))
push!(function_attributes(fn), EnumAttribute("nofree"))
push!(function_attributes(fn), EnumAttribute("nosync"))
push!(function_attributes(fn), EnumAttribute("nounwind"))
push!(function_attributes(fn), EnumAttribute("willreturn"))
end
end
end
Expand Down Expand Up @@ -815,6 +865,7 @@ function annotate!(mod::LLVM.Module)
push!(function_attributes(fn), LLVM.EnumAttribute("willreturn"))
push!(function_attributes(fn), LLVM.EnumAttribute("nounwind"))
push!(function_attributes(fn), LLVM.EnumAttribute("nofree"))
push!(function_attributes(fn), LLVM.EnumAttribute("nosync"))
accattr = if LLVM.version().major <= 15
LLVM.EnumAttribute("inaccessiblememonly")
else
Expand Down Expand Up @@ -933,6 +984,11 @@ function annotate!(mod::LLVM.Module)
for fname in ("llvm.julia.gc_preserve_begin", "llvm.julia.gc_preserve_end")
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), LLVM.EnumAttribute("mustprogress"))
push!(function_attributes(fn), LLVM.EnumAttribute("willreturn"))
push!(function_attributes(fn), LLVM.EnumAttribute("nounwind"))
push!(function_attributes(fn), LLVM.EnumAttribute("nofree"))
push!(function_attributes(fn), LLVM.EnumAttribute("nosync"))
push!(function_attributes(fn), LLVM.StringAttribute("enzyme_ReadOnlyOrThrow"))
if LLVM.version().major <= 15
push!(function_attributes(fn), LLVM.EnumAttribute("inaccessiblememonly"))
Expand All @@ -957,6 +1013,10 @@ function annotate!(mod::LLVM.Module)
for fname in ("jl_eqtable_get", "ijl_eqtable_get")
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), LLVM.EnumAttribute("mustprogress"))
push!(function_attributes(fn), LLVM.EnumAttribute("willreturn"))
push!(function_attributes(fn), LLVM.EnumAttribute("nofree"))
push!(function_attributes(fn), LLVM.EnumAttribute("nosync"))
push!(parameter_attributes(fn, 2), LLVM.StringAttribute("enzyme_inactive"))
if LLVM.version().major <= 15
push!(function_attributes(fn), LLVM.EnumAttribute("readonly"))
Expand Down Expand Up @@ -991,6 +1051,10 @@ function annotate!(mod::LLVM.Module)
for fname in ("jl_eqtable_put", "ijl_eqtable_put")
if haskey(funcs, fname)
for fn in funcs[fname]
push!(function_attributes(fn), LLVM.EnumAttribute("mustprogress"))
push!(function_attributes(fn), LLVM.EnumAttribute("willreturn"))
push!(function_attributes(fn), LLVM.EnumAttribute("nofree"))
push!(function_attributes(fn), LLVM.EnumAttribute("nosync"))
push!(parameter_attributes(fn, 2), LLVM.StringAttribute("enzyme_inactive"))
push!(parameter_attributes(fn, 4), LLVM.StringAttribute("enzyme_inactive"))
if value_type(LLVM.parameters(fn)[4]) isa LLVM.PointerType
Expand Down
Loading