Add JIT-time array map lookup inline optimization#46
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
==========================================
+ Coverage 74.12% 74.47% +0.35%
==========================================
Files 5 5
Lines 1341 1434 +93
Branches 153 176 +23
==========================================
+ Hits 994 1068 +74
- Misses 347 366 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| optimizeModule(M, vm.optimization_level, vm.disabled_passes_, | ||
| vm.log_passes_); | ||
| if (inline_array_map_lookup_helpers(M)) { | ||
| optimizeModule(M, vm.optimization_level, |
Contributor
There was a problem hiding this comment.
Why calling optimizeModule two times?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bpf_map_lookup_elemon array maps. When a BPF program calls helper-1 (bpf_map_lookup_elem) with a constant map handle that has been registered as an array map, the JIT rewrites the call into direct address arithmetic — eliminating the helper call entirely.register_array_map()API lets the host register an array map's metadata (fd/handle,max_entries,value_size, and data base pointer) before JIT compilation. During the LLVM IR rewrite pass, calls to_bpf_helper_ext_0001where arg0 matches a registered handle are replaced with an inline bounds-check and pointer computation:key < max_entries ? base + key * value_size : nullptr.bpf_get_helper_call_count()).key_size == 4, constant map handle only. Does not cover per-CPU array maps or hash maps.Changed files (7 files, +445 lines)
include/llvmbpf.hppregister_array_map()public API onllvmbpf_vmsrc/vm.cppsrc/llvm_jit_context.cppsrc/llvm_jit_context.hppexample/array_map_inline_bench.cppexample/CMakeLists.txttest/unit-test/vm_test.cppTest plan
vm_test.cpp): verify thatexec()returns the correct looked-up value andbpf_get_helper_call_count()reports 0 helper-1 calls after inliningarray_map_inline_bench.cpp): run./build/example/array_map_inline_benchand confirm ~1.3x speedup vs baseline (no inline)cmake --build build -jsucceeds with no warnings on the new filesctest --test-dir buildpasses (no regressions)🤖 Generated with Claude Code