@@ -107,7 +107,9 @@ static const SupportedConditionalValue SupportedConditionalCompilationPtrAuthSch
107
107
" _arm64e" ,
108
108
};
109
109
110
- static const SupportedConditionalValue SupportedConditionalCompilationAtomicBitWidths[] = {
110
+ static const SupportedConditionalValue SupportedConditionalCompilationHasAtomicBitWidths[] = {
111
+ " _8" ,
112
+ " _16" ,
111
113
" _32" ,
112
114
" _64" ,
113
115
" _128"
@@ -137,8 +139,8 @@ ArrayRef<SupportedConditionalValue> getSupportedConditionalCompilationValues(con
137
139
return SupportedConditionalCompilationTargetEnvironments;
138
140
case PlatformConditionKind::PtrAuth:
139
141
return SupportedConditionalCompilationPtrAuthSchemes;
140
- case PlatformConditionKind::AtomicBitWidth :
141
- return SupportedConditionalCompilationAtomicBitWidths ;
142
+ case PlatformConditionKind::HasAtomicBitWidth :
143
+ return SupportedConditionalCompilationHasAtomicBitWidths ;
142
144
}
143
145
llvm_unreachable (" Unhandled PlatformConditionKind in switch" );
144
146
}
@@ -202,7 +204,7 @@ checkPlatformConditionSupported(PlatformConditionKind Kind, StringRef Value,
202
204
case PlatformConditionKind::Runtime:
203
205
case PlatformConditionKind::TargetEnvironment:
204
206
case PlatformConditionKind::PtrAuth:
205
- case PlatformConditionKind::AtomicBitWidth :
207
+ case PlatformConditionKind::HasAtomicBitWidth :
206
208
return isMatching (Kind, Value, suggestedKind, suggestedValues);
207
209
case PlatformConditionKind::CanImport:
208
210
// All importable names are valid.
@@ -244,6 +246,14 @@ checkPlatformCondition(PlatformConditionKind Kind, StringRef Value) const {
244
246
return true ;
245
247
}
246
248
249
+ if (Kind == PlatformConditionKind::HasAtomicBitWidth) {
250
+ for (auto bitWidth : AtomicBitWidths) {
251
+ if (bitWidth == Value) {
252
+ return true ;
253
+ }
254
+ }
255
+ }
256
+
247
257
return false ;
248
258
}
249
259
@@ -277,7 +287,7 @@ bool LangOptions::hasFeature(llvm::StringRef featureName) const {
277
287
return false ;
278
288
}
279
289
280
- void LangOptions::setAtomicBitWidth (llvm::Triple triple) {
290
+ void LangOptions::setHasAtomicBitWidth (llvm::Triple triple) {
281
291
// We really want to use Clang's getMaxAtomicInlineWidth(), but that requires
282
292
// a Clang::TargetInfo and we're setting up lang opts very early in the
283
293
// pipeline before any ASTContext or any ClangImporter instance where we can
@@ -291,11 +301,11 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
291
301
switch (triple.getSubArch ()) {
292
302
case llvm::Triple::SubArchType::ARMSubArch_v6m:
293
303
case llvm::Triple::SubArchType::ARMSubArch_v7m:
294
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
304
+ setMaxAtomicBitWidth ( 32 );
295
305
break ;
296
306
297
307
default :
298
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
308
+ setMaxAtomicBitWidth ( 64 );
299
309
break ;
300
310
}
301
311
break ;
@@ -307,48 +317,48 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
307
317
case llvm::Triple::SubArchType::ARMSubArch_v8m_baseline:
308
318
case llvm::Triple::SubArchType::ARMSubArch_v8m_mainline:
309
319
case llvm::Triple::SubArchType::ARMSubArch_v8_1m_mainline:
310
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
320
+ setMaxAtomicBitWidth ( 64 );
311
321
break ;
312
322
313
323
default :
314
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
324
+ setMaxAtomicBitWidth ( 128 );
315
325
break ;
316
326
}
317
327
break ;
318
328
319
329
// arm64_32 has 32 bit pointer words, but it has the same architecture as
320
330
// arm64 and supports 128 bit atomics.
321
331
case llvm::Triple::ArchType::aarch64_32:
322
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
332
+ setMaxAtomicBitWidth ( 128 );
323
333
break ;
324
334
325
335
// PowerPC does not support double word atomics.
326
336
case llvm::Triple::ArchType::ppc:
327
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
337
+ setMaxAtomicBitWidth ( 32 );
328
338
break ;
329
339
330
340
// All of the 64 bit PowerPC flavors do not support double word atomics.
331
341
case llvm::Triple::ArchType::ppc64:
332
342
case llvm::Triple::ArchType::ppc64le:
333
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
343
+ setMaxAtomicBitWidth ( 64 );
334
344
break ;
335
345
336
346
// SystemZ (s390x) does not support double word atomics.
337
347
case llvm::Triple::ArchType::systemz:
338
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
348
+ setMaxAtomicBitWidth ( 64 );
339
349
break ;
340
350
341
351
// Wasm32 supports double word atomics.
342
352
case llvm::Triple::ArchType::wasm32:
343
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
353
+ setMaxAtomicBitWidth ( 64 );
344
354
break ;
345
355
346
356
// x86 supports double word atomics.
347
357
//
348
358
// Technically, this is incorrect. However, on all x86 platforms where Swift
349
359
// is deployed this is true.
350
360
case llvm::Triple::ArchType::x86:
351
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
361
+ setMaxAtomicBitWidth ( 64 );
352
362
break ;
353
363
354
364
// x86_64 supports double word atomics.
@@ -357,7 +367,7 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
357
367
// is deployed this is true. If the ClangImporter ever stops unconditionally
358
368
// adding '-mcx16' to its Clang instance, then be sure to update this below.
359
369
case llvm::Triple::ArchType::x86_64:
360
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _128 " );
370
+ setMaxAtomicBitWidth ( 128 );
361
371
break ;
362
372
363
373
default :
@@ -366,17 +376,18 @@ void LangOptions::setAtomicBitWidth(llvm::Triple triple) {
366
376
// every arch supports at least word atomics.
367
377
368
378
if (triple.isArch32Bit ()) {
369
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _32 " );
379
+ setMaxAtomicBitWidth ( 32 );
370
380
}
371
381
372
382
if (triple.isArch64Bit ()) {
373
- addPlatformConditionValue (PlatformConditionKind::AtomicBitWidth, " _64 " );
383
+ setMaxAtomicBitWidth ( 64 );
374
384
}
375
385
}
376
386
}
377
387
378
388
std::pair<bool , bool > LangOptions::setTarget (llvm::Triple triple) {
379
389
clearAllPlatformConditionValues ();
390
+ clearAtomicBitWidths ();
380
391
381
392
if (triple.getOS () == llvm::Triple::Darwin &&
382
393
triple.getVendor () == llvm::Triple::Apple) {
@@ -546,8 +557,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
546
557
addPlatformConditionValue (PlatformConditionKind::TargetEnvironment,
547
558
" macabi" );
548
559
549
- // Set the "_atomicBitWidth " platform condition.
550
- setAtomicBitWidth (triple);
560
+ // Set the "_hasHasAtomicBitWidth " platform condition.
561
+ setHasAtomicBitWidth (triple);
551
562
552
563
// If you add anything to this list, change the default size of
553
564
// PlatformConditionValues to not require an extra allocation
0 commit comments