-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang][AArch64] Add getHostCPUFeatures to query for enabled features in cpu info #97749
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
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: None (neildhickey) Changes…info This pull request adds code to call getHostCPUInfo into the AArch64 Target Parser to query the cpuinfo for the device in the case where we are compiling with -mcpu=native Full diff: https://github.com/llvm/llvm-project/pull/97749.diff 1 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index ec248b80251ea3..2862c297622fa9 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -445,4 +445,21 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
Features.push_back("+no-bti-at-return-twice");
+
+ // Parse AArch64 CPU Features
+ const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
+ StringRef CPUName;
+
+ if (CPUArg) {
+ CPUName = CPUArg->getValue();
+ if (CPUName == "native") {
+ llvm::StringMap<bool> HostFeatures;
+ if (llvm::sys::getHostCPUFeatures(HostFeatures)) {
+ for (auto &F : HostFeatures) {
+ Features.push_back(
+ Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+ }
+ }
+ }
+ }
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Args.MakeArgString((F.second ? "+" : "-") + F.first())); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use early return here. Logically stating
if (!CPUArg)
return;
if (CPUName != "native")
return;
if (!llvm::sys::getHostCPUFeatures(HostFeatures))
return;
and then iterate over HostFeatures
. I think it will be cleaner.
Hi this sounds like a good idea to me. Note that the implementation of getHostCPUFeatures isn't amazing for AArch64 at the moment, there was an attempt to fix it up in #95694 (but thaat has gone a bit quiet). One point we noticed is that it could end up turning "aes+sha2" into "crypto" and "crypto" back into "sha2+aes+sha3+sm4", as it uses the old meaning of "crypto" |
Thanks for the review comments @madhur13490 and @davemgreen I plan to improve getHostCPUFeatures for AArach64 as well, this is just the first phase to add the function call. |
Looks ok to me, X86 and ARM already do this.
Then this needs to be fixed before this PR can go in, we don't want to be making binaries folks can't run. @davemgreen do we have a way that @neildhickey can reproduce that easily? |
for (auto &F : HostFeatures) { | ||
Features.push_back( | ||
Args.MakeArgString((F.second ? "+" : "-") + F.first())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (auto &F : HostFeatures) { | |
Features.push_back( | |
Args.MakeArgString((F.second ? "+" : "-") + F.first())); | |
} | |
for (auto &[Name, Enabled] : HostFeatures) | |
Features.push_back( | |
Args.MakeArgString((Enabled ? "+" : "-") + Name)); |
@@ -445,4 +445,21 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, | |||
|
|||
if (Args.getLastArg(options::OPT_mno_bti_at_return_twice)) | |||
Features.push_back("+no-bti-at-return-twice"); | |||
|
|||
// Parse AArch64 CPU Features | |||
const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like this should be done in getAArch64ArchFeaturesFromMcpu
/DecodeAArch64Mcpu
c942cb2
to
64e7d3e
Compare
Perhaps this is the part of code causing the issue
If so I can change this to remove the addition of crypto and just assert the features found in the cpuinfo file |
It is that bit of code, yeah. I don't know of a way to reproduce this without logging into different machines with different sets of options and trying it. If we had a way to test/mock that various /proc/cpuinfo files gave us the correct results, that would be helpful in giving us more confidence it was working as intended. |
db66fb7
to
9f1a5b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests. They look like a useful addition.
9f1a5b6
to
faceffd
Compare
Sorry for the delays in response. I addressed the comments and rebased the branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - LGTM
Add LLVM_CPUINFO environment variable to test mock /proc/cpuinfo files for -mcpu=native
faceffd
to
50d917f
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/7513 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/8413 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/11290 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/10880 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/13027 Here is the relevant piece of the build log for the reference
|
…features in cpu info (llvm#97749)" This reverts commit d732c0b.
#114066) …features in cpu info (#97749)" This reverts commit d732c0b. This is breaking buildbots https://lab.llvm.org/buildbot/#/builders/190/builds/8413, https://lab.llvm.org/buildbot/#/builders/56/builds/10880 and a few others.
… in cpu info (llvm#97749) Add getHostCPUFeatures into the AArch64 Target Parser to query the cpuinfo for the device in the case where we are compiling with -mcpu=native. Add LLVM_CPUINFO environment variable to test mock /proc/cpuinfo files for -mcpu=native Co-authored-by: Elvina Yakubova <[email protected]>
llvm#114066) …features in cpu info (llvm#97749)" This reverts commit d732c0b. This is breaking buildbots https://lab.llvm.org/buildbot/#/builders/190/builds/8413, https://lab.llvm.org/buildbot/#/builders/56/builds/10880 and a few others.
This pull request adds code to call getHostCPUInfo into the AArch64 Target Parser to query the cpuinfo for the device in the case where we are compiling with -mcpu=native