Skip to content

Commit 7852ebc

Browse files
[BPF] Make -mcpu=v3 as the default (#107008)
Before llvm20, (void)__sync_fetch_and_add(...) always generates locked xadd insns. In linux kernel upstream discussion [1], it is found that for arm64 architecture, the original semantics of (void)__sync_fetch_and_add(...), i.e., __atomic_fetch_add(...), is preferred in order for jit to emit proper native barrier insns. In llvm commits [2] and [3], (void)__sync_fetch_and_add(...) will generate the following insns: - for cpu v1/v2: locked xadd insns to keep backward compatibility - for cpu v3/v4: __atomic_fetch_add() insns To ensure proper barrier semantics for (void)__sync_fetch_and_add(...), cpu v3/v4 is recommended. This patch enables cpu=v3 as the default cpu version. For users wanting to use cpu v1, -mcpu=v1 needs to be explicitly added to clang/llc command line. [1] https://lore.kernel.org/bpf/ZqqiQQWRnz7H93Hc@google.com/T/#mb68d67bc8f39e35a0c3db52468b9de59b79f021f [2] #101428 [3] #106494
1 parent d7c44ef commit 7852ebc

File tree

81 files changed

+132
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+132
-127
lines changed

clang/lib/Basic/Targets/BPF.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
3838

3939
Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");
4040

41-
if (CPU.empty() || CPU == "generic" || CPU == "v1") {
41+
if (CPU.empty())
42+
CPU = "v3";
43+
44+
if (CPU == "generic" || CPU == "v1") {
4245
Builder.defineMacro("__BPF_CPU_VERSION__", "1");
4346
return;
4447
}

clang/test/Preprocessor/bpf-predefined-macros.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang -E -target bpfel -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_NO %s
2-
// RUN: %clang -E -target bpfeb -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_NO %s
1+
// RUN: %clang -E -target bpfel -mcpu=v1 -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_NO %s
2+
// RUN: %clang -E -target bpfeb -mcpu=v1 -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_NO %s
33
// RUN: %clang -E -target bpfel -mcpu=v1 -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_V1 %s
44
// RUN: %clang -E -target bpfel -mcpu=v2 -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_V2 %s
55
// RUN: %clang -E -target bpfel -mcpu=v3 -x c -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CPU_V3 %s

llvm/lib/Target/BPF/BPFSubtarget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ void BPFSubtarget::initializeEnvironment() {
6565
}
6666

6767
void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
68+
if (CPU.empty())
69+
CPU = "v3";
6870
if (CPU == "probe")
6971
CPU = sys::detail::getHostCPUNameForBPF();
7072
if (CPU == "generic" || CPU == "v1")

llvm/test/CodeGen/BPF/32-bit-subreg-cond-select.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -O2 -march=bpfel -mattr=+alu32 < %s | FileCheck %s
1+
; RUN: llc -O2 -march=bpfel -mcpu=v1 -mattr=+alu32 < %s | FileCheck %s
22
;
33
; unsigned int select_cc_32 (unsigned a, unsigned b, int c, int d)
44
; {

llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-1-bpfeb.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2-
; RUN: opt -O2 -S < %s | llc -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3-
; RUN: opt -O2 -S < %s | llc -mattr=+alu32 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
2+
; RUN: opt -O2 -S < %s | llc -mcpu=v1 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3+
; RUN: opt -O2 -S < %s | llc -mcpu=v1 -mattr=+alu32 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
44
; Source code:
55
; struct s {
66
; unsigned long long f1;

llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2-
; RUN: opt -O2 -S < %s | llc -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3-
; RUN: opt -O2 -S < %s | llc -mattr=+alu32 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
2+
; RUN: opt -O2 -S < %s | llc -mcpu=v1 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3+
; RUN: opt -O2 -S < %s | llc -mcpu=v1 -mattr=+alu32 -filetype=asm | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
44
; Source code:
55
; struct s {
66
; unsigned long long f1;

llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-2-bpfeb.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt -O2 %s | llvm-dis > %t1
2-
; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU64 %s
3-
; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU32 %s
2+
; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU64 %s
3+
; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EB,CHECK-ALU32 %s
44
; Source code:
55
; struct s {
66
; char f1;

llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt -O2 %s | llvm-dis > %t1
2-
; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EL,CHECK-ALU64 %s
3-
; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EL,CHECK-ALU32 %s
2+
; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EL,CHECK-ALU64 %s
3+
; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-EL,CHECK-ALU32 %s
44
; Source code:
55
; struct s {
66
; char f1;

llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt -O2 %s | llvm-dis > %t1
2-
; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3-
; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
2+
; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3+
; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
44
; Source code:
55
; typedef struct s1 { int a1:7; int a2:4; int a3:5; int a4:16;} __s1;
66
; union u1 { int b1; __s1 b2; };

llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt -O2 %s | llvm-dis > %t1
2-
; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3-
; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
2+
; RUN: llc -mcpu=v1 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU64 %s
3+
; RUN: llc -mcpu=v1 -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK,CHECK-ALU32 %s
44
; Source code:
55
; typedef struct s1 { int a1; char a2; } __s1;
66
; union u1 { int b1; __s1 b2; };

0 commit comments

Comments
 (0)