Skip to content

Commit 6bce29b

Browse files
committed
Allocate scratch space for temp vars at the end of allocate_mem
1 parent 321415f commit 6bce29b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def update_max_temps_for_stmt(stmt):
425425
max_temps_needed = max(max_temps_needed, temps_needed)
426426

427427
for stmt in body:
428+
update_max_temps_for_stmt(stmt)
428429
has_metadata = False
429430
if isinstance(stmt, ast.If):
430431
if stmt.body:
@@ -545,6 +546,13 @@ def update_max_temps_for_stmt(stmt):
545546

546547
if double_alloc:
547548
local_sym_tab[f"{var_name}_tmp"] = LocalSymbol(var_tmp, tmp_ir_type)
549+
550+
logger.info(f"Temporary scratch space needed for calls: {max_temps_needed}")
551+
for i in range(max_temps_needed):
552+
temp_var = builder.alloca(ir.IntType(64), name=f"__helper_temp_{i}")
553+
temp_var.align = 8
554+
local_sym_tab[f"__helper_temp_{i}"] = LocalSymbol(temp_var, ir.IntType(64))
555+
548556
return local_sym_tab
549557

550558

0 commit comments

Comments
 (0)