Skip to content

Commit 5e5c14e

Browse files
r41k0uclaude
andcommitted
Core: Correct the pool-duplication TODO: the dead allocas do cost stack
The previous note claimed LLVM deletes the unreferenced duplicate temps. Measured: removing only the dead alloca from the IR moves the BPF frame from r10-32 to r10-24, so llc keeps it through frame layout and each duplicated i64 temp costs 8 bytes per nesting level. opt -O2 would remove it; the pipeline is llc only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 055a81b commit 5e5c14e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎pythonbpf/functions/functions_pass.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ def update_max_temps_for_stmt(stmt):
149149

150150
# TODO: allocate_mem is re-entered for every if body (handle_if_allocation),
151151
# and each level allocates a pool of its own even though the top-level count
152-
# already covers nested statements. The duplicates are unreferenced and LLVM
153-
# deletes them (verified: the BPF frame is identical with and without the
154-
# nesting), so this costs nothing at runtime; it is IR noise and a trap,
155-
# since only the last-allocated pool stays in local_sym_tab. Fix: count
156-
# recursively, allocate once at the top level.
152+
# already covers nested statements. Only the last-allocated pool stays in
153+
# local_sym_tab; the others are unreferenced, but llc does not delete
154+
# unreferenced allocas before frame layout (opt -O2 would, and the pipeline
155+
# is llc only), so each duplicated temp slot costs its size in BPF stack:
156+
# measured 8 bytes per i64 temp per nesting level. Fix: count recursively,
157+
# allocate once at the top level.
157158
allocate_temp_pool(builder, max_temps_needed, local_sym_tab)
158159

159160
return local_sym_tab

0 commit comments

Comments
 (0)