Skip to content

Commit 13dd795

Browse files
authored
[clang][NFC] Make OffloadLTOMode getter a separate method (#101200)
Minor readability improvement (IMHO). Also makes it easier to find the places where we are getting the offload lto mode.
1 parent 212950f commit 13dd795

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,16 @@ class Driver {
715715
ModuleHeaderMode getModuleHeaderMode() const { return CXX20HeaderType; }
716716

717717
/// Returns true if we are performing any kind of LTO.
718-
bool isUsingLTO(bool IsOffload = false) const {
719-
return getLTOMode(IsOffload) != LTOK_None;
720-
}
718+
bool isUsingLTO() const { return getLTOMode() != LTOK_None; }
721719

722720
/// Get the specific kind of LTO being performed.
723-
LTOKind getLTOMode(bool IsOffload = false) const {
724-
return IsOffload ? OffloadLTOMode : LTOMode;
725-
}
721+
LTOKind getLTOMode() const { return LTOMode; }
722+
723+
/// Returns true if we are performing any kind of offload LTO.
724+
bool isUsingOffloadLTO() const { return getOffloadLTOMode() != LTOK_None; }
725+
726+
/// Get the specific kind of offload LTO being performed.
727+
LTOKind getOffloadLTOMode() const { return OffloadLTOMode; }
726728

727729
private:
728730

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ class OffloadingActionBuilder final {
34923492
// a fat binary containing all the code objects for different GPU's.
34933493
// The fat binary is then an input to the host action.
34943494
for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
3495-
if (C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
3495+
if (C.getDriver().isUsingOffloadLTO()) {
34963496
// When LTO is enabled, skip the backend and assemble phases and
34973497
// use lld to link the bitcode.
34983498
ActionList AL;
@@ -4856,8 +4856,7 @@ Action *Driver::ConstructPhaseAction(
48564856
Output = types::TY_LTO_BC;
48574857
return C.MakeAction<BackendJobAction>(Input, Output);
48584858
}
4859-
if (isUsingLTO(/* IsOffload */ true) &&
4860-
TargetDeviceOffloadKind != Action::OFK_None) {
4859+
if (isUsingOffloadLTO() && TargetDeviceOffloadKind != Action::OFK_None) {
48614860
types::ID Output =
48624861
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
48634862
return C.MakeAction<BackendJobAction>(Input, Output);

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
5757
}
5858

5959
// Link the bitcode library late if we're using device LTO.
60-
if (getDriver().isUsingLTO(/* IsOffload */ true))
60+
if (getDriver().isUsingOffloadLTO())
6161
return;
6262
}
6363

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4959,8 +4959,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49594959

49604960
bool IsRDCMode =
49614961
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
4962-
bool IsUsingLTO = D.isUsingLTO(IsDeviceOffloadAction);
4963-
auto LTOMode = D.getLTOMode(IsDeviceOffloadAction);
4962+
4963+
auto LTOMode = IsDeviceOffloadAction ? D.getOffloadLTOMode() : D.getLTOMode();
4964+
bool IsUsingLTO = LTOMode != LTOK_None;
49644965

49654966
// Extract API doesn't have a main input file, so invent a fake one as a
49664967
// placeholder.
@@ -7825,7 +7826,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
78257826
// were suppressed because this is not the device offload action.
78267827
// Check if we are using PS4 in regular LTO mode.
78277828
// Otherwise, issue an error.
7828-
if ((!IsUsingLTO && !D.isUsingLTO(!IsDeviceOffloadAction)) ||
7829+
7830+
auto OtherLTOMode =
7831+
IsDeviceOffloadAction ? D.getLTOMode() : D.getOffloadLTOMode();
7832+
auto OtherIsUsingLTO = OtherLTOMode != LTOK_None;
7833+
7834+
if ((!IsUsingLTO && !OtherIsUsingLTO) ||
78297835
(IsPS4 && !UnifiedLTO && (D.getLTOMode() != LTOK_Full)))
78307836
D.Diag(diag::err_drv_argument_only_allowed_with)
78317837
<< "-fwhole-program-vtables"
@@ -9022,8 +9028,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
90229028
"kind=" + Kind.str(),
90239029
};
90249030

9025-
if (TC->getDriver().isUsingLTO(/* IsOffload */ true) ||
9026-
TC->getTriple().isAMDGPU())
9031+
if (TC->getDriver().isUsingOffloadLTO() || TC->getTriple().isAMDGPU())
90279032
for (StringRef Feature : FeatureArgs)
90289033
Parts.emplace_back("feature=" + Feature.str());
90299034

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ void CudaToolChain::addClangTargetOptions(
887887
}
888888

889889
// Link the bitcode library late if we're using device LTO.
890-
if (getDriver().isUsingLTO(/* IsOffload */ true))
890+
if (getDriver().isUsingOffloadLTO())
891891
return;
892892

893893
addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, GpuArch.str(),

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
736736
CmdArgs.push_back("-fcolor-diagnostics");
737737

738738
// LTO mode is parsed by the Clang driver library.
739-
LTOKind LTOMode = D.getLTOMode(/* IsOffload */ false);
739+
LTOKind LTOMode = D.getLTOMode();
740740
assert(LTOMode != LTOK_Unknown && "Unknown LTO mode.");
741741
if (LTOMode == LTOK_Full)
742742
CmdArgs.push_back("-flto=full");

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
120120
auto &TC = getToolChain();
121121
auto &D = TC.getDriver();
122122
assert(!Inputs.empty() && "Must have at least one input.");
123-
bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
123+
bool IsThinLTO = D.getOffloadLTOMode() == LTOK_Thin;
124124
addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
125125

126126
// Extract all the -m options

0 commit comments

Comments
 (0)