This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Add target feature to force 32-bit atomics
ClosedPublic

Authored by nikic on Jul 25 2022, 6:23 AM.

Details

Summary

This adds a +atomic-32 target feature, which instructs LLVM to assume that lock-free 32-bit atomics are available for this target, even if they usually wouldn't be.

If only atomic loads/stores are used, then this won't emit libcalls. If atomic CAS is used, then the user is responsible for providing any necessary __sync implementations (e.g. by masking interrupts for single-core privileged use cases).

See https://reviews.llvm.org/D120026#3674333 for context on this change. The tl;dr is that the thumbv6m target in Rust has historically made atomic load/store only available, which is incompatible with the change from D120026, which switched these to use libatomic.

This is an ARM target feature for now, but probably the ability to override setMaxAtomicSizeInBitsSupported() would also be useful in general...

Diff Detail

Event Timeline

nikic created this revision.Jul 25 2022, 6:23 AM
nikic requested review of this revision.Jul 25 2022, 6:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2022, 6:23 AM

the ability to override setMaxAtomicSizeInBitsSupported() would also be useful in general...

Probably for each target where you want a feature like this, you need to go through and ensure it actually works. Just overriding setMaxAtomicSizeInBitsSupported() on a target that isn't expecting it is going to either crash, or generate __sync_* calls for load/store ops.

efriedma accepted this revision.Jul 25 2022, 12:10 PM

LGTM

llvm/lib/Target/ARM/ARM.td
561

Maybe note that code built with this feature is not ABI-compatible with code built without it, if atomic variables are exposed across the ABI boundary.

llvm/test/CodeGen/ARM/thumbv6m-atomic32.ll
168

Ideally, this should probably use __atomic_add_8, but that's not related to this patch.

This revision is now accepted and ready to land.Jul 25 2022, 12:10 PM
This revision was landed with ongoing or failed builds.Jul 27 2022, 1:02 AM
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.