Skip to content

[TargetParser][AArch64] Believe runtime feature detection #95694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions llvm/lib/TargetParser/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,8 @@ const StringMap<bool> sys::getHostCPUFeatures() {
}

#if defined(__aarch64__)
// Keep track of which crypto features we have seen
// All of these are "crypto" features, but we must sift out actual features
// as the former meaning of "crypto" as a single feature is no more.
enum { CAP_AES = 0x1, CAP_PMULL = 0x2, CAP_SHA1 = 0x4, CAP_SHA2 = 0x8 };
uint32_t crypto = 0;
#endif
Expand Down Expand Up @@ -1941,9 +1942,13 @@ const StringMap<bool> sys::getHostCPUFeatures() {
}

#if defined(__aarch64__)
// If we have all crypto bits we can add the feature
if (crypto == (CAP_AES | CAP_PMULL | CAP_SHA1 | CAP_SHA2))
Features["crypto"] = true;
// LLVM has decided some AArch64 CPUs have all the instructions they _may_
// have, as opposed to all the instructions they _must_ have, so allow runtime
// information to correct us on that.
uint32_t Aes = CAP_AES | CAP_PMULL;
uint32_t Sha2 = CAP_SHA1 | CAP_SHA2;
Features["aes"] = (crypto & Aes) == Aes;
Features["sha2"] = (crypto & Sha2) == Sha2;
#endif

return Features;
Expand All @@ -1952,12 +1957,17 @@ const StringMap<bool> sys::getHostCPUFeatures() {
const StringMap<bool> sys::getHostCPUFeatures() {
StringMap<bool> Features;

if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE))
Features["neon"] = true;
if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE))
Features["crc"] = true;
if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
Features["crypto"] = true;
// If we're asking the OS at runtime, believe what the OS says
Features["neon"] =
IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
Features["crc"] =
IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);

// Avoid inferring "crypto" means more than the traditional AES + SHA2
bool TradCrypto =
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
Features["aes"] = TradCrypto;
Features["sha2"] = TradCrypto;

return Features;
}
Expand Down
Loading