Skip to content

[ThinLTO] NFC: Merge duplicated functions together #82421

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
Feb 26, 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
2 changes: 2 additions & 0 deletions llvm/include/llvm/LTO/LTO.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void computeLTOCacheKey(

namespace lto {

StringLiteral getThinLTODefaultCPU(const Triple &TheTriple);

/// Given the original \p Path to an output file, replace any path
/// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
/// resulting directory if it does not yet exist.
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,21 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
};
}

StringLiteral lto::getThinLTODefaultCPU(const Triple &TheTriple) {
if (!TheTriple.isOSDarwin())
return "";
if (TheTriple.getArch() == Triple::x86_64)
return "core2";
if (TheTriple.getArch() == Triple::x86)
return "yonah";
if (TheTriple.isArm64e())
return "apple-a12";
if (TheTriple.getArch() == Triple::aarch64 ||
TheTriple.getArch() == Triple::aarch64_32)
return "cyclone";
return "";
}

// Given the original \p Path to an output file, replace any path
// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
// resulting directory if it does not yet exist.
Expand Down
14 changes: 2 additions & 12 deletions llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,8 @@ bool LTOCodeGenerator::determineTarget() {
SubtargetFeatures Features(join(Config.MAttrs, ""));
Features.getDefaultSubtargetFeatures(Triple);
FeatureStr = Features.getString();
// Set a default CPU for Darwin triples.
if (Config.CPU.empty() && Triple.isOSDarwin()) {
if (Triple.getArch() == llvm::Triple::x86_64)
Config.CPU = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
Config.CPU = "yonah";
else if (Triple.isArm64e())
Config.CPU = "apple-a12";
else if (Triple.getArch() == llvm::Triple::aarch64 ||
Triple.getArch() == llvm::Triple::aarch64_32)
Config.CPU = "cyclone";
}
if (Config.CPU.empty())
Config.CPU = lto::getThinLTODefaultCPU(Triple);

// If data-sections is not explicitly set or unset, set data-sections by
// default to match the behaviour of lld and gold plugin.
Expand Down
13 changes: 2 additions & 11 deletions llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,8 @@ static void resolvePrevailingInIndex(
// Initialize the TargetMachine builder for a given Triple
static void initTMBuilder(TargetMachineBuilder &TMBuilder,
const Triple &TheTriple) {
// Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
// FIXME this looks pretty terrible...
if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
if (TheTriple.getArch() == llvm::Triple::x86_64)
TMBuilder.MCpu = "core2";
else if (TheTriple.getArch() == llvm::Triple::x86)
TMBuilder.MCpu = "yonah";
else if (TheTriple.getArch() == llvm::Triple::aarch64 ||
TheTriple.getArch() == llvm::Triple::aarch64_32)
TMBuilder.MCpu = "cyclone";
}
if (TMBuilder.MCpu.empty())
TMBuilder.MCpu = lto::getThinLTODefaultCPU(TheTriple);
TMBuilder.TheTriple = std::move(TheTriple);
}

Expand Down