[clang] [llvm] [Hexagon] Add V79 support to compiler and assembler (PR #120983)

2025-01-07 Thread Alexey Karyakin via cfe-commits

quic-akaryaki wrote:

This change misses new HVX instructions in HexagonDepInstrInfo.td, like:
V6_get_qfext
V6_get_qfext_oracc
V6_set_qfext,
(about 20 in total).

https://github.com/llvm/llvm-project/pull/120983
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] NFC: Reduce the amount of version-specific code (PR #145812)

2025-06-25 Thread Alexey Karyakin via cfe-commits

https://github.com/quic-akaryaki updated 
https://github.com/llvm/llvm-project/pull/145812

>From a84ed78481f37843143b5622a1351d7d8a3c3045 Mon Sep 17 00:00:00 2001
From: Alexey Karyakin 
Date: Mon, 19 May 2025 12:16:36 -0700
Subject: [PATCH] [Hexagon] NFC: Reduce the amount of version-specific code

There is a lot of redundant code that needs to be modified when new
Hexagon versions are added. Reduce the amount of this redundancy.

- compute ELF flags and attributes based on version feature names;
- simplify EnableHVX option handling by using arch features instead of
  arch version enums;
- simplify completeHVXFeatures() by using features;
- delete several unused or redundant functions and constants:
  isCPUValid, getCpu, getHexagonCPUSuffix;
- do not set HexagonArchVersion in initializeSubtargetDependencies,
  it is set in ParseSubtargetFeatures;

Signed-off-by: Alexey Karyakin 
---
 clang/lib/Basic/Targets/Hexagon.cpp   |  41 +--
 clang/lib/Basic/Targets/Hexagon.h |   5 +-
 llvm/lib/Target/Hexagon/HexagonDepArch.h  |  20 --
 llvm/lib/Target/Hexagon/HexagonSubtarget.cpp  |   8 +-
 .../MCTargetDesc/HexagonMCELFStreamer.cpp |   7 +-
 .../MCTargetDesc/HexagonMCTargetDesc.cpp  | 312 --
 .../MCTargetDesc/HexagonMCTargetDesc.h|   7 +-
 7 files changed, 169 insertions(+), 231 deletions(-)

diff --git a/clang/lib/Basic/Targets/Hexagon.cpp 
b/clang/lib/Basic/Targets/Hexagon.cpp
index 06dcac03baa5b..9fff20bf0f417 100644
--- a/clang/lib/Basic/Targets/Hexagon.cpp
+++ b/clang/lib/Basic/Targets/Hexagon.cpp
@@ -18,6 +18,19 @@
 using namespace clang;
 using namespace clang::targets;
 
+namespace {
+
+constexpr llvm::StringLiteral CpuValsTextArray[] = {
+"hexagonv5",  "hexagonv55",  "hexagonv60",  "hexagonv62", "hexagonv65",
+"hexagonv66", "hexagonv67",  "hexagonv67t", "hexagonv68", "hexagonv69",
+"hexagonv71", "hexagonv71t", "hexagonv73",  "hexagonv75", "hexagonv79",
+};
+
+} // namespace
+
+const llvm::ArrayRef
+HexagonTargetInfo::CpuValsText(CpuValsTextArray);
+
 void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   Builder.defineMacro("__qdsp6__", "1");
@@ -239,22 +252,6 @@ bool HexagonTargetInfo::hasFeature(StringRef Feature) 
const {
   .Default(false);
 }
 
-struct CPUSuffix {
-  llvm::StringLiteral Name;
-  llvm::StringLiteral Suffix;
-};
-
-static constexpr CPUSuffix Suffixes[] = {
-{{"hexagonv5"}, {"5"}},   {{"hexagonv55"}, {"55"}},
-{{"hexagonv60"}, {"60"}}, {{"hexagonv62"}, {"62"}},
-{{"hexagonv65"}, {"65"}}, {{"hexagonv66"}, {"66"}},
-{{"hexagonv67"}, {"67"}}, {{"hexagonv67t"}, {"67t"}},
-{{"hexagonv68"}, {"68"}}, {{"hexagonv69"}, {"69"}},
-{{"hexagonv71"}, {"71"}}, {{"hexagonv71t"}, {"71t"}},
-{{"hexagonv73"}, {"73"}}, {{"hexagonv75"}, {"75"}},
-{{"hexagonv79"}, {"79"}},
-};
-
 std::optional HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
   StringRef Arch = Name;
   Arch.consume_front("hexagonv");
@@ -267,18 +264,10 @@ std::optional 
HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
   return std::nullopt;
 }
 
-const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
-  const CPUSuffix *Item = llvm::find_if(
-  Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
-  if (Item == std::end(Suffixes))
-return nullptr;
-  return Item->Suffix.data();
-}
-
 void HexagonTargetInfo::fillValidCPUList(
 SmallVectorImpl &Values) const {
-  for (const CPUSuffix &Suffix : Suffixes)
-Values.push_back(Suffix.Name);
+  for (const llvm::StringLiteral &I : CpuValsText)
+Values.push_back(I);
 }
 
 llvm::SmallVector
diff --git a/clang/lib/Basic/Targets/Hexagon.h 
b/clang/lib/Basic/Targets/Hexagon.h
index a65663ca09eee..8aebbe157d6c1 100644
--- a/clang/lib/Basic/Targets/Hexagon.h
+++ b/clang/lib/Basic/Targets/Hexagon.h
@@ -25,6 +25,7 @@ namespace targets {
 // Hexagon abstract base class
 class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
 
+  static const llvm::ArrayRef CpuValsText;
   static const char *const GCCRegNames[];
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
   std::string CPU;
@@ -115,11 +116,11 @@ class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public 
TargetInfo {
 
   std::string_view getClobbers() const override { return ""; }
 
-  static const char *getHexagonCPUSuffix(StringRef Name);
   static std::optional getHexagonCPURev(StringRef Name);
 
   bool isValidCPUName(StringRef Name) const override {
-return getHexagonCPUSuffix(Name);
+return std::any_of(std::begin(CpuValsText), std::end(CpuValsText),
+   [Name](StringRef V) { return V == Name; });
   }
 
   void fillValidCPUList(SmallVectorImpl &Values) const override;
diff --git a/llvm/lib/Target/Hexagon/HexagonDepArch.h 
b/llvm/lib/Target/Hexagon/HexagonDepArch.h
index 89845348a9e31..6f851a042ca20 100644
--- a/llvm/lib/Target/Hexagon/HexagonDepArch.h