[libcxx-commits] [PATCH] D91911: [libc++] Add a 'is-lockfree-runtime-function' lit feature

Alexander Richardson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 30 01:41:20 PST 2020


arichardson added a comment.

In D91911#2420671 <https://reviews.llvm.org/D91911#2420671>, @ldionne wrote:

> How difficult would it be to implement `__atomic_is_lock_free` in compiler-rt? I think something like this in `atomic.c` would work:
>
>   int __atomic_is_lock_free(size_t size, void const volatile* ptr) {
>   #define LOCK_FREE_ACTION(type) return sizeof(type) <= size;
>     LOCK_FREE_CASES(ptr);
>   #undef LOCK_FREE_ACTION
>     return 0;
>   }
>
> However, I'm not familiar with how to add builtins in compiler-rt, and I haven't been able to figure out the details at a glance.
>
> Do I understand correctly that:
>
> 1. When Clang sees `__atomic_is_lock_free(args...)`, it tries to generate code directly for it if it can.
> 2. Otherwise, it generates an external call to a function called `int __atomic_is_lock_free(unsigned long, void const volatile*);`
> 3. If a library that defines this function isn't provided, a linker error follows
>
> Is that how these work? We can definitely add a workaround to fix the test suite here, however I'd also like to actually solve the root cause of this issue. It's also something we've had requests about in the past.

That matches my understanding and what the GCC documentation says:

> Built-in Function: `bool __atomic_is_lock_free (size_t size, void *ptr)`
> This built-in function returns true if objects of size bytes always generate lock-free atomic instructions for the target architecture. If the built-in function is not known to be lock-free, a call is made to a runtime routine named __atomic_is_lock_free.
> ptr is an optional pointer to the object that may be used to determine alignment. A value of 0 indicates typical alignment should be used. The compiler may also ignore this parameter.

I've also posted D92302 <https://reviews.llvm.org/D92302> to implement this in compiler-rt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91911



More information about the libcxx-commits mailing list