Skip to content

Commit 35688ff

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 d30b639 commit 35688ff

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ def hip_Group : OptionGroup<"<HIP group>">, Group<f_Group>,
195195

196196
def m_Group : OptionGroup<"<m group>">, Group<CompileOnly_Group>,
197197
DocName<"Target-dependent compilation options">,
198+
#ifdef ENABLE_CLASSIC_FLANG
199+
Visibility<[ClangOption, CLOption, FlangOption]>;
200+
#else
198201
Visibility<[ClangOption, CLOption]>;
202+
#endif
199203

200204
def hlsl_Group : OptionGroup<"<HLSL group>">, Group<f_Group>,
201205
DocName<"HLSL options">,
@@ -231,10 +235,18 @@ def m_wasm_Features_Group : OptionGroup<"<wasm features group>">,
231235
def m_wasm_Features_Driver_Group : OptionGroup<"<wasm driver features group>">,
232236
Group<m_Group>, DocName<"WebAssembly Driver">;
233237
def m_x86_Features_Group : OptionGroup<"<x86 features group>">,
238+
#ifdef ENABLE_CLASSIC_FLANG
239+
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
240+
#else
234241
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
242+
#endif
235243
DocName<"X86">;
236244
def m_x86_AVX10_Features_Group : OptionGroup<"<x86 AVX10 features group>">,
245+
#ifdef ENABLE_CLASSIC_FLANG
246+
Group<m_Group>, Visibility<[ClangOption, CLOption, FlangOption]>,
247+
#else
237248
Group<m_Group>, Visibility<[ClangOption, CLOption]>,
249+
#endif
238250
DocName<"X86 AVX10">;
239251
def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
240252
Group<m_Group>, DocName<"RISC-V">;
@@ -3516,7 +3528,11 @@ def fno_realloc_lhs : Flag<["-"], "fno-realloc-lhs">, Group<f_Group>,
35163528
def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>,
35173529
HelpText<"Disable the use of stack protectors">;
35183530
def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
3531+
#ifdef ENABLE_CLASSIC_FLANG
3532+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
3533+
#else
35193534
Visibility<[ClangOption, CLOption, DXCOption]>,
3535+
#endif
35203536
HelpText<"Disable optimizations based on strict aliasing rules">;
35213537
def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
35223538
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, 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)