[llvm] c570287 - [RISCV][NFC] Move RISCVISAInfo back to Support

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 21:56:17 PST 2023


Author: wangpc
Date: 2023-01-03T13:55:39+08:00
New Revision: c570287fbf4d2ee8656e94bd20a9aa96553febd0

URL: https://github.com/llvm/llvm-project/commit/c570287fbf4d2ee8656e94bd20a9aa96553febd0
DIFF: https://github.com/llvm/llvm-project/commit/c570287fbf4d2ee8656e94bd20a9aa96553febd0.diff

LOG: [RISCV][NFC] Move RISCVISAInfo back to Support

So that there is no cyclic dependency if we want to use it in
tablegen.

Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D140529

Added: 
    llvm/lib/Support/RISCVISAInfo.cpp

Modified: 
    llvm/include/llvm/Support/RISCVISAInfo.h
    llvm/lib/Support/CMakeLists.txt
    llvm/lib/TargetParser/CMakeLists.txt

Removed: 
    llvm/include/llvm/TargetParser/RISCVISAInfo.h
    llvm/lib/TargetParser/RISCVISAInfo.cpp


################################################################################
diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h b/llvm/include/llvm/Support/RISCVISAInfo.h
index 06aaf9bc95a04..746ef5f947b06 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -1,14 +1,107 @@
-//===-- llvm/Support/RISCVISAInfo.h -----------------------------*- C++ -*-===//
+//===-- RISCVISAInfo.h - RISCV ISA Information ------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-///
-/// \file
-/// This header is deprecated in favour of `llvm/Support/RISCVISAInfo.h`.
-///
-//===----------------------------------------------------------------------===//
 
-#include "llvm/TargetParser/RISCVISAInfo.h"
+#ifndef LLVM_SUPPORT_RISCVISAINFO_H
+#define LLVM_SUPPORT_RISCVISAINFO_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace llvm {
+struct RISCVExtensionInfo {
+  std::string ExtName;
+  unsigned MajorVersion;
+  unsigned MinorVersion;
+};
+
+class RISCVISAInfo {
+public:
+  RISCVISAInfo(const RISCVISAInfo &) = delete;
+  RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
+
+  static bool compareExtension(const std::string &LHS, const std::string &RHS);
+
+  /// Helper class for OrderedExtensionMap.
+  struct ExtensionComparator {
+    bool operator()(const std::string &LHS, const std::string &RHS) const {
+      return compareExtension(LHS, RHS);
+    }
+  };
+
+  /// OrderedExtensionMap is std::map, it's specialized to keep entries
+  /// in canonical order of extension.
+  typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
+      OrderedExtensionMap;
+
+  RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
+      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
+
+  /// Parse RISCV ISA info from arch string.
+  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+  parseArchString(StringRef Arch, bool EnableExperimentalExtension,
+                  bool ExperimentalExtensionVersionCheck = true);
+
+  /// Parse RISCV ISA info from feature vector.
+  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+  parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
+
+  /// Convert RISCV ISA info to a feature vector.
+  void toFeatures(std::vector<StringRef> &Features,
+                  std::function<StringRef(const Twine &)> StrAlloc) const;
+
+  const OrderedExtensionMap &getExtensions() const { return Exts; };
+
+  unsigned getXLen() const { return XLen; };
+  unsigned getFLen() const { return FLen; };
+  unsigned getMinVLen() const { return MinVLen; }
+  unsigned getMaxVLen() const { return 65536; }
+  unsigned getMaxELen() const { return MaxELen; }
+  unsigned getMaxELenFp() const { return MaxELenFp; }
+
+  bool hasExtension(StringRef Ext) const;
+  std::string toString() const;
+  std::vector<std::string> toFeatureVector() const;
+  StringRef computeDefaultABI() const;
+
+  static bool isSupportedExtensionFeature(StringRef Ext);
+  static bool isSupportedExtension(StringRef Ext);
+  static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
+                                   unsigned MinorVersion);
+  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
+  postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
+
+private:
+  RISCVISAInfo(unsigned XLen)
+      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
+
+  unsigned XLen;
+  unsigned FLen;
+  unsigned MinVLen;
+  unsigned MaxELen, MaxELenFp;
+
+  OrderedExtensionMap Exts;
+
+  void addExtension(StringRef ExtName, unsigned MajorVersion,
+                    unsigned MinorVersion);
+
+  Error checkDependency();
+
+  void updateImplication();
+  void updateCombination();
+  void updateFLen();
+  void updateMinVLen();
+  void updateMaxELen();
+};
+
+} // namespace llvm
+
+#endif

diff  --git a/llvm/include/llvm/TargetParser/RISCVISAInfo.h b/llvm/include/llvm/TargetParser/RISCVISAInfo.h
deleted file mode 100644
index e352d8ab9e4db..0000000000000
--- a/llvm/include/llvm/TargetParser/RISCVISAInfo.h
+++ /dev/null
@@ -1,107 +0,0 @@
-//===-- RISCVISAInfo.h - RISCV ISA Information ------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TARGETPARSER_RISCVISAINFO_H
-#define LLVM_TARGETPARSER_RISCVISAINFO_H
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace llvm {
-struct RISCVExtensionInfo {
-  std::string ExtName;
-  unsigned MajorVersion;
-  unsigned MinorVersion;
-};
-
-class RISCVISAInfo {
-public:
-  RISCVISAInfo(const RISCVISAInfo &) = delete;
-  RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
-
-  static bool compareExtension(const std::string &LHS, const std::string &RHS);
-
-  /// Helper class for OrderedExtensionMap.
-  struct ExtensionComparator {
-    bool operator()(const std::string &LHS, const std::string &RHS) const {
-      return compareExtension(LHS, RHS);
-    }
-  };
-
-  /// OrderedExtensionMap is std::map, it's specialized to keep entries
-  /// in canonical order of extension.
-  typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
-      OrderedExtensionMap;
-
-  RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
-      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
-
-  /// Parse RISCV ISA info from arch string.
-  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
-  parseArchString(StringRef Arch, bool EnableExperimentalExtension,
-                  bool ExperimentalExtensionVersionCheck = true);
-
-  /// Parse RISCV ISA info from feature vector.
-  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
-  parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
-
-  /// Convert RISCV ISA info to a feature vector.
-  void toFeatures(std::vector<StringRef> &Features,
-                  std::function<StringRef(const Twine &)> StrAlloc) const;
-
-  const OrderedExtensionMap &getExtensions() const { return Exts; };
-
-  unsigned getXLen() const { return XLen; };
-  unsigned getFLen() const { return FLen; };
-  unsigned getMinVLen() const { return MinVLen; }
-  unsigned getMaxVLen() const { return 65536; }
-  unsigned getMaxELen() const { return MaxELen; }
-  unsigned getMaxELenFp() const { return MaxELenFp; }
-
-  bool hasExtension(StringRef Ext) const;
-  std::string toString() const;
-  std::vector<std::string> toFeatureVector() const;
-  StringRef computeDefaultABI() const;
-
-  static bool isSupportedExtensionFeature(StringRef Ext);
-  static bool isSupportedExtension(StringRef Ext);
-  static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
-                                   unsigned MinorVersion);
-  static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
-  postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
-
-private:
-  RISCVISAInfo(unsigned XLen)
-      : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
-
-  unsigned XLen;
-  unsigned FLen;
-  unsigned MinVLen;
-  unsigned MaxELen, MaxELenFp;
-
-  OrderedExtensionMap Exts;
-
-  void addExtension(StringRef ExtName, unsigned MajorVersion,
-                    unsigned MinorVersion);
-
-  Error checkDependency();
-
-  void updateImplication();
-  void updateCombination();
-  void updateFLen();
-  void updateMinVLen();
-  void updateMaxELen();
-};
-
-} // namespace llvm
-
-#endif

diff  --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index aa64f186f662c..46469c6e9e624 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -202,6 +202,7 @@ add_llvm_component_library(LLVMSupport
   Regex.cpp
   RISCVAttributes.cpp
   RISCVAttributeParser.cpp
+  RISCVISAInfo.cpp
   ScaledNumber.cpp
   ScopedPrinter.cpp
   SHA1.cpp

diff  --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
similarity index 99%
rename from llvm/lib/TargetParser/RISCVISAInfo.cpp
rename to llvm/lib/Support/RISCVISAInfo.cpp
index 4f56d1aa00955..168fdbf20e404 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/TargetParser/RISCVISAInfo.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringExtras.h"
@@ -132,8 +132,8 @@ static bool stripExperimentalPrefix(StringRef &Ext) {
 // have version numbers and no extension name. It assumes the extension name
 // will be at least more than one character.
 static size_t findFirstNonVersionCharacter(StringRef Ext) {
-   assert(!Ext.empty() &&
-          "Already guarded by if-statement in ::parseArchString");
+  assert(!Ext.empty() &&
+         "Already guarded by if-statement in ::parseArchString");
 
   int Pos = Ext.size() - 1;
   while (Pos > 0 && isDigit(Ext[Pos]))
@@ -783,7 +783,8 @@ static const char *ImpliedExtsZvl256b[] = {"zvl128b"};
 static const char *ImpliedExtsZvl128b[] = {"zvl64b"};
 static const char *ImpliedExtsZvl64b[] = {"zvl32b"};
 static const char *ImpliedExtsZk[] = {"zkn", "zkt", "zkr"};
-static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"};
+static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx",
+                                       "zkne", "zknd", "zknh"};
 static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"};
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
 static const char *ImpliedExtsXTHeadVdot[] = {"v"};

diff  --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt
index 4249cc075e888..7e31f817cb28e 100644
--- a/llvm/lib/TargetParser/CMakeLists.txt
+++ b/llvm/lib/TargetParser/CMakeLists.txt
@@ -6,7 +6,6 @@ add_llvm_component_library(LLVMTargetParser
   CSKYTargetParser.cpp
   Host.cpp
   LoongArchTargetParser.cpp
-  RISCVISAInfo.cpp
   TargetParser.cpp
   Triple.cpp
   X86TargetParser.cpp


        


More information about the llvm-commits mailing list