This improves the getHostCPUName check for Apple M1 CPUs, which
previously would always be considered cyclone instead. This also enables
-march=native support when building on M1 CPUs which would previously
fail. This isn't as sophisticated as the X86 CPU feature checking which
consults the CPU via getHostCPUFeatures, but this is still better than
before. This CPU selection could also be invalid if this was run on an
iOS device instead, ideally we can improve those cases as they come up.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Things have moved on since the ARM and (especially) PPC variants of that function were written. That field (despite the name) is now more of an ABI tag and not going to be updated with each CPU.
I think the modern replacement for it is hw.cpufamily obtained from sysctl (command line or man 3 sysctl for programmatically). The potential values (CPUFAMILY_ARM_* starting with Cyclone) are listed in https://opensource.apple.com/source/xnu/xnu-4570.41.2/osfmk/mach/machine.h.auto.html (which should be in the SDK under mach/machine.h). It warns against inferring features from this, which is exactly what we'd be doing, but still probably has a better chance of being right long term.
I'd probably default to the latest known one rather than earliest too, since an unknown family is more likely to be new than old.
Sorry, that was an old xnu version, the newest one is https://opensource.apple.com/source/xnu/xnu-7195.81.3/osfmk/mach/machine.h.auto.html which has
CPUFAMILY_ARM_CYCLONE | 0x37a09642 | apple-a7 |
CPUFAMILY_ARM_TYPHOON | 0x2c91a47e | apple-a8 |
CPUFAMILY_ARM_TWISTER | 0x92fb37c8 | apple-a9 |
CPUFAMILY_ARM_HURRICANE | 0x67ceee93 | apple-a10 |
CPUFAMILY_ARM_MONSOON_MISTRAL | 0xe81e7ef6 | apple-a11 |
CPUFAMILY_ARM_VORTEX_TEMPEST | 0x07d34b9f | apple-a12 |
CPUFAMILY_ARM_LIGHTNING_THUNDER | 0x462504d2 | apple-a13 |
CPUFAMILY_ARM_FIRESTORM_ICESTORM | 0x1b588bb3 | apple-m1 (and apple-a14) |
We'll probably have to hard-code most of those because we need LLVM to be buildable on much older versions of Xcode that don't know about newer CPUs (likely Xcode 9.3 soon, but now older even than that).
Thanks for the tips! I left the default as generic here, but I totally take your point on defaulting to the newest and I'm happy to update if you feel strongly, lmk what you think
llvm/lib/Support/Host.cpp | ||
---|---|---|
1321 | ARM only calls it cyclone, AArch64 allows both but apple-a7 is the canonical name (the comment above the cyclone alias states it's for old bitcode compatibility) | |
1327 | Not sure this should be an assert? I think other implementations will fall back on generic on errors (e.g. the things that read /proc/cpuinfo will use "" on error for the file contents and that gets parsed as generic by the various default cases). Also technically you need to check Length is still sizeof(Family) and not smaller (the other direction is an error), but nobody ever bothers so meh. | |
1335 | Maybe a question for AArch64 maintainers about whether apple-a14 or apple-m1 should be used... they're the same thing from the backend's perspective just with different names. Shame the naming doesn't separate out the "generation" from the specific configuration like you see for other backends (apple-aN is almost that as it omits all the bionic etc marketing name fluff, except apple-m1 comes along and ruins that). |
I agree with Tim, this should default to the newest known one.
generic doesn't really make sense for Darwin anyway, the "oldest" sane default would probably be cyclone, apple-a12, or apple-m1, depending on the slice and OS
llvm/lib/Support/Host.cpp | ||
---|---|---|
1303 | Looks like we have the same includes for computeHostNumPhysicalCores. Maybe move this to the top of the file, gated with just __APPLE__? | |
1335 | Seems fine to stick to the apple-aNN names here. (we already have a similar situation with apple-sN) |
Code review improvements
llvm/lib/Support/Host.cpp | ||
---|---|---|
1321 | I saw this comment: // Support cyclone as an alias for apple-a7 so we can still LTO old bitcode. def : ProcessorModel<"cyclone", CycloneModel, ProcessorFeatures.AppleA7, [TuneAppleA7]>; And thought that implied that the a7 name would be preferred to the "old" name for this case of case, wdyt? | |
1335 | I felt like the m1 name would be preferred here even though they're aliases just because I assume since this is for host CPUs you're more likely to hit this on an m1 machine than something that has an a14, which might lead to some user confusion. For example if you run clang -march=native -### with this change, you see apple-m1 in the invocation, I would personally be surprised if I saw a14 there on my mac, even if they're the same. |
Reading this again, I have a feeling defaulting to newest will come back to bite us (or, well, apple folks.) But we can reevaluate if we get to that. So, LGTM, thanks!
Looks like we have the same includes for computeHostNumPhysicalCores. Maybe move this to the top of the file, gated with just __APPLE__?