Skip to content

Commit 695b630

Browse files
authored
[ThinLTO] NFC: Merge duplicated functions together (#82421)
1 parent e2d80a3 commit 695b630

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

llvm/include/llvm/LTO/LTO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void computeLTOCacheKey(
7575

7676
namespace lto {
7777

78+
StringLiteral getThinLTODefaultCPU(const Triple &TheTriple);
79+
7880
/// Given the original \p Path to an output file, replace any path
7981
/// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
8082
/// resulting directory if it does not yet exist.

llvm/lib/LTO/LTO.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,21 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
15571557
};
15581558
}
15591559

1560+
StringLiteral lto::getThinLTODefaultCPU(const Triple &TheTriple) {
1561+
if (!TheTriple.isOSDarwin())
1562+
return "";
1563+
if (TheTriple.getArch() == Triple::x86_64)
1564+
return "core2";
1565+
if (TheTriple.getArch() == Triple::x86)
1566+
return "yonah";
1567+
if (TheTriple.isArm64e())
1568+
return "apple-a12";
1569+
if (TheTriple.getArch() == Triple::aarch64 ||
1570+
TheTriple.getArch() == Triple::aarch64_32)
1571+
return "cyclone";
1572+
return "";
1573+
}
1574+
15601575
// Given the original \p Path to an output file, replace any path
15611576
// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
15621577
// resulting directory if it does not yet exist.

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,8 @@ bool LTOCodeGenerator::determineTarget() {
409409
SubtargetFeatures Features(join(Config.MAttrs, ""));
410410
Features.getDefaultSubtargetFeatures(Triple);
411411
FeatureStr = Features.getString();
412-
// Set a default CPU for Darwin triples.
413-
if (Config.CPU.empty() && Triple.isOSDarwin()) {
414-
if (Triple.getArch() == llvm::Triple::x86_64)
415-
Config.CPU = "core2";
416-
else if (Triple.getArch() == llvm::Triple::x86)
417-
Config.CPU = "yonah";
418-
else if (Triple.isArm64e())
419-
Config.CPU = "apple-a12";
420-
else if (Triple.getArch() == llvm::Triple::aarch64 ||
421-
Triple.getArch() == llvm::Triple::aarch64_32)
422-
Config.CPU = "cyclone";
423-
}
412+
if (Config.CPU.empty())
413+
Config.CPU = lto::getThinLTODefaultCPU(Triple);
424414

425415
// If data-sections is not explicitly set or unset, set data-sections by
426416
// default to match the behaviour of lld and gold plugin.

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,8 @@ static void resolvePrevailingInIndex(
539539
// Initialize the TargetMachine builder for a given Triple
540540
static void initTMBuilder(TargetMachineBuilder &TMBuilder,
541541
const Triple &TheTriple) {
542-
// Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
543-
// FIXME this looks pretty terrible...
544-
if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
545-
if (TheTriple.getArch() == llvm::Triple::x86_64)
546-
TMBuilder.MCpu = "core2";
547-
else if (TheTriple.getArch() == llvm::Triple::x86)
548-
TMBuilder.MCpu = "yonah";
549-
else if (TheTriple.getArch() == llvm::Triple::aarch64 ||
550-
TheTriple.getArch() == llvm::Triple::aarch64_32)
551-
TMBuilder.MCpu = "cyclone";
552-
}
542+
if (TMBuilder.MCpu.empty())
543+
TMBuilder.MCpu = lto::getThinLTODefaultCPU(TheTriple);
553544
TMBuilder.TheTriple = std::move(TheTriple);
554545
}
555546

0 commit comments

Comments
 (0)