[clang] [llvm] [BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 24 01:56:04 PDT 2024
================
@@ -0,0 +1,186 @@
+; RUN: llc -march=bpfel -mcpu=v3 -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -mcpu=v3 -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+;
+; Source:
+; #include <stdatomic.h>
+; struct gstruct_t {
+; _Atomic int a;
+; } gstruct;
+; extern _Atomic int ext;
+; _Atomic int gbl;
+; _Atomic int *pgbl;
+; volatile _Atomic int vvar;
+; _Atomic int foo(_Atomic int a1, _Atomic int *p1) {
+; (void)__c11_atomic_fetch_add(&gstruct.a, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&ext, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&gbl, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(pgbl, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&vvar, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(p1, 1, memory_order_relaxed);
+;
+; return a1;
+; }
+
+target triple = "bpf"
+
+%struct.gstruct_t = type { i32 }
+
+ at gstruct = dso_local global %struct.gstruct_t zeroinitializer, align 4, !dbg !0
+ at ext = external dso_local global i32, align 4, !dbg !26
+ at gbl = dso_local global i32 0, align 4, !dbg !16
+ at pgbl = dso_local local_unnamed_addr global ptr null, align 8, !dbg !20
+ at vvar = dso_local global i32 0, align 4, !dbg !23
+
+; Function Attrs: mustprogress nofree norecurse nounwind willreturn
+define dso_local i32 @foo(i32 returned %a1, ptr nocapture noundef %p1) local_unnamed_addr #0 !dbg !37 {
+entry:
+ #dbg_value(i32 %a1, !41, !DIExpression(), !43)
+ #dbg_value(ptr %p1, !42, !DIExpression(), !43)
+ %0 = atomicrmw add ptr @gstruct, i32 1 monotonic, align 4, !dbg !44
+ %1 = atomicrmw add ptr @ext, i32 1 monotonic, align 4, !dbg !45
+ %2 = atomicrmw add ptr @gbl, i32 1 monotonic, align 4, !dbg !46
+ %3 = load ptr, ptr @pgbl, align 8, !dbg !47, !tbaa !48
+ %4 = atomicrmw add ptr %3, i32 1 monotonic, align 4, !dbg !52
+ %5 = atomicrmw volatile add ptr @vvar, i32 1 monotonic, align 4, !dbg !53
+ %6 = atomicrmw add ptr %p1, i32 1 monotonic, align 4, !dbg !54
+ ret i32 %a1, !dbg !55
+}
+
+; CHECK: .long 1 # BTF_KIND_INT(id = 1)
----------------
eddyz87 wrote:
Looks like linter does not like the way the script is formatted, sorry about that :(
I can update the script and attach here, if you'd like.
https://github.com/llvm/llvm-project/pull/107343
More information about the cfe-commits
mailing list