@@ -107,7 +107,9 @@ static const SupportedConditionalValue SupportedConditionalCompilationPtrAuthSch
107107 " _arm64e" ,
108108};
109109
110- static const SupportedConditionalValue SupportedConditionalCompilationAtomicBitWidths[] = {
110+ static const SupportedConditionalValue SupportedConditionalCompilationHasAtomicBitWidths[] = {
111+ " _8" ,
112+ " _16" ,
111113 " _32" ,
112114 " _64" ,
113115 " _128"
@@ -137,8 +139,8 @@ ArrayRef<SupportedConditionalValue> getSupportedConditionalCompilationValues(con
137139 return SupportedConditionalCompilationTargetEnvironments;
138140 case PlatformConditionKind::PtrAuth:
139141 return SupportedConditionalCompilationPtrAuthSchemes;
140- case PlatformConditionKind::AtomicBitWidth :
141- return SupportedConditionalCompilationAtomicBitWidths ;
142+ case PlatformConditionKind::HasAtomicBitWidth :
143+ return SupportedConditionalCompilationHasAtomicBitWidths ;
142144 }
143145 llvm_unreachable (" Unhandled PlatformConditionKind in switch" );
144146}
@@ -202,7 +204,7 @@ checkPlatformConditionSupported(PlatformConditionKind Kind, StringRef Value,
202204 case PlatformConditionKind::Runtime:
203205 case PlatformConditionKind::TargetEnvironment:
204206 case PlatformConditionKind::PtrAuth:
205- case PlatformConditionKind::AtomicBitWidth :
207+ case PlatformConditionKind::HasAtomicBitWidth :
206208 return isMatching (Kind, Value, suggestedKind, suggestedValues);
207209 case PlatformConditionKind::CanImport:
208210 // All importable names are valid.
@@ -244,6 +246,14 @@ checkPlatformCondition(PlatformConditionKind Kind, StringRef Value) const {
244246 return true ;
245247 }
246248
249+ if (Kind == PlatformConditionKind::HasAtomicBitWidth) {
250+ for (auto bitWidth : AtomicBitWidths) {
251+ if (bitWidth == Value) {
252+ return true ;
253+ }
254+ }
255+ }
256+
247257 return false ;
248258}
249259
@@ -277,7 +287,7 @@ bool LangOptions::hasFeature(llvm::StringRef featureName) const {
277287 return false ;
278288}
279289
280- void LangOptions::setAtomicBitWidth (llvm::Triple triple) {
290+ void LangOptions::setHasAtomicBitWidth (llvm::Triple triple) {
281291 // We really want to use Clang's getMaxAtomicInlineWidth(), but that requires
282292 // a Clang::TargetInfo and we're setting up lang opts very early in the
283293 // pipeline before any ASTContext or any ClangImporter instance where we can
@@ -291,11 +301,11 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
291301 switch (triple.getSubArch ()) {
292302 case llvm::Triple::SubArchType::ARMSubArch_v6m:
293303 case llvm::Triple::SubArchType::ARMSubArch_v7m:
294- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
304+ setMaxAtomicBitWidth ( 32 );
295305 break ;
296306
297307 default :
298- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
308+ setMaxAtomicBitWidth ( 64 );
299309 break ;
300310 }
301311 break ;
@@ -307,48 +317,48 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
307317 case llvm::Triple::SubArchType::ARMSubArch_v8m_baseline:
308318 case llvm::Triple::SubArchType::ARMSubArch_v8m_mainline:
309319 case llvm::Triple::SubArchType::ARMSubArch_v8_1m_mainline:
310- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
320+ setMaxAtomicBitWidth ( 64 );
311321 break ;
312322
313323 default :
314- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
324+ setMaxAtomicBitWidth ( 128 );
315325 break ;
316326 }
317327 break ;
318328
319329 // arm64_32 has 32 bit pointer words, but it has the same architecture as
320330 // arm64 and supports 128 bit atomics.
321331 case llvm::Triple::ArchType::aarch64_32:
322- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
332+ setMaxAtomicBitWidth ( 128 );
323333 break ;
324334
325335 // PowerPC does not support double word atomics.
326336 case llvm::Triple::ArchType::ppc:
327- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
337+ setMaxAtomicBitWidth ( 32 );
328338 break ;
329339
330340 // All of the 64 bit PowerPC flavors do not support double word atomics.
331341 case llvm::Triple::ArchType::ppc64:
332342 case llvm::Triple::ArchType::ppc64le:
333- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
343+ setMaxAtomicBitWidth ( 64 );
334344 break ;
335345
336346 // SystemZ (s390x) does not support double word atomics.
337347 case llvm::Triple::ArchType::systemz:
338- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
348+ setMaxAtomicBitWidth ( 64 );
339349 break ;
340350
341351 // Wasm32 supports double word atomics.
342352 case llvm::Triple::ArchType::wasm32:
343- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
353+ setMaxAtomicBitWidth ( 64 );
344354 break ;
345355
346356 // x86 supports double word atomics.
347357 //
348358 // Technically, this is incorrect. However, on all x86 platforms where Swift
349359 // is deployed this is true.
350360 case llvm::Triple::ArchType::x86:
351- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
361+ setMaxAtomicBitWidth ( 64 );
352362 break ;
353363
354364 // x86_64 supports double word atomics.
@@ -357,7 +367,7 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
357367 // is deployed this is true. If the ClangImporter ever stops unconditionally
358368 // adding '-mcx16' to its Clang instance, then be sure to update this below.
359369 case llvm::Triple::ArchType::x86_64:
360- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
370+ setMaxAtomicBitWidth ( 128 );
361371 break ;
362372
363373 default :
@@ -366,17 +376,18 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
366376 // every arch supports at least word atomics.
367377
368378 if (triple.isArch32Bit ()) {
369- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
379+ setMaxAtomicBitWidth ( 32 );
370380 }
371381
372382 if (triple.isArch64Bit ()) {
373- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
383+ setMaxAtomicBitWidth ( 64 );
374384 }
375385 }
376386}
377387
378388std::pair<bool , bool > LangOptions::setTarget (llvm::Triple triple) {
379389 clearAllPlatformConditionValues ();
390+ clearAtomicBitWidths ();
380391
381392 if (triple.getOS () == llvm::Triple::Darwin &&
382393 triple.getVendor () == llvm::Triple::Apple) {
@@ -546,8 +557,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
546557 addPlatformConditionValue (PlatformConditionKind::TargetEnvironment,
547558 " macabi" );
548559
549- // Set the "_atomicBitWidth " platform condition.
550- setAtomicBitWidth (triple);
560+ // Set the "_hasHasAtomicBitWidth " platform condition.
561+ setHasAtomicBitWidth (triple);
551562
552563 // If you add anything to this list, change the default size of
553564 // PlatformConditionValues to not require an extra allocation
0 commit comments