[llvm] [ThinLTO] NFC: Merge duplicated functions together (PR #82421)
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 13:30:34 PST 2024
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/82421
None
>From 6968219a690ea6267ccf35be0cf61d7bdcb736fd Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Tue, 20 Feb 2024 13:29:39 -0800
Subject: [PATCH] [ThinLTO] NFC: Merge duplicated functions together
---
llvm/include/llvm/LTO/LTO.h | 2 ++
llvm/lib/LTO/LTO.cpp | 15 +++++++++++++++
llvm/lib/LTO/LTOCodeGenerator.cpp | 14 ++------------
llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 13 ++-----------
4 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index 1050f24161fb92..94996ae89e35d0 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -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.
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index b5062580169da3..34a49c8588b2f7 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -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.
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 52d8fff14be9ce..19b6f7e7879238 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -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.
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 535faf5f780474..8fd181846f0c4c 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -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);
}
More information about the llvm-commits
mailing list