Skip to content

Commit 9f265c3

Browse files
authored
[flang][driver] add -flang-deprecated-no-hlfir hidden option (#71820)
Patch 1/3 of the transition to use the HLFIR step by default in lowering as described in https://discourse.llvm.org/t/rfc-enabling-the-hlfir-lowering-by-default/72778/7 This option will allow to lower code without the HLFIR step during a grace period as described in the RFC. It is not meant to be a long term switch for flang.
1 parent 7b1a058 commit 9f265c3

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6218,6 +6218,10 @@ def flang_experimental_hlfir : Flag<["-"], "flang-experimental-hlfir">,
62186218
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
62196219
HelpText<"Use HLFIR lowering (experimental)">;
62206220

6221+
def flang_deprecated_no_hlfir : Flag<["-"], "flang-deprecated-no-hlfir">,
6222+
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
6223+
HelpText<"Do not use HLFIR lowering (deprecated)">;
6224+
62216225
def flang_experimental_polymorphism : Flag<["-"], "flang-experimental-polymorphism">,
62226226
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
62236227
HelpText<"Enable Fortran 2003 polymorphism (experimental)">;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
143143
CmdArgs.push_back("-fversion-loops-for-stride");
144144

145145
Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
146+
options::OPT_flang_deprecated_no_hlfir,
146147
options::OPT_flang_experimental_polymorphism,
147148
options::OPT_fno_ppc_native_vec_elem_order,
148149
options::OPT_fppc_native_vec_elem_order,

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,19 @@ bool CompilerInvocation::createFromArgs(
10731073
res.loweringOpts.setLowerToHighLevelFIR(true);
10741074
}
10751075

1076+
// -flang-deprecated-no-hlfir
1077+
if (args.hasArg(clang::driver::options::OPT_flang_deprecated_no_hlfir) &&
1078+
!args.hasArg(clang::driver::options::OPT_emit_hlfir)) {
1079+
if (args.hasArg(clang::driver::options::OPT_flang_experimental_hlfir)) {
1080+
const unsigned diagID = diags.getCustomDiagID(
1081+
clang::DiagnosticsEngine::Error,
1082+
"Options '-flang-experimental-hlfir' and "
1083+
"'-flang-deprecated-no-hlfir' cannot be both specified");
1084+
diags.Report(diagID);
1085+
}
1086+
res.loweringOpts.setLowerToHighLevelFIR(false);
1087+
}
1088+
10761089
if (args.hasArg(clang::driver::options::OPT_flang_experimental_polymorphism)) {
10771090
res.loweringOpts.setPolymorphicTypeImpl(true);
10781091
}

flang/test/Driver/driver-help-hidden.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
! CHECK-NEXT: -fintegrated-as Enable the integrated assembler
5050
! CHECK-NEXT: -fintrinsic-modules-path <dir>
5151
! CHECK-NEXT: Specify where to find the compiled intrinsic modules
52+
! CHECK-NEXT: -flang-deprecated-no-hlfir
53+
! CHECK-NEXT: Do not use HLFIR lowering (deprecated)
5254
! CHECK-NEXT: -flang-experimental-hlfir
5355
! CHECK-NEXT: Use HLFIR lowering (experimental)
5456
! CHECK-NEXT: -flang-experimental-polymorphism

flang/test/Driver/frontend-forwarding.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
! RUN: -fversion-loops-for-stride \
1919
! RUN: -flang-experimental-polymorphism \
2020
! RUN: -flang-experimental-hlfir \
21+
! RUN: -flang-deprecated-no-hlfir \
2122
! RUN: -fno-ppc-native-vector-element-order \
2223
! RUN: -fppc-native-vector-element-order \
2324
! RUN: -mllvm -print-before-all \
@@ -49,6 +50,7 @@
4950
! CHECK: "-fversion-loops-for-stride"
5051
! CHECK: "-flang-experimental-polymorphism"
5152
! CHECK: "-flang-experimental-hlfir"
53+
! CHECK: "-flang-deprecated-no-hlfir"
5254
! CHECK: "-fno-ppc-native-vector-element-order"
5355
! CHECK: "-fppc-native-vector-element-order"
5456
! CHECK: "-Rpass"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! Test that -flang-experimental-hlfir and -flang-deprecated-no-hlfir
2+
! options cannot be both used.
3+
4+
!--------------------------
5+
! FLANG DRIVER (flang-new)
6+
!--------------------------
7+
! RUN: not %flang -flang-experimental-hlfir -flang-deprecated-no-hlfir %s 2>&1 | FileCheck %s
8+
9+
!-----------------------------------------
10+
! FRONTEND FLANG DRIVER (flang-new -fc1)
11+
!-----------------------------------------
12+
! RUN: not %flang_fc1 -emit-llvm -flang-experimental-hlfir -flang-deprecated-no-hlfir %s 2>&1 | FileCheck %s
13+
14+
! CHECK:error: Options '-flang-experimental-hlfir' and '-flang-deprecated-no-hlfir' cannot be both specified
15+
16+
end

flang/test/HLFIR/hlfir-flags.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
! RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
55
! RUN: bbc -emit-hlfir -hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
66
! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR --check-prefix ALL
7+
! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s --check-prefix NO-HLFIR --check-prefix ALL
78
! RUN: bbc -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR --check-prefix ALL
89
! RUN: %flang_fc1 -emit-fir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix FIR --check-prefix ALL %s
910
! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck --check-prefix FIR --check-prefix ALL %s

0 commit comments

Comments
 (0)