Skip to content

[clang][NFC] Make OffloadLTOMode getter a separate method #101200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 10 additions & 5 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading