Skip to content

Commit 4341503

Browse files
committed
[ClassicFlang][Driver] Coexist with LLVM Flang
Make TableGen respect the ENABLE_CLASSIC_FLANG macro and better separate the driver options that are mutually exclusive. When the macro is defined, do not build LLVM Flang at all.
1 parent 9b92884 commit 4341503

File tree

13 files changed

+55
-24
lines changed

13 files changed

+55
-24
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
set(LLVM_TARGET_DEFINITIONS Options.td)
2-
tablegen(LLVM Options.inc -gen-opt-parser-defs)
2+
if(LLVM_ENABLE_CLASSIC_FLANG)
3+
tablegen(LLVM Options.inc -DENABLE_CLASSIC_FLANG -gen-opt-parser-defs)
4+
else()
5+
tablegen(LLVM Options.inc -gen-opt-parser-defs)
6+
endif()
37
add_public_tablegen_target(ClangDriverOptions)

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6718,18 +6718,19 @@ def fconvert_EQ : Joined<["-"], "fconvert=">, Group<f_Group>,
67186718
HelpText<"Set endian conversion of data for unformatted files">;
67196719
def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group<f_Group>,
67206720
HelpText<"Set the default double precision kind to an 8 byte wide type">;
6721+
def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>,
6722+
HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
67216723
#ifdef ENABLE_CLASSIC_FLANG
67226724
def fno_default_integer_8 : Flag<["-"], "fno-default-integer-8">, Group<f_Group>;
67236725
#endif
6724-
def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>,
6725-
HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
67266726
def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group<f_Group>,
67276727
HelpText<"Set the default real kind to an 8 byte wide type">;
67286728
#ifdef ENABLE_CLASSIC_FLANG
67296729
def fno_default_real_8 : Flag<["-"], "fno-default-real-8">, Group<f_Group>;
67306730
#endif
67316731
def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>,
67326732
HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics">;
6733+
67336734
def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group<f_Group>,
67346735
HelpText<"Enable the old style PARAMETER statement">;
67356736
def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">, Group<f_Group>, MetaVarName<"<dir>">,
@@ -8861,8 +8862,8 @@ def enable_16bit_types : DXCFlag<"enable-16bit-types">, Alias<fnative_half_type>
88618862
"Available in HLSL 2018 and shader model 6.2.">;
88628863

88638864
#ifdef ENABLE_CLASSIC_FLANG
8864-
// gfortran options that we recognize in the driver and pass along when
8865-
// invoking GCC to compile Fortran code.
8865+
// Classic Flang options that we recognize in the driver and pass along when
8866+
// invoking flang1/flang2 to compile Fortran code.
88668867
def flang_rt_Group : OptionGroup<"Flang runtime library Group">;
88678868
def pgi_fortran_Group : OptionGroup<"PGI Fortran compatibility Group">,
88688869
Flags<[HelpHidden]>;

clang/include/clang/Driver/ToolChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,15 @@ class ToolChain {
676676
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
677677
llvm::opt::ArgStringList &CC1Args) const;
678678

679+
#ifdef ENABLE_CLASSIC_FLANG
679680
/// \brief Add the flang arguments for system include paths.
680681
///
681682
/// This routine is responsible for adding the -stdinc argument to
682683
/// include headers and module files from standard system header directories.
683684
virtual void
684685
AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
685686
llvm::opt::ArgStringList &Flang1Args) const { }
687+
#endif
686688

687689
/// Add options that need to be passed to cc1 for this target.
688690
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
@@ -790,10 +792,12 @@ class ToolChain {
790792
virtual void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
791793
llvm::opt::ArgStringList &CmdArgs) const {}
792794

795+
#ifdef ENABLE_CLASSIC_FLANG
793796
/// AddFortranStdlibLibArgs - Add the system specific linker arguments to use
794797
/// for the given Fortran runtime library type.
795798
virtual void AddFortranStdlibLibArgs(const llvm::opt::ArgList &Args,
796799
llvm::opt::ArgStringList &CmdArgs) const;
800+
#endif
797801

798802
/// Return sanitizers which are available in this toolchain.
799803
virtual SanitizerMask getSupportedSanitizers() const;

clang/lib/Driver/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ if(WIN32)
1515
endif()
1616

1717
if(LLVM_ENABLE_CLASSIC_FLANG)
18-
set(CLASSIC_FLANG_FILES ToolChains/ClassicFlang.cpp)
18+
set(TOOLCHAINS_FLANG_CPP ToolChains/ClassicFlang.cpp)
19+
else()
20+
set(TOOLCHAINS_FLANG_CPP ToolChains/Flang.cpp)
1921
endif()
2022

2123
add_clang_library(clangDriver
@@ -57,7 +59,7 @@ add_clang_library(clangDriver
5759
ToolChains/Cuda.cpp
5860
ToolChains/Darwin.cpp
5961
ToolChains/DragonFly.cpp
60-
ToolChains/Flang.cpp
62+
${TOOLCHAINS_FLANG_CPP}
6163
ToolChains/FreeBSD.cpp
6264
ToolChains/Fuchsia.cpp
6365
ToolChains/Gnu.cpp
@@ -91,7 +93,6 @@ add_clang_library(clangDriver
9193
ToolChains/ZOS.cpp
9294
Types.cpp
9395
XRayArgs.cpp
94-
${CLASSIC_FLANG_FILES}
9596

9697
DEPENDS
9798
ClangDriverOptions

clang/lib/Driver/ToolChain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,13 @@ Tool *ToolChain::getClang() const {
467467
}
468468

469469
Tool *ToolChain::getFlang() const {
470+
#ifndef ENABLE_CLASSIC_FLANG
470471
if (!Flang)
471472
Flang.reset(new tools::Flang(*this));
472473
return Flang.get();
474+
#else
475+
llvm_unreachable("Flang is not supported by this toolchain");
476+
#endif
473477
}
474478

475479
Tool *ToolChain::buildAssembler() const {
@@ -1332,6 +1336,7 @@ void ToolChain::AddCCKextLibArgs(const ArgList &Args,
13321336
CmdArgs.push_back("-lcc_kext");
13331337
}
13341338

1339+
#ifdef ENABLE_CLASSIC_FLANG
13351340
void ToolChain::AddFortranStdlibLibArgs(const ArgList &Args,
13361341
ArgStringList &CmdArgs) const {
13371342
bool staticFlangLibs = false;
@@ -1370,6 +1375,7 @@ void ToolChain::AddFortranStdlibLibArgs(const ArgList &Args,
13701375
// Allways link Fortran executables with Pthreads
13711376
CmdArgs.push_back("-lpthread");
13721377
}
1378+
#endif
13731379

13741380
bool ToolChain::isFastMathRuntimeAvailable(const ArgList &Args,
13751381
std::string &Path) const {

clang/lib/Driver/ToolChains/ClassicFlang.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,18 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
366366
// Handle -fdefault-real-8 (and its alias, -r8) and -fno-default-real-8
367367
if (Arg *A = Args.getLastArg(options::OPT_r8,
368368
options::OPT_fdefault_real_8,
369-
options::OPT_default_real_8_fno)) {
369+
options::OPT_fno_default_real_8)) {
370370
const char * fl;
371371
// For -f version add -x flag, for -fno add -y
372-
if (A->getOption().matches(options::OPT_default_real_8_fno)) {
372+
if (A->getOption().matches(options::OPT_fno_default_real_8)) {
373373
fl = "-y";
374374
} else {
375375
fl = "-x";
376376
}
377377

378378
for (Arg *A : Args.filtered(options::OPT_r8,
379379
options::OPT_fdefault_real_8,
380-
options::OPT_default_real_8_fno)) {
380+
options::OPT_fno_default_real_8)) {
381381
A->claim();
382382
}
383383

@@ -392,18 +392,18 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
392392
// Process and claim -i8/-fdefault-integer-8/-fno-default-integer-8 argument
393393
if (Arg *A = Args.getLastArg(options::OPT_i8,
394394
options::OPT_fdefault_integer_8,
395-
options::OPT_default_integer_8_fno)) {
395+
options::OPT_fno_default_integer_8)) {
396396
const char * fl;
397397

398-
if (A->getOption().matches(options::OPT_default_integer_8_fno)) {
398+
if (A->getOption().matches(options::OPT_fno_default_integer_8)) {
399399
fl = "-y";
400400
} else {
401401
fl = "-x";
402402
}
403403

404404
for (Arg *A : Args.filtered(options::OPT_i8,
405405
options::OPT_fdefault_integer_8,
406-
options::OPT_default_integer_8_fno)) {
406+
options::OPT_fno_default_integer_8)) {
407407
A->claim();
408408
}
409409

@@ -730,14 +730,14 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
730730
default:
731731
llvm_unreachable("missed a case");
732732
case options::OPT_ffixed_form:
733-
case options::OPT_free_form_off:
733+
case options::OPT_fno_free_form:
734734
case options::OPT_Mfixed:
735735
case options::OPT_Mfree_off:
736736
case options::OPT_Mfreeform_off:
737737
UpperCmdArgs.push_back("-nofreeform");
738738
break;
739739
case options::OPT_ffree_form:
740-
case options::OPT_fixed_form_off:
740+
case options::OPT_fno_fixed_form:
741741
case options::OPT_Mfree_on:
742742
case options::OPT_Mfreeform_on:
743743
UpperCmdArgs.push_back("-freeform");

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ static bool shouldIgnoreUnsupportedTargetFeature(const Arg &TargetFeatureArg,
337337
return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode);
338338
}
339339

340+
#ifdef ENABLE_CLASSIC_FLANG
340341
/// \brief Determine if Fortran "main" object is needed
341342
static bool needFortranMain(const Driver &D, const ArgList &Args) {
342343
return (needFortranLibs(D, Args)
@@ -353,6 +354,7 @@ bool tools::needFortranLibs(const Driver &D, const ArgList &Args) {
353354

354355
return false;
355356
}
357+
#endif
356358

357359
void tools::addPathIfExists(const Driver &D, const Twine &Path,
358360
ToolChain::path_list &Paths) {
@@ -462,7 +464,9 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
462464
const ArgList &Args, ArgStringList &CmdArgs,
463465
const JobAction &JA) {
464466
const Driver &D = TC.getDriver();
467+
#ifdef ENABLE_CLASSIC_FLANG
465468
bool SeenFirstLinkerInput = false;
469+
#endif
466470

467471
// Add extra linker input arguments which are not treated as inputs
468472
// (constructed via -Xarch_).
@@ -496,14 +500,15 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
496500
if (II.isNothing())
497501
continue;
498502

503+
#ifdef ENABLE_CLASSIC_FLANG
499504
// Add Fortan "main" before the first linker input
500505
if (!SeenFirstLinkerInput) {
501506
if (needFortranMain(D, Args)) {
502507
CmdArgs.push_back("-lflangmain");
503508
}
504509
SeenFirstLinkerInput = true;
505510
}
506-
511+
#endif
507512
// Otherwise, this is a linker input argument.
508513
const Arg &A = II.getInputArg();
509514

@@ -515,7 +520,7 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
515520
else
516521
A.renderAsInput(Args, CmdArgs);
517522
}
518-
523+
#ifdef ENABLE_CLASSIC_FLANG
519524
if (!SeenFirstLinkerInput && needFortranMain(D, Args)) {
520525
CmdArgs.push_back("-lflangmain");
521526
}
@@ -524,6 +529,7 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
524529
for (auto Arg : Args.filtered(options::OPT_no_fortran_main, options::OPT_Mnomain)) {
525530
Arg->claim();
526531
}
532+
#endif
527533
}
528534

529535
void tools::addLinkerCompressDebugSectionsOption(

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ namespace clang {
2424
namespace driver {
2525
namespace tools {
2626

27+
#ifdef ENABLE_CLASSIC_FLANG
2728
bool needFortranLibs(const Driver &D, const llvm::opt::ArgList &Args);
29+
#endif
2830

2931
void addPathIfExists(const Driver &D, const Twine &Path,
3032
ToolChain::path_list &Paths);

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ VersionTuple CudaToolChain::computeMSVCVersion(const Driver *D,
10361036
return HostTC.computeMSVCVersion(D, Args);
10371037
}
10381038

1039+
#ifdef ENABLE_CLASSIC_FLANG
10391040
static void AddFlangSysIncludeArg(const ArgList &DriverArgs,
10401041
ArgStringList &Flang1Args,
10411042
ToolChain::path_list IncludePathList) {
@@ -1068,3 +1069,4 @@ void CudaToolChain::AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverAr
10681069
IncludePathList.push_back(P.c_str());
10691070
AddFlangSysIncludeArg(DriverArgs, Flang1Args, IncludePathList);
10701071
}
1072+
#endif

clang/lib/Driver/ToolChains/Cuda.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
222222
llvm::opt::ArgStringList &CC1Args) const override;
223223
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
224224
llvm::opt::ArgStringList &CC1Args) const override;
225+
#ifdef ENABLE_CLASSIC_FLANG
226+
void
227+
AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
228+
llvm::opt::ArgStringList &Flang1Args) const override;
229+
#endif
225230

226231
SanitizerMask getSupportedSanitizers() const override;
227232

@@ -231,12 +236,6 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
231236

232237
const ToolChain &HostTC;
233238

234-
#ifdef ENABLE_CLASSIC_FLANG
235-
void
236-
AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
237-
llvm::opt::ArgStringList &Flang1Args) const override;
238-
#endif
239-
240239
protected:
241240
Tool *buildAssembler() const override; // ptxas
242241
Tool *buildLinker() const override; // fatbinary (ok, not really a linker)

0 commit comments

Comments
 (0)