Skip to content

Commit

Permalink
[Driver] Allow Classic Flang driver to accept more Clang options
Browse files Browse the repository at this point in the history
This patch cherry-picks a number of Visibility changes from the tip of trunk
upstream, to make selected Clang options visible to Classic Flang. It also
makes target-specific codegen options (-mxxxx) visible to Flang by default.
Note that accepting the option does not imply support; Classic Flang may
simply ignore certain options for backward compatibility.
  • Loading branch information
bryanpkc committed Jul 24, 2024
1 parent 15cbdd5 commit 97b6ab9
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
73 changes: 71 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def hip_Group : OptionGroup<"<HIP group>">, Group<f_Group>,

def m_Group : OptionGroup<"<m group>">, Group<CompileOnly_Group>,
DocName<"Target-dependent compilation options">,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CLOption, FlangOption]>;
#else
Visibility<[ClangOption, CLOption]>;
#endif

// Feature groups - these take command line options that correspond directly to
// target specific features and can be translated directly from command line
Expand Down Expand Up @@ -199,10 +203,18 @@ def m_wasm_Features_Group : OptionGroup<"<wasm features group>">,
def m_wasm_Features_Driver_Group : OptionGroup<"<wasm driver features group>">,
Group<m_Group>, DocName<"WebAssembly Driver">;
def m_x86_Features_Group : OptionGroup<"<x86 features group>">,
#ifdef ENABLE_CLASSIC_FLANG
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
#else
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
#endif
DocName<"X86">;
def m_x86_AVX10_Features_Group : OptionGroup<"<x86 AVX10 features group>">,
#ifdef ENABLE_CLASSIC_FLANG
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
#else
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
#endif
DocName<"X86 AVX10">;
def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
Group<m_Group>, DocName<"RISC-V">;
Expand Down Expand Up @@ -768,10 +780,22 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>;
def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>,
Group<gfortran_Group>;
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
#ifdef ENABLE_CLASSIC_FLANG
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
Visibility<[ClangOption, FlangOption]>,
#endif
HelpText<"Search $prefix$file for executables, libraries, and data files. "
"If $prefix is a directory, search $prefix/$file">;
def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
Visibility<[ClangOption, FlangOption]>,
HelpText<"Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
"Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation">;
def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
Visibility<[ClangOption, FlangOption]>,
HelpText<
"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
"Clang will use the GCC installation with the largest version">;
#else
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
HelpText<"Search $prefix$file for executables, libraries, and data files. "
"If $prefix is a directory, search $prefix/$file">;
def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
Expand All @@ -780,6 +804,7 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
HelpText<"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
"Clang will use the GCC installation with the largest version">;
#endif
def gcc_triple_EQ : Joined<["--"], "gcc-triple=">,
HelpText<"Search for the GCC installation with the specified triple.">;
def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>,
Expand Down Expand Up @@ -3255,7 +3280,11 @@ defm diagnostics_show_line_numbers : BoolFOption<"diagnostics-show-line-numbers"
def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>,
HelpText<"Disable the use of stack protectors">;
def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
#else
Visibility<[ClangOption, CLOption, DXCOption]>,
#endif
HelpText<"Disable optimizations based on strict aliasing rules">;
def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
Expand Down Expand Up @@ -3859,10 +3888,17 @@ def ftrap_function_EQ : Joined<["-"], "ftrap-function=">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Issue call to specified function rather than a trap instruction">,
MarshallingInfoString<CodeGenOpts<"TrapFuncName">>;
#ifdef ENABLE_CLASSIC_FLANG
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption]>;
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,
HelpText<"Turn off loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption]>;
#else
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option]>;
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,
HelpText<"Turn off loop unroller">, Visibility<[ClangOption, CC1Option]>;
#endif
defm reroll_loops : BoolFOption<"reroll-loops",
CodeGenOpts<"RerollLoops">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Turn on loop reroller">,
Expand Down Expand Up @@ -4458,17 +4494,29 @@ def mwatchsimulator_version_min_EQ : Joined<["-"], "mwatchsimulator-version-min=
def march_EQ : Joined<["-"], "march=">, Group<m_Group>,
Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
HelpText<"For a list of available architectures for the target use '-mcpu=help'">;
#ifdef ENABLE_CLASSIC_FLANG
def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Visibility<[ClangOption, FlangOption]>;
#else
def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>;
#endif
def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group<m_Group>,
Visibility<[ClangOption, CC1Option]>,
Values<"att,intel">,
NormalizedValuesScope<"CodeGenOptions">, NormalizedValues<["IAD_ATT", "IAD_Intel"]>,
MarshallingInfoEnum<CodeGenOpts<"InlineAsmDialect">, "IAD_ATT">;
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
#else
Visibility<[ClangOption, CC1Option]>,
#endif
MarshallingInfoString<TargetOpts<"CodeModel">, [{"default"}]>;
def mlarge_data_threshold_EQ : Joined<["-"], "mlarge-data-threshold=">, Group<m_Group>,
#ifdef ENABLE_CLASSIC_FLANG
Flags<[TargetSpecific]>, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
#else
Flags<[TargetSpecific]>, Visibility<[ClangOption, CC1Option]>,
#endif
MarshallingInfoInt<TargetOpts<"LargeDataThreshold">, "0">;
def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group<m_Group>,
Visibility<[ClangOption, CC1Option]>,
Expand Down Expand Up @@ -5033,12 +5081,21 @@ def msoft_float : Flag<["-"], "msoft-float">, Group<m_Group>,
def mno_fmv : Flag<["-"], "mno-fmv">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Disable function multiversioning">;
#ifdef ENABLE_CLASSIC_FLANG
def moutline_atomics : Flag<["-"], "moutline-atomics">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option, FlangOption]>,
HelpText<"Generate local calls to out-of-line atomic operations">;
def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option, FlangOption]>,
HelpText<"Don't generate local calls to out-of-line atomic operations">;
#else
def moutline_atomics : Flag<["-"], "moutline-atomics">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Generate local calls to out-of-line atomic operations">;
def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Don't generate local calls to out-of-line atomic operations">;
#endif
def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group<m_Group>,
HelpText<"Don't generate implicit floating point or vector instructions">;
def mimplicit_float : Flag<["-"], "mimplicit-float">, Group<m_Group>;
Expand Down Expand Up @@ -5369,7 +5426,11 @@ def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
Visibility<[ClangOption, CLOption]>;
def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
HelpText<"Print the resource directory pathname">,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CLOption, FlangOption]>;
#else
Visibility<[ClangOption, CLOption]>;
#endif
def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
HelpText<"Print the paths used for finding libraries and programs">,
Visibility<[ClangOption, CLOption]>;
Expand Down Expand Up @@ -5406,11 +5467,19 @@ def rdynamic : Flag<["-"], "rdynamic">, Group<Link_Group>,
Visibility<[ClangOption, FlangOption]>;
def resource_dir : Separate<["-"], "resource-dir">,
Flags<[NoXarchOption, HelpHidden]>,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
#else
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
#endif
HelpText<"The directory which holds the compiler resource files">,
MarshallingInfoString<HeaderSearchOpts<"ResourceDir">>;
def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
#ifdef ENABLE_CLASSIC_FLANG
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
#else
Visibility<[ClangOption, CLOption, DXCOption]>,
#endif
Alias<resource_dir>;
def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
Expand Down
22 changes: 20 additions & 2 deletions clang/test/Driver/flang/classic-flang.f95
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

! Check that the driver invokes flang1 correctly for preprocessed free-form
! Fortran code. Also check that the backend is invoked correctly.
! In particular, target-dependent flags (e.g. -mavx for x86_64) should be visible.

! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu -c %s -### 2>&1 \
! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu -mavx -c %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: "{{.*}}flang1"
! CHECK-OBJECT-NOT: "-preprocess"
! CHECK-OBJECT-SAME: "-freeform"
! CHECK-OBJECT-NEXT: "{{.*}}flang2"
! CHECK-OBJECT-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-OBJECT-NEXT: {{clang.* "-cc1"}}
! CHECK-OBJECT-SAME: "-target-feature" "+avx"
! CHECK-OBJECT-SAME: "-o" "classic-flang.o"
! CHECK-OBJECT-SAME: "-x" "ir"
! CHECK-OBJECT-SAME: [[LLFILE]]
Expand All @@ -31,17 +33,33 @@

! Check that the backend job (clang -cc1) is not combined into the compile job
! (flang2) even if -integrated-as is specified.
! Also, check that AArch64-specific target-dependent flags are visible.

! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu -integrated-as -S %s -### 2>&1 \
! RUN: %clang --driver-mode=flang -target aarch64-unknown-linux-gnu -integrated-as -mno-outline-atomics -S %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-ASM %s
! CHECK-ASM: "{{.*}}flang1"
! CHECK-ASM-NEXT: "{{.*}}flang2"
! CHECK-ASM-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-ASM-NEXT: {{clang.* "-cc1"}}
! CHECK-ASM-SAME: "-target-feature" "-outline-atomics"
! CHECK-ASM-SAME: "-o" "classic-flang.s"
! CHECK-ASM-SAME: "-x" "ir"
! CHECK-ASM-SAME: [[LLFILE]]

! Check that other target-independent compiler flags are visible.
! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu --gcc-install-dir=%S/../Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10/ -fno-strict-aliasing -funroll-loops %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-FFLAGS %s
! CHECK-FFLAGS: "{{.*}}flang1"
! CHECK-FFLAGS-NEXT: "{{.*}}flang2"
! CHECK-FFLAGS-SAME: "-asm" [[LLFILE:.*.ll]]
! CHECK-FFLAGS-NEXT: {{clang.* "-cc1"}}
! CHECK-FFLAGS-SAME: "-relaxed-aliasing"
! CHECK-FFLAGS-SAME: "-funroll-loops"
! CHECK-FFLAGS-SAME: "-x" "ir"
! CHECK-FFLAGS-SAME: [[LLFILE]]
! CHECK-FFLAGS-NEXT: "{{.*}}ld{{(.exe)?}}"
! CHECK-FFLAGS-SAME: "-L{{[^ ]*[/\\]+}}debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10"

! Check that the linker job is given the correct libraries and library paths.

! RUN: %flang -target x86_64-linux-gnu -ccc-install-dir %S/../Inputs/basic_linux_tree/usr/bin -mp \
Expand Down

0 comments on commit 97b6ab9

Please sign in to comment.