Skip to content

Commit 047f361

Browse files
committed
Allocate twice for map lookups
1 parent 489244a commit 047f361

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pythonbpf/binary_ops.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def store_through_chain(value, chain, builder):
5555

5656
def handle_binary_op_impl(rval, builder, local_sym_tab):
5757
op = rval.op
58-
left, _, _ = get_operand_value(rval.left, builder, local_sym_tab)
59-
right, _, _ = get_operand_value(rval.right, builder, local_sym_tab)
58+
left, lchain, _ = get_operand_value(rval.left, builder, local_sym_tab)
59+
right, rchain, _ = get_operand_value(rval.right, builder, local_sym_tab)
6060
logger.info(f"left is {left}, right is {right}, op is {op}")
6161

62+
logger.info(f"left chain: {lchain}, right chain: {rchain}")
63+
6264
# Map AST operation nodes to LLVM IR builder methods
6365
op_map = {
6466
ast.Add: builder.add,

pythonbpf/functions/functions_pass.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,17 @@ def allocate_mem(
455455
f"Pre-allocated variable {var_name} for struct {call_type}"
456456
)
457457
elif isinstance(rval.func, ast.Attribute):
458+
# Map method call
458459
ir_type = ir.PointerType(ir.IntType(64))
459460
var = builder.alloca(ir_type, name=var_name)
461+
462+
# declare an intermediate ptr type for map lookup
463+
ir_type = ir.IntType(64)
464+
var_tmp = builder.alloca(ir_type, name=f"{var_name}_tmp")
460465
# var.align = ir_type.width // 8
461-
logger.info(f"Pre-allocated variable {var_name} for map")
466+
logger.info(
467+
f"Pre-allocated variable {var_name} and {var_name}_tmp for map"
468+
)
462469
else:
463470
logger.info("Unsupported assignment call function type")
464471
continue
@@ -496,6 +503,9 @@ def allocate_mem(
496503
local_sym_tab[var_name] = LocalSymbol(var, ir_type, call_type)
497504
else:
498505
local_sym_tab[var_name] = LocalSymbol(var, ir_type)
506+
507+
if var_tmp:
508+
local_sym_tab[f"{var_name}_tmp"] = LocalSymbol(var_tmp, ir_type)
499509
return local_sym_tab
500510

501511

0 commit comments

Comments
 (0)