Skip to content

Commit 72a4391

Browse files
committed
[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.
1 parent 8fc3294 commit 72a4391

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
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 & 4 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.
@@ -7835,7 +7836,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
78357836
// were suppressed because this is not the device offload action.
78367837
// Check if we are using PS4 in regular LTO mode.
78377838
// Otherwise, issue an error.
7838-
if ((!IsUsingLTO && !D.isUsingLTO(!IsDeviceOffloadAction)) ||
7839+
7840+
auto OtherLTOMode =
7841+
IsDeviceOffloadAction ? D.getLTOMode() : D.getOffloadLTOMode();
7842+
auto OtherIsUsingLTO = OtherLTOMode != LTOK_None;
7843+
7844+
if ((!IsUsingLTO && !OtherIsUsingLTO) ||
78397845
(IsPS4 && !UnifiedLTO && (D.getLTOMode() != LTOK_Full)))
78407846
D.Diag(diag::err_drv_argument_only_allowed_with)
78417847
<< "-fwhole-program-vtables"
@@ -9032,7 +9038,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
90329038
"kind=" + Kind.str(),
90339039
};
90349040

9035-
if (TC->getDriver().isUsingLTO(/* IsOffload */ true) ||
9041+
if (TC->getDriver().isUsingOffloadLTO() ||
90369042
TC->getTriple().isAMDGPU())
90379043
for (StringRef Feature : FeatureArgs)
90389044
Parts.emplace_back("feature=" + Feature.str());

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void CudaToolChain::addClangTargetOptions(
885885
}
886886

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

891891
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
@@ -734,7 +734,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
734734
CmdArgs.push_back("-fcolor-diagnostics");
735735

736736
// LTO mode is parsed by the Clang driver library.
737-
LTOKind LTOMode = D.getLTOMode(/* IsOffload */ false);
737+
LTOKind LTOMode = D.getLTOMode();
738738
assert(LTOMode != LTOK_Unknown && "Unknown LTO mode.");
739739
if (LTOMode == LTOK_Full)
740740
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)