https://github.com/weiweichen created 
https://github.com/llvm/llvm-project/pull/96832

We noticed that `TargetInfo::CreateTargetInfo` is giving up back empty 
`opt->featureMap` for AArch64, which is probably related to [this 
change](https://github.com/llvm/llvm-project/commit/a03d06a736fd8921c8f40637667d6af9c2c76505#diff-2ccae12096c75c4b8422ea0d2fdf6b195896d2554d62cce604e8fcb56a78ef62L1067).
 

Trying to bring the info back (if possible).

>From 37e0ff835b7ade8def6e141ae7a55d55380f887e Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.c...@modular.com>
Date: Wed, 26 Jun 2024 19:28:58 -0400
Subject: [PATCH] Bring initFeatureMap back to AArch64TargetInfo.

---
 clang/lib/Basic/Targets/AArch64.cpp | 18 ++++++++++++++++++
 clang/lib/Basic/Targets/AArch64.h   |  5 +++++
 2 files changed, 23 insertions(+)

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;
   }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to