[clang] 8013ce4 - [HIP] Add missing options for lto
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 21:27:09 PDT 2020
Author: Yaxun (Sam) Liu
Date: 2020-06-26T00:26:05-04:00
New Revision: 8013ce4490225faf8aae911ee88087ce445e604c
URL: https://github.com/llvm/llvm-project/commit/8013ce4490225faf8aae911ee88087ce445e604c
DIFF: https://github.com/llvm/llvm-project/commit/8013ce4490225faf8aae911ee88087ce445e604c.diff
LOG: [HIP] Add missing options for lto
Add -mcpu, -mattr, -mllvm, and -save-temps options for lto when necessary.
Differential Revision: https://reviews.llvm.org/D82506
Added:
Modified:
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.cpp
clang/test/Driver/hip-link-save-temps.hip
clang/test/Driver/hip-save-temps.hip
clang/test/Driver/hip-toolchain-features.hip
clang/test/Driver/hip-toolchain-mllvm.hip
clang/test/Driver/hip-toolchain-opt.hip
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/test/Driver/hip-toolchain-rdc.hip
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 671a987bf9fc..3b2a85b23375 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -85,6 +85,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
return true;
}
+ /// Needed for translating LTO options.
+ const char *getDefaultLinker() const override { return "ld.lld"; }
};
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp
index f524951ce837..15c44f394466 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -57,14 +57,38 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
const llvm::opt::ArgList &Args) const {
// Construct lld command.
// The output from ld.lld is an HSA code object file.
- ArgStringList LldArgs{"-flavor",
- "gnu",
- "--no-undefined",
- "-shared",
- "-mllvm",
- "-amdgpu-internalize-symbols",
- "-o",
- Output.getFilename()};
+ ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", "-shared",
+ "-plugin-opt=-amdgpu-internalize-symbols"};
+
+ auto &TC = getToolChain();
+ auto &D = TC.getDriver();
+ assert(!Inputs.empty() && "Must have at least one input.");
+ addLTOOptions(TC, Args, LldArgs, Output, Inputs[0],
+ D.getLTOMode() == LTOK_Thin);
+
+ // Extract all the -m options
+ std::vector<llvm::StringRef> Features;
+ amdgpu::getAMDGPUTargetFeatures(D, Args, Features);
+
+ // Add features to mattr such as cumode
+ std::string MAttrString = "-plugin-opt=-mattr=";
+ for (auto OneFeature : unifyTargetFeatures(Features)) {
+ MAttrString.append(Args.MakeArgString(OneFeature));
+ if (OneFeature != Features.back())
+ MAttrString.append(",");
+ }
+ if (!Features.empty())
+ LldArgs.push_back(Args.MakeArgString(MAttrString));
+
+ for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
+ LldArgs.push_back(
+ Args.MakeArgString(Twine("-plugin-opt=") + A->getValue(0)));
+ }
+
+ if (C.getDriver().isSaveTempsEnabled())
+ LldArgs.push_back("-save-temps");
+
+ LldArgs.append({"-o", Output.getFilename()});
for (auto Input : Inputs)
LldArgs.push_back(Input.getFilename());
const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld"));
diff --git a/clang/test/Driver/hip-link-save-temps.hip b/clang/test/Driver/hip-link-save-temps.hip
index d03cf1e5f4a9..60f71d0c5249 100644
--- a/clang/test/Driver/hip-link-save-temps.hip
+++ b/clang/test/Driver/hip-link-save-temps.hip
@@ -41,9 +41,9 @@
// CHECK-NOT: {{".*/llvm-link"}}
// CHECK-NOT: {{".*/opt"}}
// CHECK-NOT: {{".*/llc"}}
-// CHECK: "{{.*lld.*}}" {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// CHECK: "{{.*lld.*}}" {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
// CHECK-SAME: "-o" "a.out-hip-amdgcn-amd-amdhsa-gfx900" "obj1-hip-amdgcn-amd-amdhsa-gfx900.o" "obj2-hip-amdgcn-amd-amdhsa-gfx900.o"
-// CHECK: "{{.*lld.*}}" {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// CHECK: "{{.*lld.*}}" {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
// CHECK-SAME: "-o" "a.out-hip-amdgcn-amd-amdhsa-gfx906" "obj1-hip-amdgcn-amd-amdhsa-gfx906.o" "obj2-hip-amdgcn-amd-amdhsa-gfx906.o"
// CHECK: {{".*llvm-mc.*"}} "-triple" "amdgcn-amd-amdhsa" "-o"
// CHECK-SAME: "[[OBJBUNDLE:.*.o]]" "{{.*}}.mcin" "--filetype=obj"
diff --git a/clang/test/Driver/hip-save-temps.hip b/clang/test/Driver/hip-save-temps.hip
index f326f4155a15..b5d54a8092a9 100644
--- a/clang/test/Driver/hip-save-temps.hip
+++ b/clang/test/Driver/hip-save-temps.hip
@@ -54,7 +54,7 @@
// CHECK-NOT: "{{.*}}opt"
// CHECK-NOT: "{{.*}}llc"
// NORDC: {{.*lld.*}}"-o" "hip-save-temps-hip-amdgcn-amd-amdhsa-gfx900.out"
-// RDCL: "{{.*lld.*}}" {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// RDCL: "{{.*lld.*}}" {{.*}} "-plugin-opt=-amdgpu-internalize-symbols" {{.*}}"-save-temps"
// RDCL-SAME: "-o" "a.out-hip-amdgcn-amd-amdhsa-gfx900"
// RDCC: "{{.*clang.*}}" "-cc1" {{.*}} "-E" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.cui"
// RDCC: "{{.*clang.*}}" "-cc1" {{.*}} "-emit-llvm-bc" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.bc"
diff --git a/clang/test/Driver/hip-toolchain-features.hip b/clang/test/Driver/hip-toolchain-features.hip
index d45a7129f793..c236d2c7102f 100644
--- a/clang/test/Driver/hip-toolchain-features.hip
+++ b/clang/test/Driver/hip-toolchain-features.hip
@@ -2,39 +2,45 @@
// REQUIRES: x86-registered-target
// REQUIRES: amdgpu-registered-target
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -mxnack 2>&1 | FileCheck %s -check-prefix=XNACK
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -mno-xnack 2>&1 | FileCheck %s -check-prefix=NOXNACK
// XNACK: {{.*}}clang{{.*}}"-target-feature" "+xnack"
+// XNACK: {{.*}}lld{{.*}}"-plugin-opt=-mattr=+xnack"
// NOXNACK: {{.*}}clang{{.*}}"-target-feature" "-xnack"
+// NOXNACK: {{.*}}lld{{.*}}"-plugin-opt=-mattr=-xnack"
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -msram-ecc 2>&1 | FileCheck %s -check-prefix=SRAM
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -mno-sram-ecc 2>&1 | FileCheck %s -check-prefix=NOSRAM
// SRAM: {{.*}}clang{{.*}}"-target-feature" "+sram-ecc"
+// SRAM: {{.*}}lld{{.*}}"-plugin-opt=-mattr=+sram-ecc"
// NOSRAM: {{.*}}clang{{.*}}"-target-feature" "-sram-ecc"
+// NOSRAM: {{.*}}lld{{.*}}"-plugin-opt=-mattr=-sram-ecc"
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -mxnack -msram-ecc \
// RUN: 2>&1 | FileCheck %s -check-prefix=ALL3
-// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %s \
// RUN: -mno-xnack -mno-sram-ecc \
// RUN: 2>&1 | FileCheck %s -check-prefix=NOALL3
// ALL3: {{.*}}clang{{.*}}"-target-feature" "+xnack" "-target-feature" "+sram-ecc"
+// ALL3: {{.*}}lld{{.*}}"-plugin-opt=-mattr=+xnack,+sram-ecc"
// NOALL3: {{.*}}clang{{.*}}"-target-feature" "-xnack" "-target-feature" "-sram-ecc"
+// NOALL3: {{.*}}lld{{.*}}"-plugin-opt=-mattr=-xnack,-sram-ecc"
// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -nogpulib \
// RUN: --cuda-gpu-arch=gfx1010 %s \
@@ -45,3 +51,4 @@
// DUP-SAME: "-target-feature" "+wavefrontsize32"
// DUP-SAME: "-target-feature" "-wavefrontsize64"
// DUP-SAME: "-target-feature" "+cumode"
+// DUP: {{.*}}lld{{.*}} "-plugin-opt=-mattr=-wavefrontsize16,+wavefrontsize32,-wavefrontsize64,+cumode"
diff --git a/clang/test/Driver/hip-toolchain-mllvm.hip b/clang/test/Driver/hip-toolchain-mllvm.hip
index 66556d0b726b..5b47e1e0b5d8 100644
--- a/clang/test/Driver/hip-toolchain-mllvm.hip
+++ b/clang/test/Driver/hip-toolchain-mllvm.hip
@@ -7,20 +7,25 @@
// RUN: -mllvm -amdgpu-function-calls=0 \
// RUN: %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: -fgpu-rdc -mllvm -amdgpu-function-calls=0 \
+// RUN: %s 2>&1 | FileCheck -check-prefixes=CHECK,RDC %s
+
// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-emit-obj"
// CHECK-SAME: {{.*}} "-target-cpu" "gfx803"
// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
// CHECK-NOT: {{".*opt"}}
// CHECK-NOT: {{".*llc"}}
+// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
-// CHECK-SAME: "-emit-obj"
// CHECK-SAME: {{.*}} "-target-cpu" "gfx900"
// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
// CHECK-NOT: {{".*opt"}}
// CHECK-NOT: {{".*llc"}}
+// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
diff --git a/clang/test/Driver/hip-toolchain-opt.hip b/clang/test/Driver/hip-toolchain-opt.hip
index 4a470dba3855..d58471aec5f5 100644
--- a/clang/test/Driver/hip-toolchain-opt.hip
+++ b/clang/test/Driver/hip-toolchain-opt.hip
@@ -72,6 +72,16 @@
// ALL-NOT: "{{.*}}llc"
+// ALL: "{{.*}}lld{{.*}}" {{.*}} "-plugin-opt=mcpu=gfx900"
+// DEFAULT-NOT: "-plugin-opt=O{{.*}}"
+// O0-SAME: "-plugin-opt=O0"
+// O1-SAME: "-plugin-opt=O1"
+// O2-SAME: "-plugin-opt=O2"
+// O3-SAME: "-plugin-opt=O3"
+// Os-SAME: "-plugin-opt=O2"
+// Oz-SAME: "-plugin-opt=O2"
+// Og-SAME: "-plugin-opt=O1"
+
// ALL: "{{.*}}clang{{.*}}" "-cc1" "-triple" "x86_64-unknown-linux-gnu"
// DEFAULT-NOT: "-O{{.}}"
// O0-SAME: "-O0"
diff --git a/clang/test/Driver/hip-toolchain-rdc-separate.hip b/clang/test/Driver/hip-toolchain-rdc-separate.hip
index 25fd44f2529b..f65b95c7de77 100644
--- a/clang/test/Driver/hip-toolchain-rdc-separate.hip
+++ b/clang/test/Driver/hip-toolchain-rdc-separate.hip
@@ -107,13 +107,15 @@
// LINK-NOT: "*.llvm-link"
// LINK-NOT: ".*opt"
// LINK-NOT: ".*llc"
-// LINK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
+// LINK: "-plugin-opt=mcpu=gfx803"
// LINK-SAME: "-o" "[[IMG_DEV1:.*.out]]" "[[A_BC1]]" "[[B_BC1]]"
// LINK-NOT: "*.llvm-link"
// LINK-NOT: ".*opt"
// LINK-NOT: ".*llc"
-// LINK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// LINK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
+// LINK: "-plugin-opt=mcpu=gfx900"
// LINK-SAME: "-o" "[[IMG_DEV2:.*.out]]" "[[A_BC2]]" "[[B_BC2]]"
// LINK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip b/clang/test/Driver/hip-toolchain-rdc.hip
index 7148478b4285..045bbf44ae91 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -53,7 +53,8 @@
// CHECK-NOT: "*.llvm-link"
// CHECK-NOT: ".*opt"
// CHECK-NOT: ".*llc"
-// CHECK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// CHECK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
+// CHECK-SAME: "-plugin-opt=mcpu=gfx803"
// CHECK-SAME: "-o" "[[IMG_DEV1:.*.out]]" [[A_BC1]] [[B_BC1]]
// generate image for device side path on gfx900
@@ -80,7 +81,8 @@
// CHECK-NOT: "*.llvm-link"
// CHECK-NOT: ".*opt"
// CHECK-NOT: ".*llc"
-// CHECK: {{".*lld.*"}} {{.*}} "-mllvm" "-amdgpu-internalize-symbols"
+// CHECK: {{".*lld.*"}} {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
+// CHECK-SAME: "-plugin-opt=mcpu=gfx900"
// CHECK-SAME: "-o" "[[IMG_DEV2:.*.out]]" [[A_BC2]] [[B_BC2]]
// combine images generated into hip fat binary object
More information about the cfe-commits
mailing list