Skip to content

Commit

Permalink
cleanup callocas
Browse files Browse the repository at this point in the history
  • Loading branch information
harkal committed Feb 19, 2025
1 parent 42c0c2f commit 5736ee8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 41 deletions.
3 changes: 0 additions & 3 deletions vyper/codegen/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ 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
22 changes: 1 addition & 21 deletions vyper/codegen/self_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,7 @@ def ir_for_self_call(stmt_expr, context):

# note: dst_tuple_t != args_tuple_t
dst_tuple_t = TupleT(tuple(func_t.argument_types))
if context.settings.experimental_codegen:
arg_items = ["multi"]
frame_info = func_t._ir_info.frame_info

for var in frame_info.frame_vars.values():
var = copy.copy(var)
alloca = var.alloca
assert alloca is not None
assert isinstance(var.pos, str) # help mypy
if not var.pos.startswith("$palloca"):
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)
args_dst = IRnode.from_list(arg_items, typ=dst_tuple_t)
else:
# legacy
args_dst = IRnode(func_t._ir_info.frame_info.frame_start, typ=dst_tuple_t, location=MEMORY)
args_dst = IRnode(func_t._ir_info.frame_info.frame_start, typ=dst_tuple_t, location=MEMORY)

# if one of the arguments is a self call, the argument
# buffer could get borked. to prevent against that,
Expand Down
18 changes: 1 addition & 17 deletions vyper/venom/ir_node_to_venom.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,15 @@

SymbolTable = dict[str, IROperand]
_alloca_table: dict[int, IROperand]
# assumption: callsites (return pc labels) are globally unique.
_callsites: dict[str, list[Alloca]]
MAIN_ENTRY_LABEL_NAME = "__main_entry"


# convert IRnode directly to venom
def ir_node_to_venom(ir: IRnode) -> IRContext:
_ = ir.unique_symbols # run unique symbols check

global _alloca_table, _callsites
global _alloca_table
_alloca_table = {}
_callsites = defaultdict(list)

ctx = IRContext()
fn = ctx.create_function(MAIN_ENTRY_LABEL_NAME)
Expand Down Expand Up @@ -165,7 +162,6 @@ def _append_return_args(fn: IRFunction, ofst: int = 0, size: int = 0):


def _handle_self_call(fn: IRFunction, ir: IRnode, symbols: SymbolTable) -> Optional[IROperand]:
global _callsites
setup_ir = ir.args[1]
goto_ir = [ir for ir in ir.args if ir.value == "goto"][0]
target_label = goto_ir.args[0].value # goto
Expand Down Expand Up @@ -572,18 +568,6 @@ def emit_body_blocks():
_alloca_table[alloca._id] = ptr
return _alloca_table[alloca._id]

elif ir.value.startswith("$calloca"):
global _callsites
alloca = ir.passthrough_metadata["alloca"]
assert alloca._callsite is not None
if alloca._id not in _alloca_table:
_alloca_table[alloca._id] = IRLiteral(alloca.offset)
ret = _alloca_table[alloca._id]
# assumption: callocas appear in the same order as the
# order of arguments to the function.
_callsites[alloca._callsite].append(alloca)
return ret

return symbols.get(ir.value)
elif ir.is_literal:
return IRLiteral(ir.value)
Expand Down

0 comments on commit 5736ee8

Please sign in to comment.