From 89c87082c903bc6918f82e479a43f7d0d708f787 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Mon, 22 Sep 2025 00:26:07 -0500 Subject: [PATCH 1/2] Add more attributes --- src/compiler.jl | 39 ++++++++++++++++++++-- src/llvm/attributes.jl | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/src/compiler.jl b/src/compiler.jl index f8410decb3..1afa1a5fd0 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -648,6 +648,10 @@ end StringAttribute("enzyme_inactive"), EnumAttribute("readnone"), EnumAttribute("speculatable"), + EnumAttribute("willreturn"), + EnumAttribute("nosync"), + EnumAttribute("nofree"), + EnumAttribute("nounwind"), StringAttribute("enzyme_shouldrecompute"), ], ) @@ -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"), ], ) @@ -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"), ], @@ -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"), @@ -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"), ], @@ -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"), ], @@ -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"), @@ -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"), @@ -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 diff --git a/src/llvm/attributes.jl b/src/llvm/attributes.jl index 9170e7be81..5def84eb77 100644 --- a/src/llvm/attributes.jl +++ b/src/llvm/attributes.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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", @@ -632,6 +670,9 @@ 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("willreturn")) end end end @@ -680,6 +721,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 @@ -694,6 +738,10 @@ function annotate!(mod::LLVM.Module) else push!(function_attributes(fn), EnumAttribute("memory", NoEffects.data)) 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 @@ -712,6 +760,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 @@ -736,6 +788,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 @@ -815,6 +871,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 @@ -933,6 +990,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")) @@ -957,6 +1019,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")) @@ -983,6 +1049,10 @@ function annotate!(mod::LLVM.Module) for fn in funcs[fname] push!(parameter_attributes(fn, 3), LLVM.EnumAttribute("readonly")) push!(parameter_attributes(fn, 3), LLVM.EnumAttribute("nocapture")) + 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")) end end end @@ -991,6 +1061,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 From 423dfe38d7a2967496b08e8eeddac9df28d3b140 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Mon, 22 Sep 2025 00:35:00 -0500 Subject: [PATCH 2/2] reduce --- src/llvm/attributes.jl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/llvm/attributes.jl b/src/llvm/attributes.jl index 5def84eb77..32480e29d2 100644 --- a/src/llvm/attributes.jl +++ b/src/llvm/attributes.jl @@ -670,9 +670,6 @@ 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("willreturn")) end end end @@ -738,10 +735,7 @@ function annotate!(mod::LLVM.Module) else push!(function_attributes(fn), EnumAttribute("memory", NoEffects.data)) 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 @@ -1049,10 +1043,6 @@ function annotate!(mod::LLVM.Module) for fn in funcs[fname] push!(parameter_attributes(fn, 3), LLVM.EnumAttribute("readonly")) push!(parameter_attributes(fn, 3), LLVM.EnumAttribute("nocapture")) - 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")) end end end