Skip to content

Commit

Permalink
add callsite to calloca
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Dec 2, 2024
1 parent f660a3c commit 23d1267
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions vyper/codegen/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Alloca:

_id: int

# special metadata for calloca. hint for venom to tie calloca to call site.
_callsite: Optional[str] = None

def __post_init__(self):
assert self.typ.memory_bytes_required == self.size

Expand Down
2 changes: 2 additions & 0 deletions vyper/codegen/self_call.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import dataclasses

from vyper.codegen.core import _freshname, eval_once_check, make_setter
from vyper.codegen.ir_node import IRnode
Expand Down Expand Up @@ -81,6 +82,7 @@ def ir_for_self_call(stmt_expr, context):
continue
newname = var.pos.replace("$palloca", "$calloca")
var.pos = newname
alloca = dataclasses.replace(alloca, _callsite=return_label)
irnode = var.as_ir_node()
irnode.passthrough_metadata["alloca"] = alloca
arg_items.append(irnode)
Expand Down
4 changes: 3 additions & 1 deletion vyper/venom/ir_node_to_venom.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,10 @@ def emit_body_blocks():
elif ir.value.startswith("$calloca"):
alloca = ir.passthrough_metadata["alloca"]
if alloca._id not in _alloca_table:
assert alloca._callsite is not None
callsite = IRLabel(alloca._callsite)
ptr = fn.get_basic_block().append_instruction(
"calloca", alloca.offset, alloca.size, alloca._id
"calloca", alloca.offset, alloca.size, alloca._id, callsite
)
_alloca_table[alloca._id] = ptr
return _alloca_table[alloca._id]
Expand Down

0 comments on commit 23d1267

Please sign in to comment.