@@ -982,7 +982,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
982
982
983
983
TC = DeviceTC.get ();
984
984
} else
985
- TC = &getToolChain (C.getInputArgs (), TT);
985
+ TC = &getToolChain (C.getInputArgs (), TT, Inputs );
986
986
C.addOffloadDeviceToolChain (TC, Action::OFK_OpenMP);
987
987
auto It = DerivedArchs.find (TT.getTriple ());
988
988
if (It != DerivedArchs.end ())
@@ -1484,12 +1484,17 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1484
1484
std::unique_ptr<llvm::opt::InputArgList> UArgs =
1485
1485
std::make_unique<InputArgList>(std::move (Args));
1486
1486
1487
+ llvm::Triple TT = computeTargetTriple (*this , TargetTriple, *UArgs);
1488
+
1487
1489
// Perform the default argument translations.
1488
1490
DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
1489
1491
1492
+ // Construct the list of inputs.
1493
+ InputList Inputs;
1494
+ BuildInputs (TT, *TranslatedArgs, Inputs);
1495
+
1490
1496
// Owned by the host.
1491
- const ToolChain &TC = getToolChain (
1492
- *UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1497
+ const ToolChain &TC = getToolChain (*UArgs, TT, Inputs);
1493
1498
1494
1499
// Check if the environment version is valid except wasm case.
1495
1500
llvm::Triple Triple = TC.getTriple ();
@@ -1550,10 +1555,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1550
1555
if (!HandleImmediateArgs (*C))
1551
1556
return C;
1552
1557
1553
- // Construct the list of inputs.
1554
- InputList Inputs;
1555
- BuildInputs (C->getDefaultToolChain (), *TranslatedArgs, Inputs);
1556
-
1557
1558
// Populate the tool chains for the offloading devices, if any.
1558
1559
CreateOffloadingDeviceToolChains (*C, Inputs);
1559
1560
@@ -1767,7 +1768,7 @@ void Driver::generateCompilationDiagnostics(
1767
1768
1768
1769
// Construct the list of inputs.
1769
1770
InputList Inputs;
1770
- BuildInputs (C.getDefaultToolChain (), C.getArgs (), Inputs);
1771
+ BuildInputs (C.getDefaultToolChain (). getTriple () , C.getArgs (), Inputs);
1771
1772
1772
1773
for (InputList::iterator it = Inputs.begin (), ie = Inputs.end (); it != ie;) {
1773
1774
bool IgnoreInput = false ;
@@ -2660,8 +2661,24 @@ static types::ID CXXHeaderUnitType(ModuleHeaderMode HM) {
2660
2661
return types::TY_CXXHUHeader;
2661
2662
}
2662
2663
2664
+ static types::ID lookupTypeForExtension (const Driver &D, const llvm::Triple &TT,
2665
+ llvm::StringRef Ext) {
2666
+ types::ID Ty = types::lookupTypeForExtension (Ext);
2667
+
2668
+ // Flang always runs the preprocessor and has no notion of "preprocessed
2669
+ // fortran". Here, TY_PP_Fortran is coerced to TY_Fortran to avoid treating
2670
+ // them differently.
2671
+ if (D.IsFlangMode () && Ty == types::TY_PP_Fortran)
2672
+ Ty = types::TY_Fortran;
2673
+
2674
+ // Darwin always preprocesses assembly files (unless -x is used explicitly).
2675
+ if (TT.isOSBinFormatMachO () && Ty == types::TY_PP_Asm)
2676
+ Ty = types::TY_Asm;
2677
+ return Ty;
2678
+ }
2679
+
2663
2680
// Construct a the list of inputs and their types.
2664
- void Driver::BuildInputs (const ToolChain &TC , DerivedArgList &Args,
2681
+ void Driver::BuildInputs (const llvm::Triple &TT , DerivedArgList &Args,
2665
2682
InputList &Inputs) const {
2666
2683
const llvm::opt::OptTable &Opts = getOpts ();
2667
2684
// Track the current user specified (-x) input. We also explicitly track the
@@ -2739,7 +2756,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2739
2756
// We use a host hook here because Darwin at least has its own
2740
2757
// idea of what .s is.
2741
2758
if (const char *Ext = strrchr (Value, ' .' ))
2742
- Ty = TC. LookupTypeForExtension ( Ext + 1 );
2759
+ Ty = lookupTypeForExtension (* this , TT, Ext + 1 );
2743
2760
2744
2761
if (Ty == types::TY_INVALID) {
2745
2762
if (IsCLMode () && (Args.hasArgNoClaim (options::OPT_E) || CCGenDiagnostics))
@@ -2795,7 +2812,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2795
2812
// If emulating cl.exe, make sure that /TC and /TP don't affect input
2796
2813
// object files.
2797
2814
const char *Ext = strrchr (Value, ' .' );
2798
- if (Ext && TC.LookupTypeForExtension (Ext + 1 ) == types::TY_Object)
2815
+ if (Ext &&
2816
+ lookupTypeForExtension (*this , TT, Ext + 1 ) == types::TY_Object)
2799
2817
Ty = types::TY_Object;
2800
2818
}
2801
2819
if (Ty == types::TY_INVALID) {
@@ -5613,9 +5631,9 @@ InputInfoList Driver::BuildJobsForActionNoCache(
5613
5631
StringRef ArchName = BAA->getArchName ();
5614
5632
5615
5633
if (!ArchName.empty ())
5616
- TC = &getToolChain (C. getArgs (),
5617
- computeTargetTriple (* this , TargetTriple ,
5618
- C.getArgs (), ArchName));
5634
+ TC = &getToolChain (
5635
+ C. getArgs () ,
5636
+ computeTargetTriple (* this , TargetTriple, C.getArgs (), ArchName), {} );
5619
5637
else
5620
5638
TC = &C.getDefaultToolChain ();
5621
5639
@@ -6376,7 +6394,8 @@ std::string Driver::GetClPchPath(Compilation &C, StringRef BaseName) const {
6376
6394
}
6377
6395
6378
6396
const ToolChain &Driver::getToolChain (const ArgList &Args,
6379
- const llvm::Triple &Target) const {
6397
+ const llvm::Triple &Target,
6398
+ const InputList &Inputs) const {
6380
6399
6381
6400
auto &TC = ToolChains[Target.str ()];
6382
6401
if (!TC) {
@@ -6444,7 +6463,12 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
6444
6463
TC = std::make_unique<toolchains::NVPTXToolChain>(*this , Target, Args);
6445
6464
break ;
6446
6465
case llvm::Triple::AMDHSA:
6447
- TC = std::make_unique<toolchains::ROCMToolChain>(*this , Target, Args);
6466
+ TC =
6467
+ llvm::any_of (Inputs,
6468
+ [](auto &Input) { return types::isOpenCL (Input.first ); })
6469
+ ? std::make_unique<toolchains::ROCMToolChain>(*this , Target, Args)
6470
+ : std::make_unique<toolchains::AMDGPUToolChain>(*this , Target,
6471
+ Args);
6448
6472
break ;
6449
6473
case llvm::Triple::AMDPAL:
6450
6474
case llvm::Triple::Mesa3D:
0 commit comments