@@ -6053,7 +6053,8 @@ class OffloadingActionBuilder final {
6053
6053
6054
6054
// / Initialize the GPU architecture list from arguments - this populates
6055
6055
// / `GpuArchList` from `--offload-arch` flags. Only relevant if compiling to
6056
- // / CUDA or AMDGCN. Return true if any initialization errors are found.
6056
+ // / CUDA or AMDGCN.
6057
+ // / \return true if any initialization is successful.
6057
6058
// / FIXME: "offload-arch" and the BoundArch mechanism should also be
6058
6059
// used in the SYCLToolChain for SPIR-V AOT to track the offload
6059
6060
// architecture instead of the Triple sub-arch it currently uses.
@@ -6139,11 +6140,11 @@ class OffloadingActionBuilder final {
6139
6140
})) {
6140
6141
C.getDriver ().Diag (clang::diag::err_drv_sycl_missing_amdgpu_arch)
6141
6142
<< (SYCLTripleList.size () > 1 ) << Triple.str ();
6142
- return true ;
6143
+ return false ;
6143
6144
}
6144
6145
}
6145
6146
6146
- return false ;
6147
+ return true ;
6147
6148
}
6148
6149
6149
6150
// Goes through all of the arguments, including inputs expected for the
@@ -6314,119 +6315,112 @@ class OffloadingActionBuilder final {
6314
6315
C.getInputArgs ().getLastArg (options::OPT_fsycl_targets_EQ);
6315
6316
bool HasValidSYCLRuntime = C.getInputArgs ().hasFlag (
6316
6317
options::OPT_fsycl, options::OPT_fno_sycl, false );
6317
- bool ShouldAddDefaultTriple = true ;
6318
- bool GpuInitHasErrors = false ;
6319
- bool HasSYCLTargetsOption = SYCLTargets;
6320
-
6321
- if (HasSYCLTargetsOption) {
6322
- if (SYCLTargets) {
6323
- Arg *SYCLTargetsValues = SYCLTargets;
6324
- // Fill SYCLTripleList
6325
- llvm::StringMap<StringRef> FoundNormalizedTriples;
6326
- for (StringRef Val : SYCLTargetsValues->getValues ()) {
6327
- StringRef UserTargetName (Val);
6328
- if (auto ValidDevice = gen::isGPUTarget<gen::IntelGPU>(Val)) {
6329
- if (ValidDevice->empty ())
6330
- // Unrecognized, we have already diagnosed this earlier; skip.
6331
- continue ;
6332
- // Add the proper -device value to the list.
6333
- GpuArchList.emplace_back (
6334
- C.getDriver ().getSYCLDeviceTriple (" spir64_gen" ),
6335
- ValidDevice->data ());
6336
- UserTargetName = " spir64_gen" ;
6337
- } else if (auto ValidDevice =
6338
- gen::isGPUTarget<gen::NvidiaGPU>(Val)) {
6339
- if (ValidDevice->empty ())
6340
- // Unrecognized, we have already diagnosed this earlier; skip.
6341
- continue ;
6342
- // Add the proper -device value to the list.
6343
- GpuArchList.emplace_back (
6344
- C.getDriver ().getSYCLDeviceTriple (" nvptx64-nvidia-cuda" ),
6345
- ValidDevice->data ());
6346
- UserTargetName = " nvptx64-nvidia-cuda" ;
6347
- } else if (auto ValidDevice = gen::isGPUTarget<gen::AmdGPU>(Val)) {
6348
- if (ValidDevice->empty ())
6349
- // Unrecognized, we have already diagnosed this earlier; skip.
6350
- continue ;
6351
- // Add the proper -device value to the list.
6352
- GpuArchList.emplace_back (
6353
- C.getDriver ().getSYCLDeviceTriple (" amdgcn-amd-amdhsa" ),
6354
- ValidDevice->data ());
6355
- UserTargetName = " amdgcn-amd-amdhsa" ;
6356
- }
6357
-
6358
- llvm::Triple TT (
6359
- C.getDriver ().getSYCLDeviceTriple (Val, SYCLTargetsValues));
6360
- std::string NormalizedName = TT.normalize ();
6361
6318
6362
- // Make sure we don't have a duplicate triple.
6363
- auto Duplicate = FoundNormalizedTriples.find (NormalizedName);
6364
- if (Duplicate != FoundNormalizedTriples.end ())
6319
+ if (SYCLTargets) {
6320
+ Arg *SYCLTargetsValues = SYCLTargets;
6321
+ // Fill SYCLTripleList
6322
+ llvm::StringMap<StringRef> FoundNormalizedTriples;
6323
+ for (StringRef Val : SYCLTargetsValues->getValues ()) {
6324
+ StringRef UserTargetName (Val);
6325
+ if (auto ValidDevice = gen::isGPUTarget<gen::IntelGPU>(Val)) {
6326
+ if (ValidDevice->empty ())
6327
+ // Unrecognized, we have already diagnosed this earlier; skip.
6328
+ continue ;
6329
+ // Add the proper -device value to the list.
6330
+ GpuArchList.emplace_back (
6331
+ C.getDriver ().getSYCLDeviceTriple (" spir64_gen" ),
6332
+ ValidDevice->data ());
6333
+ UserTargetName = " spir64_gen" ;
6334
+ } else if (auto ValidDevice = gen::isGPUTarget<gen::NvidiaGPU>(Val)) {
6335
+ if (ValidDevice->empty ())
6336
+ // Unrecognized, we have already diagnosed this earlier; skip.
6365
6337
continue ;
6338
+ // Add the proper -device value to the list.
6339
+ GpuArchList.emplace_back (
6340
+ C.getDriver ().getSYCLDeviceTriple (" nvptx64-nvidia-cuda" ),
6341
+ ValidDevice->data ());
6342
+ UserTargetName = " nvptx64-nvidia-cuda" ;
6343
+ } else if (auto ValidDevice = gen::isGPUTarget<gen::AmdGPU>(Val)) {
6344
+ if (ValidDevice->empty ())
6345
+ // Unrecognized, we have already diagnosed this earlier; skip.
6346
+ continue ;
6347
+ // Add the proper -device value to the list.
6348
+ GpuArchList.emplace_back (
6349
+ C.getDriver ().getSYCLDeviceTriple (" amdgcn-amd-amdhsa" ),
6350
+ ValidDevice->data ());
6351
+ UserTargetName = " amdgcn-amd-amdhsa" ;
6352
+ }
6366
6353
6367
- // Store the current triple so that we can check for duplicates in
6368
- // the following iterations.
6369
- FoundNormalizedTriples[ NormalizedName] = Val ;
6354
+ llvm::Triple TT (
6355
+ C. getDriver (). getSYCLDeviceTriple (Val, SYCLTargetsValues));
6356
+ std::string NormalizedName = TT. normalize () ;
6370
6357
6371
- SYCLTripleList.push_back (
6372
- C.getDriver ().getSYCLDeviceTriple (UserTargetName));
6373
- // For user specified spir64_gen, add an empty device value as a
6374
- // placeholder.
6375
- if (TT.getSubArch () == llvm::Triple::SPIRSubArch_gen)
6376
- GpuArchList.emplace_back (TT, nullptr );
6377
- }
6358
+ // Make sure we don't have a duplicate triple.
6359
+ auto Duplicate = FoundNormalizedTriples.find (NormalizedName);
6360
+ if (Duplicate != FoundNormalizedTriples.end ())
6361
+ continue ;
6378
6362
6379
- // Fill GpuArchList, end if there are issues in initializingGpuArchMap
6380
- GpuInitHasErrors = initializeGpuArchMap ();
6381
- if (GpuInitHasErrors)
6382
- return true ;
6363
+ // Store the current triple so that we can check for duplicates in
6364
+ // the following iterations.
6365
+ FoundNormalizedTriples[NormalizedName] = Val;
6383
6366
6384
- size_t GenIndex = 0 ;
6385
- // Fill SYCLTargetInfoList
6386
- for (auto &TT : SYCLTripleList) {
6387
- auto TCIt = llvm::find_if (
6388
- ToolChains, [&](auto &TC) { return TT == TC->getTriple (); });
6389
- assert (TCIt != ToolChains.end () &&
6390
- " Toolchain was not created for this platform" );
6391
- if (!TT.isNVPTX () && !TT.isAMDGCN ()) {
6392
- // When users specify the target as 'intel_gpu_*', the proper
6393
- // triple is 'spir64_gen'. The given string from intel_gpu_*
6394
- // is the target device.
6395
- if (TT.isSPIR () &&
6396
- TT.getSubArch () == llvm::Triple::SPIRSubArch_gen) {
6397
- // Multiple spir64_gen targets are allowed to be used via the
6398
- // -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_*
6399
- // specifiers. Using an index through the known GpuArchList
6400
- // values, increment through them accordingly to allow for
6401
- // the multiple settings as well as preventing re-use.
6402
- while (TT != GpuArchList[GenIndex].first &&
6403
- GenIndex < GpuArchList.size ())
6404
- ++GenIndex;
6405
- if (GpuArchList[GenIndex].first != TT)
6406
- // No match.
6407
- continue ;
6408
- StringRef Device (GpuArchList[GenIndex].second );
6409
- SYCLTargetInfoList.emplace_back (
6410
- *TCIt, Device.empty () ? nullptr : Device.data ());
6367
+ SYCLTripleList.push_back (
6368
+ C.getDriver ().getSYCLDeviceTriple (UserTargetName));
6369
+ // For user specified spir64_gen, add an empty device value as a
6370
+ // placeholder.
6371
+ if (TT.getSubArch () == llvm::Triple::SPIRSubArch_gen)
6372
+ GpuArchList.emplace_back (TT, nullptr );
6373
+ }
6374
+
6375
+ // Fill GpuArchList, end if there are issues in initializingGpuArchMap
6376
+ if (!initializeGpuArchMap ())
6377
+ return true ;
6378
+
6379
+ size_t GenIndex = 0 ;
6380
+ // Fill SYCLTargetInfoList
6381
+ for (auto &TT : SYCLTripleList) {
6382
+ auto TCIt = llvm::find_if (
6383
+ ToolChains, [&](auto &TC) { return TT == TC->getTriple (); });
6384
+ assert (TCIt != ToolChains.end () &&
6385
+ " Toolchain was not created for this platform" );
6386
+ if (!TT.isNVPTX () && !TT.isAMDGCN ()) {
6387
+ // When users specify the target as 'intel_gpu_*', the proper
6388
+ // triple is 'spir64_gen'. The given string from intel_gpu_*
6389
+ // is the target device.
6390
+ if (TT.isSPIR () &&
6391
+ TT.getSubArch () == llvm::Triple::SPIRSubArch_gen) {
6392
+ // Multiple spir64_gen targets are allowed to be used via the
6393
+ // -fsycl-targets=spir64_gen and -fsycl-targets=intel_gpu_*
6394
+ // specifiers. Using an index through the known GpuArchList
6395
+ // values, increment through them accordingly to allow for
6396
+ // the multiple settings as well as preventing re-use.
6397
+ while (TT != GpuArchList[GenIndex].first &&
6398
+ GenIndex < GpuArchList.size ())
6411
6399
++GenIndex;
6400
+ if (GpuArchList[GenIndex].first != TT)
6401
+ // No match.
6412
6402
continue ;
6413
- }
6414
- SYCLTargetInfoList.emplace_back (*TCIt, nullptr );
6415
- } else {
6416
- const char *OffloadArch = nullptr ;
6417
- for (auto &TargetTripleArchPair : GpuArchList) {
6418
- if (TT == TargetTripleArchPair.first ) {
6419
- OffloadArch = TargetTripleArchPair.second ;
6420
- // Add an arch to the SYCLTargetInfoList
6421
- // only if it is not already present in the list.
6422
- auto Arch = llvm::find_if (
6423
- SYCLTargetInfoList, [&](auto &DeviceTargetInfo) {
6424
- return OffloadArch == DeviceTargetInfo.BoundArch ;
6425
- });
6426
-
6427
- if (Arch == SYCLTargetInfoList.end ())
6428
- SYCLTargetInfoList.emplace_back (*TCIt, OffloadArch);
6429
- }
6403
+ StringRef Device (GpuArchList[GenIndex].second );
6404
+ SYCLTargetInfoList.emplace_back (
6405
+ *TCIt, Device.empty () ? nullptr : Device.data ());
6406
+ ++GenIndex;
6407
+ continue ;
6408
+ }
6409
+ SYCLTargetInfoList.emplace_back (*TCIt, nullptr );
6410
+ } else {
6411
+ const char *OffloadArch = nullptr ;
6412
+ for (auto &TargetTripleArchPair : GpuArchList) {
6413
+ if (TT == TargetTripleArchPair.first ) {
6414
+ OffloadArch = TargetTripleArchPair.second ;
6415
+ // Add an arch to the SYCLTargetInfoList
6416
+ // only if it is not already present in the list.
6417
+ auto Arch = llvm::find_if (
6418
+ SYCLTargetInfoList, [&](auto &DeviceTargetInfo) {
6419
+ return OffloadArch == DeviceTargetInfo.BoundArch ;
6420
+ });
6421
+
6422
+ if (Arch == SYCLTargetInfoList.end ())
6423
+ SYCLTargetInfoList.emplace_back (*TCIt, OffloadArch);
6430
6424
}
6431
6425
}
6432
6426
}
@@ -6470,7 +6464,7 @@ class OffloadingActionBuilder final {
6470
6464
}
6471
6465
}
6472
6466
6473
- if (ShouldAddDefaultTriple && addSYCLDefaultTriple (C, SYCLTripleList)) {
6467
+ if (addSYCLDefaultTriple (C, SYCLTripleList)) {
6474
6468
// If a SYCLDefaultTriple is added to SYCLTripleList,
6475
6469
// add new target to SYCLTargetInfoList
6476
6470
llvm::Triple TT = SYCLTripleList.front ();
0 commit comments