This is an archive of the discontinued LLVM Phabricator instance.

[openmp] Use GCC style intrinsics for atomics on Clang-cl on aarch64 too
ClosedPublic

Authored by mstorsjo on Nov 25 2022, 2:56 PM.

Details

Summary

This fixes compilation in the Clang-cl configuration on aarch64;
Clang doesn't implement all the aarch64 MSVC atomic intrinsics yet.

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 25 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2022, 2:56 PM
mstorsjo requested review of this revision.Nov 25 2022, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2022, 2:56 PM
Herald added a subscriber: sstefan1. · View Herald Transcript

Can you explain the structure of the existing #ifdef? I'm having trouble following it.

I think the idea is that gcc on AArch64 would end up in the following #elif (KMP_ASM_INTRINS && KMP_OS_UNIX) || !(KMP_ARCH_X86 || KMP_ARCH_X86_64). On Windows, you'd fall down into the #else. But what each of those blocks includes I'm not sure.

Can you explain the structure of the existing #ifdef? I'm having trouble following it.

I think the idea is that gcc on AArch64 would end up in the following #elif (KMP_ASM_INTRINS && KMP_OS_UNIX) || !(KMP_ARCH_X86 || KMP_ARCH_X86_64). On Windows, you'd fall down into the #else. But what each of those blocks includes I'm not sure.

As far as I can see, the high level structure right now is this:

#if KMP_ASM_INTRINS && KMP_OS_WINDOWS && !((KMP_ARCH_AARCH64 || KMP_ARCH_ARM) && defined(__GNUC__))


// MSVC Intrinsics
// Used on MSVC on all archs, plus used by Clang on Windows on x86

#if KMP_ARCH_AARCH64 && KMP_COMPILER_MSVC && !KMP_COMPILER_CLANG

// MSVC/AArch64 specific bits

#else // !KMP_ARCH_AARCH64

// MSVC/X86 specifics

#endif


#elif (KMP_ASM_INTRINS && KMP_OS_UNIX) || !(KMP_ARCH_X86 || KMP_ARCH_X86_64)

// GCC Intrinsics, __sync_*, __atomic_*

#else

// Relying on external function definitions

#endif

Clang hasn't implemented the full set of MSVC intrinsics for atomics, so for Windows on non-x86, Clang is better off with the GCC style intrinsics of __sync_* and __atomic_*. D137168 / a356782426f5bf54a00570e1f925345e5fda7b2e added && !(KMP_ARCH_AARCH64 && defined(__GNUC__)) to the first condition, to single out the aarch64+mingw condition, but the same issue (Clang doesn't handle the full set of MSVC aarch64 atomic intrinsics) is present in Clang in MSVC/clang-cl mode too. (D138689 / 97958c9bb83cec44b6ce13e732b53de0171a5d43 then added ARM to the same condition.)

DavidSpickett accepted this revision.Nov 28 2022, 3:49 AM

LGTM, thanks for explaining.

This revision is now accepted and ready to land.Nov 28 2022, 3:49 AM