[PATCH] D61052: [compiler-rt][builtins] Implement some fetch-and-x operations for Cortex-M

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 12:54:15 PDT 2019


efriedma added a comment.

There are really two intended uses for the __sync_* builtins on ARM.

1. Allow pre-Thumb2 ARMv6 code in Thumb mode to use atomics which are natively supported, but can't be emitted inline (because the instructions only exist in ARM mode).
2. On ARM Linux, there's a special kernel-assisted sequence that can be used to implement these builtins for all ARM targets, even ones which don't have native atomics.  (compiler-rt currently doesn't support this, but libgcc does).

Neither of these is relevant for M-class processors.

In other cases, the compiler should emit an inline sequence, or call one of the __atomic_* APIs.  See http://llvm.org/docs/Atomics.html#libcalls-sync .  If that isn't happening, it's a bug in clang/LLVM.

The open question here, is whether it's appropriate to turn off interrupts in compiler-rt, if we're in a baremetal environment.  I would lean towards no... if someone really wants to use an implementation that turns off interrupts, they can implement __atomic_* appropriately.

> disabling interrupts with cpsid is specific to M class

The instruction exists on A-class targets.  It's just that on most A-class targets, we run in userspace, and userspace isn't allowed to disable interrupts, for obvious reasons.  (Also, on A-class targets, we can't generally assume there's only one CPU core.)


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D61052





More information about the llvm-commits mailing list