[clang] [llvm] [AArch64] Add support for -mcpu=gb10. (PR #146515)
Ricardo Jesus via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 4 03:28:12 PDT 2025
================
@@ -176,25 +176,43 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) {
SmallVector<StringRef, 32> Lines;
ProcCpuinfoContent.split(Lines, '\n');
- // Look for the CPU implementer line.
+ // Look for the CPU implementer and hardware lines, and store the CPU part
+ // numbers found.
StringRef Implementer;
StringRef Hardware;
- StringRef Part;
+ SmallVector<StringRef, 32> Parts;
for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
if (Lines[I].starts_with("CPU implementer"))
Implementer = Lines[I].substr(15).ltrim("\t :");
if (Lines[I].starts_with("Hardware"))
Hardware = Lines[I].substr(8).ltrim("\t :");
if (Lines[I].starts_with("CPU part"))
- Part = Lines[I].substr(8).ltrim("\t :");
+ Parts.emplace_back(Lines[I].substr(8).ltrim("\t :"));
}
+ // Last `Part' seen, in case we don't analyse all `Parts' parsed.
+ StringRef Part = Parts.empty() ? StringRef() : Parts.back();
+
+ // Remove duplicate `Parts'.
+ llvm::sort(Parts);
+ Parts.erase(llvm::unique(Parts), Parts.end());
+
+ auto MatchBigLittle = [](auto const &Parts, StringRef Big, StringRef Little) {
+ if (Parts.size() == 2)
+ return (Parts[0] == Big && Parts[1] == Little) ||
+ (Parts[1] == Big && Parts[0] == Little);
+ return false;
+ };
+
if (Implementer == "0x41") { // ARM Ltd.
// MSM8992/8994 may give cpu part for the core that the kernel is running on,
// which is undeterministic and wrong. Always return cortex-a53 for these SoC.
if (Hardware.ends_with("MSM8994") || Hardware.ends_with("MSM8996"))
return "cortex-a53";
+ // Detect big.LITTLE systems.
+ if (MatchBigLittle(Parts, "0xd85", "0xd87"))
+ return "gb10";
----------------
rj-jesus wrote:
Indeed, at first I had thought of doing this more automatically as you're suggesting based on the MIDR numbers or the corresponding CPU names, but I wasn't sure that would work reliably for all possible combinations, and so I ended up taking this approach instead. But if you have a better idea I'm happy to follow up with it. :)
https://github.com/llvm/llvm-project/pull/146515
More information about the llvm-commits
mailing list