[clang] [Clang][Driver] Add an option to control loop-interchange (PR #125830)
Sjoerd Meijer via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 5 02:12:49 PST 2025
https://github.com/sjoerdmeijer created https://github.com/llvm/llvm-project/pull/125830
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.
>From 24b8e28cfa016ad2b3f494dbf811a2c0da5d7742 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Tue, 4 Feb 2025 03:38:34 -0800
Subject: [PATCH] [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.
---
clang/include/clang/Driver/Options.td | 3 +++
clang/lib/Driver/ToolChains/Clang.cpp | 10 ++++++++++
clang/test/Driver/clang_f_opts.c | 7 +++++++
3 files changed, 20 insertions(+)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index df705104d9ea314..3132f8946c6d3be 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4073,6 +4073,9 @@ defm assumptions : BoolFOption<"assumptions",
"Disable codegen and compile-time checks for C++23's [[assume]] attribute">,
PosFlag<SetTrue>>;
+def floop_interchange : Flag<["-"], "floop-interchange">, Group<f_Group>,
+ HelpText<"Enable the loop interchange pass">;
+def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group<f_Group>;
def fvectorize : Flag<["-"], "fvectorize">, Group<f_Group>,
HelpText<"Enable the loop vectorization passes">;
def fno_vectorize : Flag<["-"], "fno-vectorize">, Group<f_Group>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 33f08cf28feca18..757093c3d3a5cfa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7619,6 +7619,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
options::OPT_fno_gnu_inline_asm);
+ // Handle -floop-interchange
+ if (Arg *A = Args.getLastArg(options::OPT_floop_interchange,
+ options::OPT_fno_loop_interchange)) {
+ CmdArgs.push_back("-mllvm");
+ if (A->getOption().matches(options::OPT_floop_interchange))
+ CmdArgs.push_back("-enable-loopinterchange=true");
+ else
+ CmdArgs.push_back("-enable-loopinterchange=false");
+ }
+
// Enable vectorization per default according to the optimization level
// selected. For optimization levels that want vectorization we use the alias
// option to simplify the hasFlag logic.
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index 38f25898c955682..908d592928b01fc 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -156,6 +156,13 @@
// CHECK-VECTORIZE: "-vectorize-loops"
// CHECK-NO-VECTORIZE-NOT: "-vectorize-loops"
+// RUN: %clang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s
+// RUN: %clang -### -S -fno-loop-interchange -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s
+// RUN: %clang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s
+// RUN: %clang -### -S -floop-interchange -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s
+// CHECK-INTERCHANGE: "-mllvm" "-enable-loopinterchange=true"
+// CHECK-NO-INTERCHANGE: "-mllvm" "-enable-loopinterchange=false"
+
// RUN: %clang -### -S -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s
// RUN: %clang -### -S -fno-slp-vectorize -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s
// RUN: %clang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE %s
More information about the cfe-commits
mailing list