@@ -296,56 +296,25 @@ static bool forwardToGCC(const Option &O) {
296
296
!O.hasFlag (options::DriverOption) && !O.hasFlag (options::LinkerInput);
297
297
}
298
298
299
- // / Add the C++ include args of other offloading toolchains. If this is a host
300
- // / job, the device toolchains are added. If this is a device job, the host
301
- // / toolchains will be added.
302
- static void addExtraOffloadCXXStdlibIncludeArgs (Compilation &C,
303
- const JobAction &JA,
304
- const ArgList &Args,
305
- ArgStringList &CmdArgs) {
306
-
307
- if (JA.isHostOffloading (Action::OFK_Cuda))
308
- C.getSingleOffloadToolChain <Action::OFK_Cuda>()
309
- ->AddClangCXXStdlibIncludeArgs (Args, CmdArgs);
310
- else if (JA.isDeviceOffloading (Action::OFK_Cuda))
311
- C.getSingleOffloadToolChain <Action::OFK_Host>()
312
- ->AddClangCXXStdlibIncludeArgs (Args, CmdArgs);
313
-
314
- // TODO: Add support for other programming models here.
315
- }
316
-
317
- // / Add the C include args of other offloading toolchains. If this is a host
318
- // / job, the device toolchains are added. If this is a device job, the host
319
- // / toolchains will be added.
320
- static void addExtraOffloadClangSystemIncludeArgs (Compilation &C,
321
- const JobAction &JA,
322
- const ArgList &Args,
323
- ArgStringList &CmdArgs) {
324
-
325
- if (JA.isHostOffloading (Action::OFK_Cuda))
326
- C.getSingleOffloadToolChain <Action::OFK_Cuda>()->AddClangSystemIncludeArgs (
327
- Args, CmdArgs);
328
- else if (JA.isDeviceOffloading (Action::OFK_Cuda))
329
- C.getSingleOffloadToolChain <Action::OFK_Host>()->AddClangSystemIncludeArgs (
330
- Args, CmdArgs);
331
-
332
- // TODO: Add support for other programming models here.
333
- }
334
-
335
- // / Add the include args that are specific of each offloading programming model.
336
- static void addExtraOffloadSpecificIncludeArgs (Compilation &C,
337
- const JobAction &JA,
338
- const ArgList &Args,
339
- ArgStringList &CmdArgs) {
340
-
299
+ // / Apply \a Work on the current tool chain \a RegularToolChain and any other
300
+ // / offloading tool chain that is associated with the current action \a JA.
301
+ static void
302
+ forAllAssociatedToolChains (Compilation &C, const JobAction &JA,
303
+ const ToolChain &RegularToolChain,
304
+ llvm::function_ref<void (const ToolChain &)> Work) {
305
+ // Apply Work on the current/regular tool chain.
306
+ Work (RegularToolChain);
307
+
308
+ // Apply Work on all the offloading tool chains associated with the current
309
+ // action.
341
310
if (JA.isHostOffloading (Action::OFK_Cuda))
342
- C.getSingleOffloadToolChain <Action::OFK_Host>()->AddCudaIncludeArgs (
343
- Args, CmdArgs);
311
+ Work (*C.getSingleOffloadToolChain <Action::OFK_Host>());
344
312
else if (JA.isDeviceOffloading (Action::OFK_Cuda))
345
- C.getSingleOffloadToolChain <Action::OFK_Cuda>()->AddCudaIncludeArgs (
346
- Args, CmdArgs);
313
+ Work (*C.getSingleOffloadToolChain <Action::OFK_Cuda>());
347
314
348
- // TODO: Add support for other programming models here.
315
+ //
316
+ // TODO: Add support for other offloading programming models here.
317
+ //
349
318
}
350
319
351
320
void Clang::AddPreprocessingOptions (Compilation &C, const JobAction &JA,
@@ -622,22 +591,26 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
622
591
// of an offloading programming model.
623
592
624
593
// Add C++ include arguments, if needed.
625
- if (types::isCXX (Inputs[0 ].getType ())) {
626
- getToolChain ().AddClangCXXStdlibIncludeArgs (Args, CmdArgs);
627
- addExtraOffloadCXXStdlibIncludeArgs (C, JA, Args, CmdArgs);
628
- }
594
+ if (types::isCXX (Inputs[0 ].getType ()))
595
+ forAllAssociatedToolChains (C, JA, getToolChain (),
596
+ [&Args, &CmdArgs](const ToolChain &TC) {
597
+ TC.AddClangCXXStdlibIncludeArgs (Args, CmdArgs);
598
+ });
629
599
630
600
// Add system include arguments for all targets but IAMCU.
631
- if (!IsIAMCU) {
632
- getToolChain ().AddClangSystemIncludeArgs (Args, CmdArgs);
633
- addExtraOffloadClangSystemIncludeArgs (C, JA, Args, CmdArgs);
634
- } else {
601
+ if (!IsIAMCU)
602
+ forAllAssociatedToolChains (C, JA, getToolChain (),
603
+ [&Args, &CmdArgs](const ToolChain &TC) {
604
+ TC.AddClangSystemIncludeArgs (Args, CmdArgs);
605
+ });
606
+ else {
635
607
// For IAMCU add special include arguments.
636
608
getToolChain ().AddIAMCUIncludeArgs (Args, CmdArgs);
637
609
}
638
610
639
- // Add offload include arguments, if needed.
640
- addExtraOffloadSpecificIncludeArgs (C, JA, Args, CmdArgs);
611
+ // Add offload include arguments specific for CUDA if that is required.
612
+ if (JA.isOffloading (Action::OFK_Cuda))
613
+ getToolChain ().AddCudaIncludeArgs (Args, CmdArgs);
641
614
}
642
615
643
616
// FIXME: Move to target hook.
0 commit comments