Skip to content

Commit

Permalink
[BPF] rename 'arena' to 'address_space' (#85161)
Browse files Browse the repository at this point in the history
There are a few places where `arena` name is used for pointers in
non-zero address space in BPF backend, rename these to use a more
generic `address_space`:
- macro `__BPF_FEATURE_ARENA_CAST` -> `__BPF_FEATURE_ADDR_SPACE_CAST
- name for arena global variables section `.arena.N` ->
`.addr_space.N`
  • Loading branch information
eddyz87 committed Mar 15, 2024
1 parent 0c07102 commit 65b123e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
return;
}

Builder.defineMacro("__BPF_FEATURE_ARENA_CAST");
Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");

if (CPU.empty() || CPU == "generic" || CPU == "v1") {
Builder.defineMacro("__BPF_CPU_VERSION__", "1");
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Preprocessor/bpf-predefined-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int r;
#ifdef __BPF_FEATURE_ST
int s;
#endif
#ifdef __BPF_FEATURE_ARENA_CAST
#ifdef __BPF_FEATURE_ADDR_SPACE_CAST
int t;
#endif

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// - remove llvm.bpf.getelementptr.and.load builtins.
// - remove llvm.bpf.getelementptr.and.store builtins.
// - for loads and stores with base addresses from non-zero address space
// cast base address to zero address space (support for BPF arenas).
// cast base address to zero address space (support for BPF address spaces).
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -482,15 +482,15 @@ static void aspaceWrapOperand(DenseMap<Value *, Value *> &Cache, Instruction *I,
}
}

// Support for BPF arenas:
// Support for BPF address spaces:
// - for each function in the module M, update pointer operand of
// each memory access instruction (load/store/cmpxchg/atomicrmw)
// by casting it from non-zero address space to zero address space, e.g:
//
// (load (ptr addrspace (N) %p) ...)
// -> (load (addrspacecast ptr addrspace (N) %p to ptr))
//
// - assign section with name .arena.N for globals defined in
// - assign section with name .addr_space.N for globals defined in
// non-zero address space N
bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
bool Changed = false;
Expand All @@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
Changed |= !CastsCache.empty();
}
// Merge all globals within same address space into single
// .arena.<addr space no> section
// .addr_space.<addr space no> section
for (GlobalVariable &G : M.globals()) {
if (G.getAddressSpace() == 0 || G.hasSection())
continue;
SmallString<16> SecName;
raw_svector_ostream OS(SecName);
OS << ".arena." << G.getAddressSpace();
OS << ".addr_space." << G.getAddressSpace();
G.setSection(SecName);
// Prevent having separate section for constants
G.setConstant(false);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/BPF/addr-space-globals.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

; Verify that a,b,c reside in the same section

; CHECK: .section .arena.272,"aw",@progbits
; CHECK: .section .addr_space.272,"aw",@progbits
; CHECK-NOT: .section
; CHECK: .globl a
; CHECK: .ascii "\001\002"
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/BPF/addr-space-globals2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

; Verify that a,b reside in separate sections

; CHECK: .section .arena.1,"aw",@progbits
; CHECK: .section .addr_space.1,"aw",@progbits
; CHECK-NOT: .section
; CHECK: .globl a
; CHECK: .ascii "\001\002"

; CHECK: .section .arena.2,"aw",@progbits
; CHECK: .section .addr_space.2,"aw",@progbits
; CHECK-NOT: .section
; CHECK: .globl b
; CHECK: .ascii "\003\004"

0 comments on commit 65b123e

Please sign in to comment.