Skip to content

Commit 1000532

Browse files
committed
[Driver] Allow Classic Flang driver to accept more Clang options
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.
1 parent d91a7f2 commit 1000532

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ def hip_Group : OptionGroup<"<HIP group>">, Group<f_Group>,
194194

195195
def m_Group : OptionGroup<"<m group>">, Group<CompileOnly_Group>,
196196
DocName<"Target-dependent compilation options">,
197+
#ifdef ENABLE_CLASSIC_FLANG
198+
Visibility<[ClangOption, CLOption, FlangOption]>;
199+
#else
197200
Visibility<[ClangOption, CLOption]>;
201+
#endif
198202

199203
def hlsl_Group : OptionGroup<"<HLSL group>">, Group<f_Group>,
200204
DocName<"HLSL options">,
@@ -230,10 +234,18 @@ def m_wasm_Features_Group : OptionGroup<"<wasm features group>">,
230234
def m_wasm_Features_Driver_Group : OptionGroup<"<wasm driver features group>">,
231235
Group<m_Group>, DocName<"WebAssembly Driver">;
232236
def m_x86_Features_Group : OptionGroup<"<x86 features group>">,
237+
#ifdef ENABLE_CLASSIC_FLANG
238+
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
239+
#else
233240
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
241+
#endif
234242
DocName<"X86">;
235243
def m_x86_AVX10_Features_Group : OptionGroup<"<x86 AVX10 features group>">,
244+
#ifdef ENABLE_CLASSIC_FLANG
245+
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
246+
#else
236247
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
248+
#endif
237249
DocName<"X86 AVX10">;
238250
def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
239251
Group<m_Group>, DocName<"RISC-V">;
@@ -819,12 +831,16 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
819831
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>;
820832
def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>,
821833
Group<gfortran_Group>;
822-
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
823834
#ifdef ENABLE_CLASSIC_FLANG
835+
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
824836
Visibility<[ClangOption, FlangOption]>,
825-
#endif
826837
HelpText<"Search $prefix$file for executables, libraries, and data files. "
827838
"If $prefix is a directory, search $prefix/$file">;
839+
#else
840+
def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
841+
HelpText<"Search $prefix$file for executables, libraries, and data files. "
842+
"If $prefix is a directory, search $prefix/$file">;
843+
#endif
828844
def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
829845
Visibility<[ClangOption, FlangOption]>,
830846
HelpText<"Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
@@ -3405,7 +3421,11 @@ defm diagnostics_show_line_numbers : BoolFOption<"diagnostics-show-line-numbers"
34053421
def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>,
34063422
HelpText<"Disable the use of stack protectors">;
34073423
def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
3424+
#ifdef ENABLE_CLASSIC_FLANG
3425+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
3426+
#else
34083427
Visibility<[ClangOption, CLOption, DXCOption]>,
3428+
#endif
34093429
HelpText<"Disable optimizations based on strict aliasing rules">;
34103430
def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
34113431
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
@@ -4056,10 +4076,17 @@ def ftrap_function_EQ : Joined<["-"], "ftrap-function=">, Group<f_Group>,
40564076
Visibility<[ClangOption, CC1Option]>,
40574077
HelpText<"Issue call to specified function rather than a trap instruction">,
40584078
MarshallingInfoString<CodeGenOpts<"TrapFuncName">>;
4079+
#ifdef ENABLE_CLASSIC_FLANG
4080+
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
4081+
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption]>;
4082+
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,
4083+
HelpText<"Turn off loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption]>;
4084+
#else
40594085
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
40604086
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option]>;
40614087
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,
40624088
HelpText<"Turn off loop unroller">, Visibility<[ClangOption, CC1Option]>;
4089+
#endif
40634090
def ffinite_loops: Flag<["-"], "ffinite-loops">, Group<f_Group>,
40644091
HelpText<"Assume all non-trivial loops are finite.">, Visibility<[ClangOption, CC1Option]>;
40654092
def fno_finite_loops: Flag<["-"], "fno-finite-loops">, Group<f_Group>,

clang/test/Driver/flang/classic-flang.f95

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

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

6-
! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu -c %s -### 2>&1 \
7+
! RUN: %clang --driver-mode=flang -target x86_64-unknown-linux-gnu -mavx -c %s -### 2>&1 \
78
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
89
! CHECK-OBJECT: "{{.*}}flang1"
910
! CHECK-OBJECT-NOT: "-preprocess"
1011
! CHECK-OBJECT-SAME: "-freeform"
1112
! CHECK-OBJECT-NEXT: "{{.*}}flang2"
1213
! CHECK-OBJECT-SAME: "-asm" [[LLFILE:.*.ll]]
1314
! CHECK-OBJECT-NEXT: {{clang.* "-cc1"}}
15+
! CHECK-OBJECT-SAME: "-target-feature" "+avx"
1416
! CHECK-OBJECT-SAME: "-o" "classic-flang.o"
1517
! CHECK-OBJECT-SAME: "-x" "ir"
1618
! CHECK-OBJECT-SAME: [[LLFILE]]
@@ -31,17 +33,33 @@
3133

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

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

49+
! Check that other target-independent compiler flags are visible.
50+
! 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 \
51+
! RUN: | FileCheck --check-prefix=CHECK-FFLAGS %s
52+
! CHECK-FFLAGS: "{{.*}}flang1"
53+
! CHECK-FFLAGS-NEXT: "{{.*}}flang2"
54+
! CHECK-FFLAGS-SAME: "-asm" [[LLFILE:.*.ll]]
55+
! CHECK-FFLAGS-NEXT: {{clang.* "-cc1"}}
56+
! CHECK-FFLAGS-SAME: "-relaxed-aliasing"
57+
! CHECK-FFLAGS-SAME: "-funroll-loops"
58+
! CHECK-FFLAGS-SAME: "-x" "ir"
59+
! CHECK-FFLAGS-SAME: [[LLFILE]]
60+
! CHECK-FFLAGS-NEXT: "{{.*}}ld{{(.exe)?}}"
61+
! CHECK-FFLAGS-SAME: "-L{{[^ ]*[/\\]+}}debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10"
62+
4563
! Check that the linker job is given the correct libraries and library paths.
4664

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

0 commit comments

Comments
 (0)