[clang] [clang][NFC] Make OffloadLTOMode getter a separate method (PR #101200)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 30 09:24:14 PDT 2024
https://github.com/macurtis-amd updated https://github.com/llvm/llvm-project/pull/101200
>From 8af6a8f1432e952cae094d787170372f585f5a41 Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Tue, 23 Jul 2024 11:59:53 -0500
Subject: [PATCH] [clang][NFC] Make OffloadLTOMode getter a separate method
IMO, improves readability and makes it easier to find the places where we are
getting the offload lto mode.
---
clang/include/clang/Driver/Driver.h | 14 ++++++++------
clang/lib/Driver/Driver.cpp | 5 ++---
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 2 +-
clang/lib/Driver/ToolChains/Clang.cpp | 15 ++++++++++-----
clang/lib/Driver/ToolChains/Cuda.cpp | 2 +-
clang/lib/Driver/ToolChains/Flang.cpp | 2 +-
clang/lib/Driver/ToolChains/HIPAMD.cpp | 2 +-
7 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h
index 04b46782467d6..84eadd42880a5 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -715,14 +715,16 @@ class Driver {
ModuleHeaderMode getModuleHeaderMode() const { return CXX20HeaderType; }
/// Returns true if we are performing any kind of LTO.
- bool isUsingLTO(bool IsOffload = false) const {
- return getLTOMode(IsOffload) != LTOK_None;
- }
+ bool isUsingLTO() const { return getLTOMode() != LTOK_None; }
/// Get the specific kind of LTO being performed.
- LTOKind getLTOMode(bool IsOffload = false) const {
- return IsOffload ? OffloadLTOMode : LTOMode;
- }
+ LTOKind getLTOMode() const { return LTOMode; }
+
+ /// Returns true if we are performing any kind of offload LTO.
+ bool isUsingOffloadLTO() const { return getOffloadLTOMode() != LTOK_None; }
+
+ /// Get the specific kind of offload LTO being performed.
+ LTOKind getOffloadLTOMode() const { return OffloadLTOMode; }
private:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8e44d5afa40e0..8a5f83edfe081 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3492,7 +3492,7 @@ class OffloadingActionBuilder final {
// a fat binary containing all the code objects for different GPU's.
// The fat binary is then an input to the host action.
for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
- if (C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
+ if (C.getDriver().isUsingOffloadLTO()) {
// When LTO is enabled, skip the backend and assemble phases and
// use lld to link the bitcode.
ActionList AL;
@@ -4856,8 +4856,7 @@ Action *Driver::ConstructPhaseAction(
Output = types::TY_LTO_BC;
return C.MakeAction<BackendJobAction>(Input, Output);
}
- if (isUsingLTO(/* IsOffload */ true) &&
- TargetDeviceOffloadKind != Action::OFK_None) {
+ if (isUsingOffloadLTO() && TargetDeviceOffloadKind != Action::OFK_None) {
types::ID Output =
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
return C.MakeAction<BackendJobAction>(Input, Output);
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b75d400e6ce91..d43e683e46852 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -57,7 +57,7 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
}
// Link the bitcode library late if we're using device LTO.
- if (getDriver().isUsingLTO(/* IsOffload */ true))
+ if (getDriver().isUsingOffloadLTO())
return;
}
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc59..0c4712ff6f9e2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4959,8 +4959,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool IsRDCMode =
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
- bool IsUsingLTO = D.isUsingLTO(IsDeviceOffloadAction);
- auto LTOMode = D.getLTOMode(IsDeviceOffloadAction);
+
+ auto LTOMode = IsDeviceOffloadAction ? D.getOffloadLTOMode() : D.getLTOMode();
+ bool IsUsingLTO = LTOMode != LTOK_None;
// Extract API doesn't have a main input file, so invent a fake one as a
// placeholder.
@@ -7835,7 +7836,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// were suppressed because this is not the device offload action.
// Check if we are using PS4 in regular LTO mode.
// Otherwise, issue an error.
- if ((!IsUsingLTO && !D.isUsingLTO(!IsDeviceOffloadAction)) ||
+
+ auto OtherLTOMode =
+ IsDeviceOffloadAction ? D.getLTOMode() : D.getOffloadLTOMode();
+ auto OtherIsUsingLTO = OtherLTOMode != LTOK_None;
+
+ if ((!IsUsingLTO && !OtherIsUsingLTO) ||
(IsPS4 && !UnifiedLTO && (D.getLTOMode() != LTOK_Full)))
D.Diag(diag::err_drv_argument_only_allowed_with)
<< "-fwhole-program-vtables"
@@ -9032,8 +9038,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
"kind=" + Kind.str(),
};
- if (TC->getDriver().isUsingLTO(/* IsOffload */ true) ||
- TC->getTriple().isAMDGPU())
+ if (TC->getDriver().isUsingOffloadLTO() || TC->getTriple().isAMDGPU())
for (StringRef Feature : FeatureArgs)
Parts.emplace_back("feature=" + Feature.str());
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index e98e574d6cc2b..c01269a65d969 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -885,7 +885,7 @@ void CudaToolChain::addClangTargetOptions(
}
// Link the bitcode library late if we're using device LTO.
- if (getDriver().isUsingLTO(/* IsOffload */ true))
+ if (getDriver().isUsingOffloadLTO())
return;
addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index f5de5eb23e4be..17d9aa932f310 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -734,7 +734,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fcolor-diagnostics");
// LTO mode is parsed by the Clang driver library.
- LTOKind LTOMode = D.getLTOMode(/* IsOffload */ false);
+ LTOKind LTOMode = D.getLTOMode();
assert(LTOMode != LTOK_Unknown && "Unknown LTO mode.");
if (LTOMode == LTOK_Full)
CmdArgs.push_back("-flto=full");
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index c35b0febb262d..cbb8fab69a316 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -120,7 +120,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
auto &TC = getToolChain();
auto &D = TC.getDriver();
assert(!Inputs.empty() && "Must have at least one input.");
- bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
+ bool IsThinLTO = D.getOffloadLTOMode() == LTOK_Thin;
addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
// Extract all the -m options
More information about the cfe-commits
mailing list