Conversation
b3ccc53 to
e0546f6
Compare
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/compiler.jl b/src/compiler.jl
index 9a4e1296..d14269e6 100644
--- a/src/compiler.jl
+++ b/src/compiler.jl
@@ -3845,18 +3845,18 @@ function move_sret_tofrom_roots!(builder::LLVM.IRBuilder, jltype::LLVM.LLVMType,
if direction == SRetPointerToRootPointer
outloc = inbounds_gep!(builder, jltype, sret, to_llvm(path))
outloc = load!(builder, ty, outloc)
- if must_cache
- API.SetMustCache!(outloc)
- end
+ if must_cache
+ API.SetMustCache!(outloc)
+ end
store!(builder, outloc, loc)
elseif direction == SRetValueToRootPointer
outloc = Enzyme.API.e_extract_value!(builder, sret, path)
store!(builder, outloc, loc)
elseif direction == RootPointerToSRetValue
loc = load!(builder, ty, loc)
- if must_cache
- API.SetMustCache!(loc)
- end
+ if must_cache
+ API.SetMustCache!(loc)
+ end
val = Enzyme.API.e_insert_value!(builder, val, loc, path)
elseif direction == NullifySRetValue
loc = unsafe_to_llvm(builder, nothing)
@@ -3920,13 +3920,13 @@ function nullify_rooted_values!(builder::LLVM.IRBuilder, sret::LLVM.Value)
move_sret_tofrom_roots!(builder, jltype, sret, root_ty, nothing, NullifySRetValue)
end
-function recombine_value!(builder::LLVM.IRBuilder, sret::LLVM.Value, roots::LLVM.Value; must_cache::Bool=false)::LLVM.Value
+function recombine_value!(builder::LLVM.IRBuilder, sret::LLVM.Value, roots::LLVM.Value; must_cache::Bool = false)::LLVM.Value
jltype = value_type(sret)
tracked = CountTrackedPointers(jltype)
@assert tracked.count > 0
@assert !tracked.all "Not tracked.all, jltype ($(string(jltype)))"
root_ty = convert(LLVMType, AnyArray(Int(tracked.count)))
- move_sret_tofrom_roots!(builder, jltype, sret, root_ty, roots, RootPointerToSRetValue; must_cache)
+ return move_sret_tofrom_roots!(builder, jltype, sret, root_ty, roots, RootPointerToSRetValue; must_cache)
end
function extract_roots_from_value!(builder::LLVM.IRBuilder, sret::LLVM.Value, roots::LLVM.Value)
@@ -3963,8 +3963,8 @@ function copy_floats_into!(builder::LLVM.IRBuilder, jltype::LLVM.LLVMType, dst::
end
if isa(ty, LLVM.FloatingPointType)
- dstloc = inbounds_gep!(builder, jltype, dst, to_llvm(path), "dstloc")
- srcloc = inbounds_gep!(builder, jltype, src, to_llvm(path), "srcloc")
+ dstloc = inbounds_gep!(builder, jltype, dst, to_llvm(path), "dstloc")
+ srcloc = inbounds_gep!(builder, jltype, src, to_llvm(path), "srcloc")
val = load!(builder, ty, srcloc)
st = store!(builder, val, dstloc)
continue
@@ -4003,63 +4003,65 @@ end
function extract_nonjlvalues_into!(builder::LLVM.IRBuilder, jltype::LLVM.LLVMType, dst::LLVM.Value, src::LLVM.Value)
count = 0
- todo = Tuple{Vector{Cuint},LLVM.LLVMType}[(
- Cuint[],
- jltype,
- )]
- function to_llvm(lst::Vector{Cuint})
- vals = LLVM.Value[]
- push!(vals, LLVM.ConstantInt(LLVM.IntType(64), 0))
- for i in lst
- push!(vals, LLVM.ConstantInt(LLVM.IntType(32), i))
- end
- return vals
- end
+ todo = Tuple{Vector{Cuint}, LLVM.LLVMType}[
+ (
+ Cuint[],
+ jltype,
+ ),
+ ]
+ function to_llvm(lst::Vector{Cuint})
+ vals = LLVM.Value[]
+ push!(vals, LLVM.ConstantInt(LLVM.IntType(64), 0))
+ for i in lst
+ push!(vals, LLVM.ConstantInt(LLVM.IntType(32), i))
+ end
+ return vals
+ end
- extracted = LLVM.Value[]
+ extracted = LLVM.Value[]
while length(todo) != 0
- path, ty = popfirst!(todo)
+ path, ty = popfirst!(todo)
- if isa(ty, LLVM.PointerType)
- if any_jltypes(ty)
- continue
- end
+ if isa(ty, LLVM.PointerType)
+ if any_jltypes(ty)
+ continue
end
+ end
- if isa(ty, LLVM.ArrayType) && any_jltypes(ty)
- for i = 1:length(ty)
- npath = copy(path)
- push!(npath, i - 1)
- push!(todo, (npath, eltype(ty)))
- end
- continue
+ if isa(ty, LLVM.ArrayType) && any_jltypes(ty)
+ for i in 1:length(ty)
+ npath = copy(path)
+ push!(npath, i - 1)
+ push!(todo, (npath, eltype(ty)))
end
+ continue
+ end
- if isa(ty, LLVM.VectorType) && any_jltypes(ty)
- for i = 1:size(ty)
- npath = copy(path)
- push!(npath, i - 1)
- push!(todo, (npath, eltype(ty)))
- end
- continue
+ if isa(ty, LLVM.VectorType) && any_jltypes(ty)
+ for i in 1:size(ty)
+ npath = copy(path)
+ push!(npath, i - 1)
+ push!(todo, (npath, eltype(ty)))
end
+ continue
+ end
- if isa(ty, LLVM.StructType) && any_jltypes(ty)
- for (i, t) in enumerate(LLVM.elements(ty))
- npath = copy(path)
- push!(npath, i - 1)
- push!(todo, (npath, t))
- end
- continue
+ if isa(ty, LLVM.StructType) && any_jltypes(ty)
+ for (i, t) in enumerate(LLVM.elements(ty))
+ npath = copy(path)
+ push!(npath, i - 1)
+ push!(todo, (npath, t))
end
-
- dstloc = inbounds_gep!(builder, jltype, dst, to_llvm(path), "dstloc")
- val = Enzyme.API.e_extract_value!(builder, src, path)
- st = store!(builder, val, dstloc)
+ continue
end
- return nothing
+ dstloc = inbounds_gep!(builder, jltype, dst, to_llvm(path), "dstloc")
+ val = Enzyme.API.e_extract_value!(builder, src, path)
+ st = store!(builder, val, dstloc)
+ end
+
+ return nothing
end
diff --git a/src/rules/customrules.jl b/src/rules/customrules.jl
index a4537e70..91ca676b 100644
--- a/src/rules/customrules.jl
+++ b/src/rules/customrules.jl
@@ -971,9 +971,9 @@ end
end
LLVM.API.LLVMAddCallSiteAttribute(res, LLVM.API.LLVMAttributeIndex(1), attr)
res = load!(B, sty, sret)
- if returnRoots !== nothing && VERSION >= v"1.12"
- res = recombine_value!(B, res, returnRoots; must_cache=true)
- end
+ if returnRoots !== nothing && VERSION >= v"1.12"
+ res = recombine_value!(B, res, returnRoots; must_cache = true)
+ end
end
if swiftself
attr = EnumAttribute("swiftself")
@@ -1003,19 +1003,19 @@ end
if RT <: Const
if needsPrimal
@assert RealRt == fwd_RT
- _, prim_sret, prim_roots = get_return_info(RealRt)
+ _, prim_sret, prim_roots = get_return_info(RealRt)
if prim_sret !== nothing
val = new_from_original(gutils, operands(orig)[1])
-
- if prim_roots !== nothing && VERSION >= v"1.12"
+
+ if prim_roots !== nothing && VERSION >= v"1.12"
extract_nonjlvalues_into!(B, value_type(res), val, res)
rval = new_from_original(gutils, operands(orig)[2])
- extract_roots_from_value!(B, res, rval)
- else
+ extract_roots_from_value!(B, res, rval)
+ else
store!(B, res, val)
- end
+ end
else
normalV = res.ref
end
@@ -1029,28 +1029,28 @@ end
ST = NTuple{Int(width),ST}
end
@assert ST == fwd_RT
- _, prim_sret, prim_roots = get_return_info(RealRt)
+ _, prim_sret, prim_roots = get_return_info(RealRt)
if prim_sret !== nothing
dval_ptr = invert_pointer(gutils, operands(orig)[1], B)
-
- droots = if prim_roots !== nothing && VERSION >= v"1.12"
- @assert !is_constant_value(gutils, operands(orig)[2])
- invert_pointer(gutils, operands(orig)[2], B)
- end
-
- for idx = 1:width
+
+ droots = if prim_roots !== nothing && VERSION >= v"1.12"
+ @assert !is_constant_value(gutils, operands(orig)[2])
+ invert_pointer(gutils, operands(orig)[2], B)
+ end
+
+ for idx in 1:width
ev = (width == 1) ? dval : extract_value!(B, dval, idx - 1)
pev = (width == 1) ? dval_ptr : extract_value!(B, dval_ptr, idx - 1)
-
- if prim_roots !== nothing && VERSION >= v"1.12"
- extract_nonjlvalues_into!(B, value_type(ev), pev, ev)
- rval = (width == 1) ? droots : extract_value!(B, droots, idx - 1)
+ if prim_roots !== nothing && VERSION >= v"1.12"
+ extract_nonjlvalues_into!(B, value_type(ev), pev, ev)
- extract_roots_from_value!(B, ev, rval)
- else
+ rval = (width == 1) ? droots : extract_value!(B, droots, idx - 1)
+
+ extract_roots_from_value!(B, ev, rval)
+ else
store!(B, ev, pev)
- end
+ end
end
else
shadowV = res.ref
@@ -1062,42 +1062,42 @@ end
BatchDuplicated{RealRt,Int(width)}
end
@assert ST == fwd_RT
-
- _, prim_sret, prim_roots = get_return_info(RealRt)
+
+ _, prim_sret, prim_roots = get_return_info(RealRt)
if prim_sret !== nothing
val = new_from_original(gutils, operands(orig)[1])
-
- res0 = extract_value!(B, res, 0)
- if prim_roots !== nothing && VERSION >= v"1.12"
+
+ res0 = extract_value!(B, res, 0)
+ if prim_roots !== nothing && VERSION >= v"1.12"
extract_nonjlvalues_into!(B, value_type(res0), val, res0)
rval = new_from_original(gutils, operands(orig)[2])
- extract_roots_from_value!(B, res0, rval)
- else
+ extract_roots_from_value!(B, res0, rval)
+ else
store!(B, res0, val)
- end
+ end
dval_ptr = invert_pointer(gutils, operands(orig)[1], B)
dval = extract_value!(B, res, 1)
-
- droots = if prim_roots !== nothing && VERSION >= v"1.12"
- @assert !is_constant_value(gutils, operands(orig)[2])
- invert_pointer(gutils, operands(orig)[2], B)
- end
-
- for idx = 1:width
+
+ droots = if prim_roots !== nothing && VERSION >= v"1.12"
+ @assert !is_constant_value(gutils, operands(orig)[2])
+ invert_pointer(gutils, operands(orig)[2], B)
+ end
+
+ for idx in 1:width
ev = (width == 1) ? dval : extract_value!(B, dval, idx - 1)
pev = (width == 1) ? dval_ptr : extract_value!(B, dval_ptr, idx - 1)
- if prim_roots !== nothing && VERSION >= v"1.12"
- extract_nonjlvalues_into!(B, value_type(ev), pev, ev)
+ if prim_roots !== nothing && VERSION >= v"1.12"
+ extract_nonjlvalues_into!(B, value_type(ev), pev, ev)
- rval = (width == 1) ? droots : extract_value!(B, droots, idx - 1)
+ rval = (width == 1) ? droots : extract_value!(B, droots, idx - 1)
- extract_roots_from_value!(B, ev, rval)
- else
+ extract_roots_from_value!(B, ev, rval)
+ else
store!(B, ev, pev)
- end
+ end
end
else
normalV = extract_value!(B, res, 0).ref
@@ -1836,9 +1836,9 @@ function enzyme_custom_common_rev(
)
res = load!(B, sty, sret)
API.SetMustCache!(res)
- if returnRoots !== nothing && VERSION >= v"1.12"
- res = recombine_value!(B, res, returnRoots; must_cache=true)
- end
+ if returnRoots !== nothing && VERSION >= v"1.12"
+ res = recombine_value!(B, res, returnRoots; must_cache = true)
+ end
end
if swiftself
attr = EnumAttribute("swiftself")
@@ -1946,19 +1946,19 @@ function enzyme_custom_common_rev(
if needsPrimal
@assert !isghostty(RealRt)
normalV = extract_value!(B, resV, idx)
- _, prim_sret, prim_roots = get_return_info(RealRt)
+ _, prim_sret, prim_roots = get_return_info(RealRt)
if prim_sret !== nothing
val = new_from_original(gutils, operands(orig)[1])
-
- if prim_roots !== nothing && VERSION >= v"1.12"
+
+ if prim_roots !== nothing && VERSION >= v"1.12"
extract_nonjlvalues_into!(B, value_type(normalV), val, normalV)
rval = new_from_original(gutils, operands(orig)[2])
- extract_roots_from_value!(B, normalV, rval)
- else
+ extract_roots_from_value!(B, normalV, rval)
+ else
store!(B, normalV, val)
- end
+ end
else
@assert value_type(normalV) == value_type(orig)
normalV = normalV.ref
@@ -1969,30 +1969,30 @@ function enzyme_custom_common_rev(
if needsShadowJL
@assert !isghostty(RealRt)
shadowV = extract_value!(B, resV, idx)
- _, prim_sret, prim_roots = get_return_info(RealRt)
+ _, prim_sret, prim_roots = get_return_info(RealRt)
if prim_sret !== nothing
dval = invert_pointer(gutils, operands(orig)[1], B)
- droots = if prim_roots !== nothing && VERSION >= v"1.12"
- @assert !is_constant_value(gutils, operands(orig)[2])
- invert_pointer(gutils, operands(orig)[2], B)
- end
+ droots = if prim_roots !== nothing && VERSION >= v"1.12"
+ @assert !is_constant_value(gutils, operands(orig)[2])
+ invert_pointer(gutils, operands(orig)[2], B)
+ end
- for idx = 1:width
+ for idx in 1:width
to_store =
(width == 1) ? shadowV : extract_value!(B, shadowV, idx - 1)
store_ptr = (width == 1) ? dval : extract_value!(B, dval, idx - 1)
- if prim_roots !== nothing && VERSION >= v"1.12"
- extract_nonjlvalues_into!(B, value_type(to_store), store_ptr, to_store)
+ if prim_roots !== nothing && VERSION >= v"1.12"
+ extract_nonjlvalues_into!(B, value_type(to_store), store_ptr, to_store)
rval = (width == 1) ? droots : extract_value!(B, droots, idx - 1)
- extract_roots_from_value!(B, to_store, rval)
- else
+ extract_roots_from_value!(B, to_store, rval)
+ else
store!(B, to_store, store_ptr)
- end
+ end
end
shadowV = C_NULL
else |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2804 +/- ##
==========================================
- Coverage 68.03% 67.81% -0.22%
==========================================
Files 58 58
Lines 20628 20717 +89
==========================================
+ Hits 14035 14050 +15
- Misses 6593 6667 +74 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Benchmark Results
Benchmark PlotsA plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/19622388008/artifacts/4656161654. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.