[PATCH] D122377: [PowerPC][Linux] Support 16-byte lock free atomics on pwr8 and up

Kai Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 00:02:09 PDT 2022


lkail updated this revision to Diff 418142.
lkail added reviewers: dim, pkubaj.
lkail set the repository for this revision to rG LLVM Github Monorepo.
lkail added subscribers: pkubaj, dim.
lkail added a comment.

@dim  @pkubaj We are modifying layout of 16-byte atomic type on Linux to be consistent with GCC, I don't know if it also applies to freebsd as @MaskRay pointed out.
To be more specific, on Linux, for arch level supporting 16-byte lock free atomics, 16-byte atomic type is properly aligned.

  #include <stdatomic.h>
  
  int printf(const char *, ...);
  
  typedef struct A {
    char x[16];
  } A;
  
  typedef struct B {
    char q;
    _Atomic(A) a;
  } B;
  
  int main(void) {
    _Atomic(A) *p = 0;
    printf("aligned: %d\n", __builtin_offsetof(B, a) % 16 == 0);
  #if __clang__
    printf("lock free (size built-in): %d\n", __c11_atomic_is_lock_free(sizeof(*p)));
  #endif
    printf("lock free (type query using pointer): %d\n", atomic_is_lock_free(p));
  }

Current clang gives

  aligned: 0
  lock free (size built-in): 1
  lock free (type query using pointer): 1

GCC gives

  aligned: 1
  lock free (type query using pointer): 1

This patch also modifies the query of `__atomic_always_lock_free(16, 0)` to return true for supported arch level.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122377/new/

https://reviews.llvm.org/D122377

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/PowerPC/atomic-alignment.c
  clang/test/CodeGen/PowerPC/quadword-atomics.c
  clang/test/Driver/ppc-quadword-atomics.c
  clang/test/Sema/atomic-ops.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122377.418142.patch
Type: text/x-patch
Size: 12172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220325/f2760956/attachment-0001.bin>


More information about the cfe-commits mailing list