Skip to content

Commit

Permalink
add cacheing of abi_ofst in getelemptr_abi
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberthirst committed Apr 12, 2024
1 parent 50f9153 commit c8ccd45
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions vyper/codegen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,19 @@ def _getelemptr_abi_helper(parent, member_t, ofst, clamp_=True):
ofst_ir = add_ofst(parent, abi_ofst)

if parent.location == MEMORY: # TODO: replace with utility function
# TODO cache parent and abi_ofst
bound = parent_abi_t.size_bound()
end = ["add", abi_ofst, member_abi_t.size_bound()]
# head + member_size is le upper_bound of the parent buffer
end_clamped = clamp("le", end, bound)
# head + member_size doesn't overflow and thus is ge lower_bound of the parent buffer
end_clamped = ["assert", ["gt", end_clamped, abi_ofst]]
ofst_ir = add_ofst(parent, abi_ofst)
ofst_ir = [
"seq",
end_clamped,
ofst_ir
]
with abi_ofst.cache_when_complex("abi_ofst") as (b1, abi_ofst):
bound = parent_abi_t.size_bound()
end = ["add", abi_ofst, member_abi_t.size_bound()]
# head + member_size must be 'le' upper_bound of the parent buffer
end_clamped = clamp("le", end, bound)
# head + member_size must be 'gt' lower_bound of the parent buffer (no overflow)
end_clamped = ["assert", ["gt", end_clamped, abi_ofst]]
ofst_ir = [
"seq",
end_clamped,
add_ofst(parent, abi_ofst)
]
ofst_ir = b1.resolve(ofst_ir)

return IRnode.from_list(
ofst_ir,
Expand Down

0 comments on commit c8ccd45

Please sign in to comment.