Skip to content

Commit 24b8e28

Browse files
committed
[Clang][Driver] Add an option to control loop-interchange
This introduces options -floop-interchange and -fno-loop-interchange to enable/disable the loop-interchange pass. This is part of the work that tries to get that pass enabled by default (#124911), where it was remarked that a user facing option to control this would be convenient to have. The option (name) is the same as GCC's.
1 parent cb714e7 commit 24b8e28

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

clang/include/clang/Driver/Options.td

+3
Original file line numberDiff line numberDiff line change
@@ -4073,6 +4073,9 @@ defm assumptions : BoolFOption<"assumptions",
40734073
"Disable codegen and compile-time checks for C++23's [[assume]] attribute">,
40744074
PosFlag<SetTrue>>;
40754075

4076+
def floop_interchange : Flag<["-"], "floop-interchange">, Group<f_Group>,
4077+
HelpText<"Enable the loop interchange pass">;
4078+
def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group<f_Group>;
40764079
def fvectorize : Flag<["-"], "fvectorize">, Group<f_Group>,
40774080
HelpText<"Enable the loop vectorization passes">;
40784081
def fno_vectorize : Flag<["-"], "fno-vectorize">, Group<f_Group>;

clang/lib/Driver/ToolChains/Clang.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -7619,6 +7619,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
76197619
Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
76207620
options::OPT_fno_gnu_inline_asm);
76217621

7622+
// Handle -floop-interchange
7623+
if (Arg *A = Args.getLastArg(options::OPT_floop_interchange,
7624+
options::OPT_fno_loop_interchange)) {
7625+
CmdArgs.push_back("-mllvm");
7626+
if (A->getOption().matches(options::OPT_floop_interchange))
7627+
CmdArgs.push_back("-enable-loopinterchange=true");
7628+
else
7629+
CmdArgs.push_back("-enable-loopinterchange=false");
7630+
}
7631+
76227632
// Enable vectorization per default according to the optimization level
76237633
// selected. For optimization levels that want vectorization we use the alias
76247634
// option to simplify the hasFlag logic.

clang/test/Driver/clang_f_opts.c

+7
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@
156156
// CHECK-VECTORIZE: "-vectorize-loops"
157157
// CHECK-NO-VECTORIZE-NOT: "-vectorize-loops"
158158

159+
// RUN: %clang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s
160+
// RUN: %clang -### -S -fno-loop-interchange -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s
161+
// RUN: %clang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s
162+
// RUN: %clang -### -S -floop-interchange -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s
163+
// CHECK-INTERCHANGE: "-mllvm" "-enable-loopinterchange=true"
164+
// CHECK-NO-INTERCHANGE: "-mllvm" "-enable-loopinterchange=false"
165+
159166
// RUN: %clang -### -S -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s
160167
// RUN: %clang -### -S -fno-slp-vectorize -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s
161168
// RUN: %clang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE %s

0 commit comments

Comments
 (0)