-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Clang] Bring initFeatureMap back to AArch64TargetInfo. #96832
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-aarch64 Author: weiwei chen (weiweichen) ChangesWe noticed that Trying to bring the info back (if possible). Full diff: https://github.com/llvm/llvm-project/pull/96832.diff 2 Files Affected:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 2692ddec26ff4..efc5c7e6e931a 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1170,6 +1170,24 @@ ParsedTargetAttr AArch64TargetInfo::parseTargetAttr(StringRef Features) const {
return Ret;
}
+bool AArch64TargetInfo::initFeatureMap(
+ llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
+ const std::vector<std::string> &FeaturesVec) const {
+ std::vector<std::string> UpdatedFeaturesVec;
+ // Parse the CPU and add any implied features.
+ std::optional<llvm::AArch64::CpuInfo> CpuInfo = llvm::AArch64::parseCpu(CPU);
+ if (CpuInfo) {
+ auto Exts = CpuInfo->getImpliedExtensions();
+ std::vector<StringRef> CPUFeats;
+ llvm::AArch64::getExtensionFeatures(Exts, CPUFeats);
+ for (auto F : CPUFeats) {
+ assert((F[0] == '+' || F[0] == '-') && "Expected +/- in target feature!");
+ UpdatedFeaturesVec.push_back(F.str());
+ }
+ }
+ return TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec);
+}
+
bool AArch64TargetInfo::hasBFloat16Type() const {
return true;
}
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 71510fe289510..1af80db0de05c 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -107,6 +107,11 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
unsigned multiVersionSortPriority(StringRef Name) const override;
unsigned multiVersionFeatureCost() const override;
+ bool
+ initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
+ StringRef CPU,
+ const std::vector<std::string> &FeaturesVec) const override;
+
bool useFP16ConversionIntrinsics() const override {
return false;
}
|
6f266f1
to
e04415c
Compare
Not sure if this is the right fix, so any clang experts here, please take a look to see if this is acceptable? |
@labrinea please take a look. The PR mentioned above removed this code and broke AArch64 feature detection for us. |
Could you explain more about what broke? Are you using target(..) attributes? |
And please add a test to cover whatever broke. |
|
The only thing What inputs are you giving when you create the |
We are using
Is this still possible to get for AArch64? Is there a different API we can use instead? |
I think a test demonstrating the problem would be the fastest way forward. |
Here is a self contained simple repro test cpp file:
CMakeLists.txt
To build the test (given that LLVM and Clang can be found correctly):
Before this change, we get (non empty features):
With current top of upstream, we get (empty features):
And the same test can be run an x86 machine, and we get (non empty features with top of upstream):
This looks like the upstream change, while working good for Clang internally, it has broken the public clang API As a downstream consumer of upstream, we are broken due to the change. However, we are able to workaround it by adding a wrapper to pull the old logic back for AArch64 backend on our side, but it probably would be much better if upstream can be fixed for Please let me know if I can provide more info on reproduce the issue. |
Thank you for the example, I understand what is happening how.
This bit of code used to crudely add the CPU features to the end of the feature list. However there are some problems with that approach, which we attempted to rectify in #94279:
For example, if you wrote: There doesn't seem to be a way to specify an architecture in So the way that we set up the AArch64 backend in #94279 is to require you to calculate your feature set up front, which are then trivially passed through by the default I'm not sure there is a clear answer on this one. I can't see a way to easily let If you wanted to go the route of building the feature list before calling I'm open to other suggestions too. |
Oh, thank you so much for the explanation and suggestions on the APIs to try! We'll play with the APIs to see if we can get a cleaner workaround on our side. On the other hand, as for the clang API's perspective, maybe it's ok that different backends have different behavior in terms how they retrieve target features or is there room to improve for consistency as well? |
We noticed that
TargetInfo::CreateTargetInfo
is giving up back emptyopt->featureMap
for AArch64, which is probably related to this change.Trying to bring the info back (if possible).