[llvm] 695b630 - [ThinLTO] NFC: Merge duplicated functions together (#82421)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 09:44:05 PST 2024
Author: Jan Svoboda
Date: 2024-02-26T09:44:01-08:00
New Revision: 695b630ae16a1b243d9c72cc275b00cf0c8af2df
URL: https://github.com/llvm/llvm-project/commit/695b630ae16a1b243d9c72cc275b00cf0c8af2df
DIFF: https://github.com/llvm/llvm-project/commit/695b630ae16a1b243d9c72cc275b00cf0c8af2df.diff
LOG: [ThinLTO] NFC: Merge duplicated functions together (#82421)
Added:
Modified:
llvm/include/llvm/LTO/LTO.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Removed:
################################################################################
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