[PATCH] D142499: [Clang][AMDGPU] Set LTO CG opt level based on Clang option
Scott Linder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 15 09:35:00 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97ba3c2bec48: [Clang][AMDGPU] Set LTO CG opt level based on Clang option (authored by scott.linder).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142499/new/
https://reviews.llvm.org/D142499
Files:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/test/Driver/hip-toolchain-opt.hip
Index: clang/test/Driver/hip-toolchain-opt.hip
===================================================================
--- clang/test/Driver/hip-toolchain-opt.hip
+++ clang/test/Driver/hip-toolchain-opt.hip
@@ -57,6 +57,14 @@
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
// RUN: 2>&1 | FileCheck --check-prefixes=ALL,Og %s
+// RUN: %clang -### -O0 \
+// RUN: -Xoffload-linker --lto-CGO2 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx900 \
+// RUN: -c -nogpulib \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,O0-CGO2 %s
+
// ALL: "-cc1" "-triple" "amdgcn-amd-amdhsa"
// DEFAULT-NOT: "-O{{.}}"
// O0-SAME: "-O0"
@@ -66,6 +74,8 @@
// Os-SAME: "-Os"
// Oz-SAME: "-Oz"
// Og-SAME: "-Og"
+// O0-CGO2-SAME: "-O0"
+// O0-CGO2-NOT: "--lto-CGO2"
// ALL-NOT: "{{.*}}opt"
@@ -74,12 +84,22 @@
// ALL: "{{.*}}lld{{.*}}" {{.*}} "-plugin-opt=mcpu=gfx900"
// DEFAULT-NOT: "-plugin-opt=O{{.*}}"
// O0-SAME: "-plugin-opt=O0"
+// O0-SAME: "--lto-CGO0"
// O1-SAME: "-plugin-opt=O1"
+// O1-SAME: "--lto-CGO1"
// O2-SAME: "-plugin-opt=O2"
+// O2-SAME: "--lto-CGO2"
// O3-SAME: "-plugin-opt=O3"
+// O3-SAME: "--lto-CGO3"
// Os-SAME: "-plugin-opt=O2"
+// Os-SAME: "--lto-CGO2"
// Oz-SAME: "-plugin-opt=O2"
+// Oz-SAME: "--lto-CGO2"
// Og-SAME: "-plugin-opt=O1"
+// Og-SAME: "--lto-CGO1"
+// O0-CGO2-SAME: "-plugin-opt=O0"
+// O0-CGO2-SAME: "--lto-CGO0"
+// O0-CGO2-SAME: "--lto-CGO2"
// ALL: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
// DEFAULT-NOT: "-O{{.}}"
@@ -90,3 +110,5 @@
// Os-SAME: "-Os"
// Oz-SAME: "-Oz"
// Og-SAME: "-Og"
+// O0-CGO2-SAME: "-O0"
+// O0-CGO2-NOT: "--lto-CGO2"
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -152,8 +152,10 @@
addLinkerCompressDebugSectionsOption(TC, Args, LldArgs);
- for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker))
+ for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
LldArgs.push_back(Arg->getValue(1));
+ Arg->claim();
+ }
LldArgs.append({"-o", Output.getFilename()});
for (auto Input : Inputs)
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -567,6 +567,7 @@
ArgStringList &CmdArgs, const InputInfo &Output,
const InputInfo &Input, bool IsThinLTO) {
const bool IsOSAIX = ToolChain.getTriple().isOSAIX();
+ const bool IsAMDGCN = ToolChain.getTriple().isAMDGCN();
const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
const Driver &D = ToolChain.getDriver();
if (llvm::sys::path::filename(Linker) != "ld.lld" &&
@@ -631,9 +632,12 @@
OOpt = "2";
} else if (A->getOption().matches(options::OPT_O0))
OOpt = "0";
- if (!OOpt.empty())
+ if (!OOpt.empty()) {
CmdArgs.push_back(
Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "O" + OOpt));
+ if (IsAMDGCN)
+ CmdArgs.push_back(Args.MakeArgString(Twine("--lto-CGO") + OOpt));
+ }
}
if (Args.hasArg(options::OPT_gsplit_dwarf))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142499.497708.patch
Type: text/x-patch
Size: 3341 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230215/80b32631/attachment.bin>
More information about the cfe-commits
mailing list