Skip to content

Commit af2bc75

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 488ff60 commit af2bc75

File tree

13 files changed

+54
-24
lines changed

13 files changed

+54
-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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6972,11 +6972,11 @@ def fconvert_EQ : Joined<["-"], "fconvert=">, Group<f_Group>,
69726972
HelpText<"Set endian conversion of data for unformatted files">;
69736973
def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group<f_Group>,
69746974
HelpText<"Set the default double precision kind to an 8 byte wide type">;
6975+
def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>,
6976+
HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
69756977
#ifdef ENABLE_CLASSIC_FLANG
69766978
def fno_default_integer_8 : Flag<["-"], "fno-default-integer-8">, Group<f_Group>;
69776979
#endif
6978-
def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>,
6979-
HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
69806980
def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group<f_Group>,
69816981
HelpText<"Set the default real kind to an 8 byte wide type">;
69826982
#ifdef ENABLE_CLASSIC_FLANG
@@ -9180,8 +9180,8 @@ def wasm_opt : Flag<["--"], "wasm-opt">,
91809180
MarshallingInfoNegativeFlag<LangOpts<"NoWasmOpt">>;
91819181

91829182
#ifdef ENABLE_CLASSIC_FLANG
9183-
// gfortran options that we recognize in the driver and pass along when
9184-
// invoking GCC to compile Fortran code.
9183+
// Classic Flang options that we recognize in the driver and pass along when
9184+
// invoking flang1/flang2 to compile Fortran code.
91859185
def flang_rt_Group : OptionGroup<"Flang runtime library Group">;
91869186
def pgi_fortran_Group : OptionGroup<"PGI Fortran compatibility Group">,
91879187
Flags<[HelpHidden]>;

clang/include/clang/Driver/ToolChain.h

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

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

686688
/// Add options that need to be passed to cc1 for this target.
687689
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
@@ -800,10 +802,12 @@ class ToolChain {
800802
virtual void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
801803
llvm::opt::ArgStringList &CmdArgs) const {}
802804

805+
#ifdef ENABLE_CLASSIC_FLANG
803806
/// AddFortranStdlibLibArgs - Add the system specific linker arguments to use
804807
/// for the given Fortran runtime library type.
805808
virtual void AddFortranStdlibLibArgs(const llvm::opt::ArgList &Args,
806809
llvm::opt::ArgStringList &CmdArgs) const;
810+
#endif
807811

808812
/// Return sanitizers which are available in this toolchain.
809813
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
@@ -94,7 +96,6 @@ add_clang_library(clangDriver
9496
ToolChains/ZOS.cpp
9597
Types.cpp
9698
XRayArgs.cpp
97-
${CLASSIC_FLANG_FILES}
9899

99100
DEPENDS
100101
ClangDriverOptions

clang/lib/Driver/ToolChain.cpp

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

558558
Tool *ToolChain::getFlang() const {
559+
#ifndef ENABLE_CLASSIC_FLANG
559560
if (!Flang)
560561
Flang.reset(new tools::Flang(*this));
561562
return Flang.get();
563+
#else
564+
llvm_unreachable("Flang is not supported by this toolchain");
565+
#endif
562566
}
563567

564568
Tool *ToolChain::buildAssembler() const {
@@ -1429,6 +1433,7 @@ void ToolChain::AddCCKextLibArgs(const ArgList &Args,
14291433
CmdArgs.push_back("-lcc_kext");
14301434
}
14311435

1436+
#ifdef ENABLE_CLASSIC_FLANG
14321437
void ToolChain::AddFortranStdlibLibArgs(const ArgList &Args,
14331438
ArgStringList &CmdArgs) const {
14341439
bool staticFlangLibs = false;
@@ -1467,6 +1472,7 @@ void ToolChain::AddFortranStdlibLibArgs(const ArgList &Args,
14671472
// Allways link Fortran executables with Pthreads
14681473
CmdArgs.push_back("-lpthread");
14691474
}
1475+
#endif
14701476

14711477
bool ToolChain::isFastMathRuntimeAvailable(const ArgList &Args,
14721478
std::string &Path) const {

clang/lib/Driver/ToolChains/ClassicFlang.cpp

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

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

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

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

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

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

clang/lib/Driver/ToolChains/CommonArgs.cpp

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

345+
#ifdef ENABLE_CLASSIC_FLANG
345346
/// \brief Determine if Fortran "main" object is needed
346347
static bool needFortranMain(const Driver &D, const ArgList &Args) {
347348
return (needFortranLibs(D, Args)
@@ -358,6 +359,7 @@ bool tools::needFortranLibs(const Driver &D, const ArgList &Args) {
358359

359360
return false;
360361
}
362+
#endif
361363

362364
void tools::addPathIfExists(const Driver &D, const Twine &Path,
363365
ToolChain::path_list &Paths) {
@@ -467,7 +469,9 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
467469
const ArgList &Args, ArgStringList &CmdArgs,
468470
const JobAction &JA) {
469471
const Driver &D = TC.getDriver();
472+
#ifdef ENABLE_CLASSIC_FLANG
470473
bool SeenFirstLinkerInput = false;
474+
#endif
471475

472476
// Add extra linker input arguments which are not treated as inputs
473477
// (constructed via -Xarch_).
@@ -501,14 +505,15 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
501505
if (II.isNothing())
502506
continue;
503507

508+
#ifdef ENABLE_CLASSIC_FLANG
504509
// Add Fortan "main" before the first linker input
505510
if (!SeenFirstLinkerInput) {
506511
if (needFortranMain(D, Args)) {
507512
CmdArgs.push_back("-lflangmain");
508513
}
509514
SeenFirstLinkerInput = true;
510515
}
511-
516+
#endif
512517
// Otherwise, this is a linker input argument.
513518
const Arg &A = II.getInputArg();
514519

@@ -553,7 +558,7 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
553558
addArchSpecificRPath(TC, Args, CmdArgs);
554559
}
555560
}
556-
561+
#ifdef ENABLE_CLASSIC_FLANG
557562
if (!SeenFirstLinkerInput && needFortranMain(D, Args)) {
558563
CmdArgs.push_back("-lflangmain");
559564
}
@@ -562,6 +567,7 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
562567
for (auto Arg : Args.filtered(options::OPT_no_fortran_main, options::OPT_Mnomain)) {
563568
Arg->claim();
564569
}
570+
#endif
565571
}
566572

567573
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
@@ -1075,6 +1075,7 @@ VersionTuple CudaToolChain::computeMSVCVersion(const Driver *D,
10751075
return HostTC.computeMSVCVersion(D, Args);
10761076
}
10771077

1078+
#ifdef ENABLE_CLASSIC_FLANG
10781079
static void AddFlangSysIncludeArg(const ArgList &DriverArgs,
10791080
ArgStringList &Flang1Args,
10801081
ToolChain::path_list IncludePathList) {
@@ -1107,3 +1108,4 @@ void CudaToolChain::AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverAr
11071108
IncludePathList.push_back(P.c_str());
11081109
AddFlangSysIncludeArg(DriverArgs, Flang1Args, IncludePathList);
11091110
}
1111+
#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)