[all-commits] [llvm/llvm-project] 2aacb5: BPF address space insn (#84410)
4ast via All-commits
all-commits at lists.llvm.org
Tue Mar 12 17:27:47 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 2aacb56e8361213c1bd69c2ceafdea3aa0ca9125
https://github.com/llvm/llvm-project/commit/2aacb56e8361213c1bd69c2ceafdea3aa0ca9125
Author: 4ast <alexei.starovoitov at gmail.com>
Date: 2024-03-13 (Wed, 13 Mar 2024)
Changed paths:
M clang/lib/Basic/Targets/BPF.cpp
M clang/test/Preprocessor/bpf-predefined-macros.c
M llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
M llvm/lib/Target/BPF/BPF.h
A llvm/lib/Target/BPF/BPFASpaceCastSimplifyPass.cpp
M llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
M llvm/lib/Target/BPF/BPFInstrInfo.td
M llvm/lib/Target/BPF/BPFTargetMachine.cpp
M llvm/lib/Target/BPF/CMakeLists.txt
A llvm/test/CodeGen/BPF/addr-space-auto-casts.ll
A llvm/test/CodeGen/BPF/addr-space-cast.ll
A llvm/test/CodeGen/BPF/addr-space-gep-chain.ll
A llvm/test/CodeGen/BPF/addr-space-globals.ll
A llvm/test/CodeGen/BPF/addr-space-globals2.ll
A llvm/test/CodeGen/BPF/addr-space-phi.ll
A llvm/test/CodeGen/BPF/addr-space-simplify-1.ll
A llvm/test/CodeGen/BPF/addr-space-simplify-2.ll
A llvm/test/CodeGen/BPF/addr-space-simplify-3.ll
A llvm/test/CodeGen/BPF/addr-space-simplify-4.ll
A llvm/test/CodeGen/BPF/addr-space-simplify-5.ll
M llvm/test/CodeGen/BPF/assembler-disassembler.s
Log Message:
-----------
BPF address space insn (#84410)
This commit aims to support BPF arena kernel side
[feature](https://lore.kernel.org/bpf/20240209040608.98927-1-alexei.starovoitov@gmail.com/):
- arena is a memory region accessible from both BPF program and
userspace;
- base pointers for this memory region differ between kernel and user
spaces;
- `dst_reg = addr_space_cast(src_reg, dst_addr_space, src_addr_space)`
translates src_reg, a pointer in src_addr_space to dst_reg, equivalent
pointer in dst_addr_space, {src,dst}_addr_space are immediate constants;
- number 0 is assigned to kernel address space;
- number 1 is assigned to user address space.
On the LLVM side, the goal is to make load and store operations on arena
pointers "transparent" for BPF programs:
- assume that pointers with non-zero address space are pointers to
arena memory;
- assume that arena is identified by address space number;
- assume that address space zero corresponds to kernel address space;
- assume that every BPF-side load or store from arena is done via
pointer in user address space, thus convert base pointers using
`addr_space_cast(src_reg, 0, 1)`;
Only load, store, cmpxchg and atomicrmw IR instructions are handled by
this transformation.
For example, the following C code:
```c
#define __as __attribute__((address_space(1)))
void copy(int __as *from, int __as *to) { *to = *from; }
```
Compiled to the following IR:
```llvm
define void @copy(ptr addrspace(1) %from, ptr addrspace(1) %to) {
entry:
%0 = load i32, ptr addrspace(1) %from, align 4
store i32 %0, ptr addrspace(1) %to, align 4
ret void
}
```
Is transformed to:
```llvm
%to2 = addrspacecast ptr addrspace(1) %to to ptr ;; !
%from1 = addrspacecast ptr addrspace(1) %from to ptr ;; !
%0 = load i32, ptr %from1, align 4, !tbaa !3
store i32 %0, ptr %to2, align 4, !tbaa !3
ret void
```
And compiled as:
```asm
r2 = addr_space_cast(r2, 0, 1)
r1 = addr_space_cast(r1, 0, 1)
r1 = *(u32 *)(r1 + 0)
*(u32 *)(r2 + 0) = r1
exit
```
Co-authored-by: Eduard Zingerman <eddyz87 at gmail.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list