Skip to content

Commit adf3256

Browse files
bpf passthrough gen in codegen
Signed-off-by: varun-r-mallya <[email protected]>
1 parent 21cea97 commit adf3256

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

pythonbpf/codegen.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ def finalize_module(original_str):
3636
replacement = r'\1 "btf_ama"'
3737
return re.sub(pattern, replacement, original_str)
3838

39+
def bpf_passthrough_gen(module):
40+
i32_ty = ir.IntType(32)
41+
ptr_ty = ir.PointerType(ir.IntType(8))
42+
fnty = ir.FunctionType(ptr_ty, [i32_ty, ptr_ty])
43+
44+
# Declare the intrinsic
45+
passthrough = ir.Function(module, fnty, "llvm.bpf.passthrough.p0.p0")
46+
47+
# Set function attributes
48+
# TODO: the ones commented are supposed to be there but cannot be added due to llvmlite limitations at the moment
49+
# passthrough.attributes.add("nofree")
50+
# passthrough.attributes.add("nosync")
51+
passthrough.attributes.add("nounwind")
52+
# passthrough.attributes.add("memory(none)")
53+
54+
return passthrough
55+
3956

4057
def find_bpf_chunks(tree):
4158
"""Find all functions decorated with @bpf in the AST."""
@@ -57,6 +74,8 @@ def processor(source_code, filename, module):
5774
for func_node in bpf_chunks:
5875
logger.info(f"Found BPF function/struct: {func_node.name}")
5976

77+
bpf_passthrough_gen(module)
78+
6079
vmlinux_symtab = vmlinux_proc(tree, module)
6180
if vmlinux_symtab:
6281
handler = VmlinuxHandler.initialize(vmlinux_symtab)

pythonbpf/vmlinux_parser/import_detector.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,9 @@ def detect_import_statement(tree: ast.AST) -> list[tuple[str, ast.ImportFrom]]:
7777
return vmlinux_imports
7878

7979

80-
def bpf_passthrough_gen(module):
81-
i32_ty = ir.IntType(32)
82-
ptr_ty = ir.PointerType(ir.IntType(8))
83-
fnty = ir.FunctionType(ptr_ty, [i32_ty, ptr_ty])
84-
85-
# Declare the intrinsic
86-
passthrough = ir.Function(module, fnty, "llvm.bpf.passthrough.p0.p0")
87-
88-
# Set function attributes
89-
# TODO: the ones commented are supposed to be there but cannot be added due to llvmlite limitations at the moment
90-
# passthrough.attributes.add("nofree")
91-
# passthrough.attributes.add("nosync")
92-
passthrough.attributes.add("nounwind")
93-
# passthrough.attributes.add("memory(none)")
94-
95-
return passthrough
96-
97-
9880
def vmlinux_proc(tree: ast.AST, module):
9981
import_statements = detect_import_statement(tree)
10082

101-
bpf_passthrough_gen(module)
10283
# initialise dependency handler
10384
handler = DependencyHandler()
10485
# initialise assignment dictionary of name to type

0 commit comments

Comments
 (0)