[clang] [Clang][LTO][GISel] Propagate `-fglobal-siel` to LTO (PR #69747)
Min-Yih Hsu via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 24 09:12:19 PDT 2023
https://github.com/mshockwave updated https://github.com/llvm/llvm-project/pull/69747
>From 8abc9204d4148f1b224623ac54d5f58e2ab04e6b Mon Sep 17 00:00:00 2001
From: Min-Yih Hsu <min.hsu at sifive.com>
Date: Fri, 20 Oct 2023 11:03:30 -0700
Subject: [PATCH 1/2] [Clang][LTO][GISel] Propagate `-fglobal-siel` to LTO
Translate `-fglobal-isel` to `-plugin-opt=-global-isel=1`.
---
clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 ++++++++++
clang/test/Driver/lto.c | 9 +++++++++
2 files changed, 19 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7b2966f70bf6fc6..923fac940a00d3c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -694,6 +694,16 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
ParallelismOpt + Parallelism));
+ // Pass down GlobalISel options.
+ if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
+ options::OPT_fno_global_isel)) {
+ // Parsing -fno-global-isel explicitly gives architectures that enable GISel
+ // by default (e.g. AArch64) a chance to disable it.
+ CmdArgs.push_back(Args.MakeArgString(
+ Twine(PluginOptPrefix) + "-global-isel=" +
+ (A->getOption().matches(options::OPT_fglobal_isel) ? "1" : "0")));
+ }
+
// If an explicit debugger tuning argument appeared, pass it along.
if (Arg *A =
Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c
index 62bdbd6f5d3cfa3..b6c89eb99e27419 100644
--- a/clang/test/Driver/lto.c
+++ b/clang/test/Driver/lto.c
@@ -105,3 +105,12 @@
// FLTO-THIN: -flto=thin
// FLTO-THIN-NOT: "-flto"
// FLTO-THIN-NOT: -flto=full
+
+// -flto passes along an explicit GlobalISel flag.
+// RUN: %clang --target=riscv64-linux-gnu -### %s -flto -fglobal-isel 2> %t
+// RUN: FileCheck --check-prefix=CHECK-GISEL < %t %s
+// RUN: %clang --target=aarch64-linux-gnu -### %s -flto -fno-global-isel 2> %t
+// RUN: FileCheck --check-prefix=CHECK-DISABLE-GISEL < %t %s
+//
+// CHECK-GISEL: "-plugin-opt=-global-isel=1"
+// CHECK-DISABLE-GISEL: "-plugin-opt=-global-isel=0"
>From 2c4a02e9536446281901233756b9493d3e01f64f Mon Sep 17 00:00:00 2001
From: Min-Yih Hsu <min.hsu at sifive.com>
Date: Tue, 24 Oct 2023 09:11:43 -0700
Subject: [PATCH 2/2] fixup! [Clang][LTO][GISel] Propagate `-fglobal-siel` to
LTO
---
clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 923fac940a00d3c..6ea89d7726db2d0 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -698,7 +698,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
options::OPT_fno_global_isel)) {
// Parsing -fno-global-isel explicitly gives architectures that enable GISel
- // by default (e.g. AArch64) a chance to disable it.
+ // by default a chance to disable it.
CmdArgs.push_back(Args.MakeArgString(
Twine(PluginOptPrefix) + "-global-isel=" +
(A->getOption().matches(options::OPT_fglobal_isel) ? "1" : "0")));
More information about the cfe-commits
mailing list