Skip to content

Commit

Permalink
Update llvmrules.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Jan 9, 2025
1 parent f37271c commit b4c7245
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/rules/llvmrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1785,44 +1785,39 @@ end
end
origops = collect(operands(orig))
width = get_width(gutils)
origops = collect(operands(orig))
width = get_width(gutils)
shadowin = invert_pointer(gutils, origops[2], B)

args = LLVM.Value[
new_from_original(gutils, origops[1]),
invert_pointer(gutils, origops[2], B), # data
new_from_original(gutils, origops[3]),
new_from_original(gutils, origops[4]),
]
valTys = API.CValueType[
API.VT_Primal,
API.VT_Shadow,
API.VT_Primal,
API.VT_Primal,
]

if width == 1
vargs = args
cal = call_samefunc_with_inverted_bundles!(B, gutils, orig, vargs, valTys, false) #=lookup=#
shadowres = UndefValue(LLVM.LLVMType(API.EnzymeGetShadowType(width, value_type(orig))))
for idx = 1:width
ev = if width == 1
shadowin
else
extract_value!(B, shadowin, idx - 1)
end

args = LLVM.Value[
new_from_original(gutils, origops[1]),
ev, # data
new_from_original(gutils, origops[3]),
new_from_original(gutils, origops[4]),
]
# TODO do runtime activity relevant errors and checks

cal = call_samefunc_with_inverted_bundles!(B, gutils, orig, args, valTys, false) #=lookup=#
debug_from_orig!(gutils, cal, orig)
callconv!(cal, callconv(orig))
shadowres = cal
else
shadowres =
UndefValue(LLVM.LLVMType(API.EnzymeGetShadowType(width, value_type(orig))))
for idx = 1:width
vargs = LLVM.Value[
args[1],
extract_value!(B, args[2], idx - 1), # data
args[3],
args[4],
]
cal =
call_samefunc_with_inverted_bundles!(B, gutils, orig, vargs, valTys, false) #=lookup=#
debug_from_orig!(gutils, cal, orig)
callconv!(cal, callconv(orig))
if width == 1
shadowres = cal
else
shadowres = insert_value!(B, shadowres, call, idx - 1)
end
end
end
unsafe_store!(shadowR, shadowres.ref)

Expand Down

0 comments on commit b4c7245

Please sign in to comment.