[llvm] [ThinLTO] NFC: Merge duplicated functions together (PR #82421)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 13:31:04 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Jan Svoboda (jansvoboda11)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/82421.diff
4 Files Affected:
- (modified) llvm/include/llvm/LTO/LTO.h (+2)
- (modified) llvm/lib/LTO/LTO.cpp (+15)
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+2-12)
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+2-11)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/82421
More information about the llvm-commits
mailing list