RISCVISAInfo.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
  42. : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
  43. /// Parse RISCV ISA info from arch string.
  44. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  45. parseArchString(StringRef Arch, bool EnableExperimentalExtension,
  46. bool ExperimentalExtensionVersionCheck = true,
  47. bool IgnoreUnknown = false);
  48. /// Parse RISCV ISA info from an arch string that is already in normalized
  49. /// form (as defined in the psABI). Unlike parseArchString, this function
  50. /// will not error for unrecognized extension names or extension versions.
  51. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  52. parseNormalizedArchString(StringRef Arch);
  53. /// Parse RISCV ISA info from feature vector.
  54. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  55. parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
  56. /// Convert RISCV ISA info to a feature vector.
  57. void toFeatures(std::vector<StringRef> &Features,
  58. llvm::function_ref<StringRef(const Twine &)> StrAlloc,
  59. bool AddAllExtensions) const;
  60. const OrderedExtensionMap &getExtensions() const { return Exts; };
  61. unsigned getXLen() const { return XLen; };
  62. unsigned getFLen() const { return FLen; };
  63. unsigned getMinVLen() const { return MinVLen; }
  64. unsigned getMaxVLen() const { return 65536; }
  65. unsigned getMaxELen() const { return MaxELen; }
  66. unsigned getMaxELenFp() const { return MaxELenFp; }
  67. bool hasExtension(StringRef Ext) const;
  68. std::string toString() const;
  69. std::vector<std::string> toFeatureVector() const;
  70. StringRef computeDefaultABI() const;
  71. static bool isSupportedExtensionFeature(StringRef Ext);
  72. static bool isSupportedExtension(StringRef Ext);
  73. static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
  74. unsigned MinorVersion);
  75. static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
  76. postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
  77. private:
  78. RISCVISAInfo(unsigned XLen)
  79. : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
  80. unsigned XLen;
  81. unsigned FLen;
  82. unsigned MinVLen;
  83. unsigned MaxELen, MaxELenFp;
  84. OrderedExtensionMap Exts;
  85. void addExtension(StringRef ExtName, unsigned MajorVersion,
  86. unsigned MinorVersion);
  87. Error checkDependency();
  88. void updateImplication();
  89. void updateCombination();
  90. void updateFLen();
  91. void updateMinVLen();
  92. void updateMaxELen();
  93. };
  94. } // namespace llvm
  95. #endif
  96. #ifdef __GNUC__
  97. #pragma GCC diagnostic pop
  98. #endif