[clang] [Clang] Bring initFeatureMap back to AArch64TargetInfo. (PR #96832)

weiwei chen via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 16:38:37 PDT 2024


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

>From 37e0ff835b7ade8def6e141ae7a55d55380f887e Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.chen at modular.com>
Date: Wed, 26 Jun 2024 19:28:58 -0400
Subject: [PATCH 1/2] 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;
   }

>From e04415cd904a754fe921c8fe6e71c6044ca9bdaa Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.chen at modular.com>
Date: Wed, 26 Jun 2024 19:38:18 -0400
Subject: [PATCH 2/2] Fix format.

---
 clang/lib/Basic/Targets/AArch64.cpp | 26 +++++++++++++-------------
 clang/lib/Basic/Targets/AArch64.h   |  4 ++--
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index efc5c7e6e931a..e1f7a5913ead4 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1173,19 +1173,19 @@ ParsedTargetAttr AArch64TargetInfo::parseTargetAttr(StringRef Features) const {
 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);
+  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 {
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 1af80db0de05c..eb8b6430ebc8e 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -109,8 +109,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
 
   bool
   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
-                  StringRef CPU,
-                  const std::vector<std::string> &FeaturesVec) const override;
+                 StringRef CPU,
+                 const std::vector<std::string> &FeaturesVec) const override;
 
   bool useFP16ConversionIntrinsics() const override {
     return false;



More information about the cfe-commits mailing list