[clang] 9271c5d - [Clang] Adjust PIC handling for the AMDGPU ToolChain
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 31 12:31:17 PST 2023
Author: Joseph Huber
Date: 2023-01-31T14:31:10-06:00
New Revision: 9271c5da434b0827ad21f43013be287f3637a9b4
URL: https://github.com/llvm/llvm-project/commit/9271c5da434b0827ad21f43013be287f3637a9b4
DIFF: https://github.com/llvm/llvm-project/commit/9271c5da434b0827ad21f43013be287f3637a9b4.diff
LOG: [Clang] Adjust PIC handling for the AMDGPU ToolChain
The AMDGPU target only emits shared libraries currently. This patch
changes the handling of the PIC level to be managed in the
AMDGPUToolChain rather than having a special case for it. This causes
`--target=amdgcn--` to no longer set the PIC. This should be an
acceptable change since that doesn't use a correct toolchain anyway.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D142999
Added:
Modified:
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/test/Driver/amdgcn-toolchain-pic.cl
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 5849e9cfdb9b5..52021901b9bf8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -611,10 +611,8 @@ AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
if (!DAL)
DAL = new DerivedArgList(Args.getBaseArgs());
- for (Arg *A : Args) {
- if (!shouldSkipArgument(A))
- DAL->append(A);
- }
+ for (Arg *A : Args)
+ DAL->append(A);
checkTargetID(*DAL);
@@ -870,13 +868,6 @@ RocmInstallationDetector::getCommonBitcodeLibs(
return BCLibs;
}
-bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
- Option O = A->getOption();
- if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
- return true;
- return false;
-}
-
llvm::SmallVector<std::string, 12>
ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
const std::string &GPUArch,
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index cce70da6612ba..124a34e852e61 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -64,11 +64,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
bool IsMathErrnoDefault() const override { return false; }
bool isCrossCompiling() const override { return true; }
- bool isPICDefault() const override { return false; }
+ bool isPICDefault() const override { return true; }
bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
return false;
}
- bool isPICDefaultForced() const override { return false; }
+ bool isPICDefaultForced() const override { return true; }
bool SupportsProfiling() const override { return false; }
llvm::opt::DerivedArgList *
@@ -97,9 +97,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
/// Needed for translating LTO options.
const char *getDefaultLinker() const override { return "ld.lld"; }
- /// Should skip argument.
- bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
-
/// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
/// if unable to find one.
virtual Expected<SmallVector<std::string>>
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0883631dfe98f..24e95102f4f3d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1418,10 +1418,6 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
}
}
- // AMDGPU-specific defaults for PIC.
- if (Triple.getArch() == llvm::Triple::amdgcn)
- PIC = true;
-
// The last argument relating to either PIC or PIE wins, and no
// other argument is used. If the last argument is any flavor of the
// '-fno-...' arguments, both PIC and PIE are disabled. Any PIE
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index a555fe5830e04..8c504d8439d67 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -270,8 +270,7 @@ HIPAMDToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
const OptTable &Opts = getDriver().getOpts();
for (Arg *A : Args) {
- if (!shouldSkipArgument(A) &&
- !shouldSkipSanitizeOption(*this, Args, BoundArch, A))
+ if (!shouldSkipSanitizeOption(*this, Args, BoundArch, A))
DAL->append(A);
}
diff --git a/clang/test/Driver/amdgcn-toolchain-pic.cl b/clang/test/Driver/amdgcn-toolchain-pic.cl
index 47adb8815d317..acd5fe413ff71 100644
--- a/clang/test/Driver/amdgcn-toolchain-pic.cl
+++ b/clang/test/Driver/amdgcn-toolchain-pic.cl
@@ -1,7 +1,5 @@
-// RUN: %clang -### --target=amdgcn-- -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// RUN: %clang -### --target=amdgcn-amd- -mcpu=gfx803 %s 2>&1 | FileCheck %s
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx803 %s 2>&1 | FileCheck %s
// RUN: %clang -### --target=amdgcn-amd-amdpal -mcpu=gfx803 %s 2>&1 | FileCheck %s
// RUN: %clang -### --target=amdgcn-amd-mesa3d -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// CHECK: "-cc1"{{.*}} "-mrelocation-model" "pic" "-pic-level" "1"
+// CHECK: "-cc1"{{.*}} "-mrelocation-model" "pic" "-pic-level" "2"
More information about the cfe-commits
mailing list