RISCVISAInfo.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- RISCVISAInfo.h - RISCV ISA Information ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_RISCVISAINFO_H
  14. #define LLVM_SUPPORT_RISCVISAINFO_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Support/Error.h"
  17. #include <map>
  18. #include <string>
  19. #include <vector>
  20. namespace llvm {
  21. struct RISCVExtensionInfo {
  22. std::string ExtName;
  23. unsigned MajorVersion;
  24. unsigned MinorVersion;
  25. };
  26. class RISCVISAInfo {
  27. public:
  28. RISCVISAInfo(const RISCVISAInfo &) = delete;
  29. RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
  30. static bool compareExtension(const std::string &LHS, const std::string &RHS);
  31. /// Helper class for OrderedExtensionMap.
  32. struct ExtensionComparator {
  33. bool operator()(const std::string &LHS, const std::string &RHS) const {
  34. return compareExtension(LHS, RHS);
  35. }
  36. };
  37. /// OrderedExtensionMap is std::map, it's specialized to keep entries
  38. /// in canonical order of extension.
  39. typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
  40. OrderedExtensionMap;
  41. /// Parse RISCV ISA info from arch string.
  42. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  43. parseArchString(StringRef Arch, bool EnableExperimentalExtension,
  44. bool ExperimentalExtensionVersionCheck = true);
  45. /// Parse RISCV ISA info from feature vector.
  46. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  47. parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
  48. /// Convert RISCV ISA info to a feature vector.
  49. void toFeatures(std::vector<StringRef> &Features,
  50. std::function<StringRef(const Twine &)> StrAlloc) const;
  51. const OrderedExtensionMap &getExtensions() const { return Exts; };
  52. unsigned getXLen() const { return XLen; };
  53. unsigned getFLen() const { return FLen; };
  54. unsigned getMinVLen() const { return MinVLen; }
  55. unsigned getMaxELen() const { return MaxELen; }
  56. unsigned getMaxELenFp() const { return MaxELenFp; }
  57. bool hasExtension(StringRef Ext) const;
  58. std::string toString() const;
  59. std::vector<std::string> toFeatureVector() const;
  60. static bool isSupportedExtensionFeature(StringRef Ext);
  61. static bool isSupportedExtension(StringRef Ext);
  62. static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
  63. unsigned MinorVersion);
  64. private:
  65. RISCVISAInfo(unsigned XLen)
  66. : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
  67. unsigned XLen;
  68. unsigned FLen;
  69. unsigned MinVLen;
  70. unsigned MaxELen, MaxELenFp;
  71. OrderedExtensionMap Exts;
  72. void addExtension(StringRef ExtName, unsigned MajorVersion,
  73. unsigned MinorVersion);
  74. Error checkDependency();
  75. void updateImplication();
  76. void updateFLen();
  77. void updateMinVLen();
  78. void updateMaxELen();
  79. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  80. postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
  81. };
  82. } // namespace llvm
  83. #endif
  84. #ifdef __GNUC__
  85. #pragma GCC diagnostic pop
  86. #endif