1 | //===-- RISCVISAInfo.h - RISC-V ISA Information -----------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_SUPPORT_RISCVISAINFO_H |
10 | #define LLVM_SUPPORT_RISCVISAINFO_H |
11 | |
12 | #include "llvm/ADT/StringMap.h" |
13 | #include "llvm/ADT/StringRef.h" |
14 | #include "llvm/Support/Error.h" |
15 | #include "llvm/Support/RISCVISAUtils.h" |
16 | |
17 | #include <map> |
18 | #include <string> |
19 | #include <vector> |
20 | |
21 | namespace llvm { |
22 | void riscvExtensionsHelp(StringMap<StringRef> DescMap); |
23 | |
24 | class RISCVISAInfo { |
25 | public: |
26 | RISCVISAInfo(const RISCVISAInfo &) = delete; |
27 | RISCVISAInfo &operator=(const RISCVISAInfo &) = delete; |
28 | |
29 | /// OrderedExtensionMap is std::map, it's specialized to keep entries |
30 | /// in canonical order of extension. |
31 | typedef std::map<std::string, RISCVISAUtils::ExtensionVersion, |
32 | RISCVISAUtils::ExtensionComparator> |
33 | OrderedExtensionMap; |
34 | |
35 | RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts) |
36 | : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {} |
37 | |
38 | /// Parse RISC-V ISA info from arch string. |
39 | /// If IgnoreUnknown is set, any unrecognised extension names or |
40 | /// extensions with unrecognised versions will be silently dropped, except |
41 | /// for the special case of the base 'i' and 'e' extensions, where the |
42 | /// default version will be used (as ignoring the base is not possible). |
43 | static llvm::Expected<std::unique_ptr<RISCVISAInfo>> |
44 | parseArchString(StringRef Arch, bool EnableExperimentalExtension, |
45 | bool ExperimentalExtensionVersionCheck = true, |
46 | bool IgnoreUnknown = false); |
47 | |
48 | /// Parse RISC-V 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 | |
54 | /// Parse RISC-V ISA info from feature vector. |
55 | static llvm::Expected<std::unique_ptr<RISCVISAInfo>> |
56 | parseFeatures(unsigned XLen, const std::vector<std::string> &Features); |
57 | |
58 | /// Convert RISC-V ISA info to a feature vector. |
59 | std::vector<std::string> toFeatures(bool AddAllExtensions = false, |
60 | bool IgnoreUnknown = true) const; |
61 | |
62 | const OrderedExtensionMap &getExtensions() const { return Exts; } |
63 | |
64 | unsigned getXLen() const { return XLen; } |
65 | unsigned getFLen() const { return FLen; } |
66 | unsigned getMinVLen() const { return MinVLen; } |
67 | unsigned getMaxVLen() const { return 65536; } |
68 | unsigned getMaxELen() const { return MaxELen; } |
69 | unsigned getMaxELenFp() const { return MaxELenFp; } |
70 | |
71 | bool hasExtension(StringRef Ext) const; |
72 | std::string toString() const; |
73 | StringRef computeDefaultABI() const; |
74 | |
75 | static bool isSupportedExtensionFeature(StringRef Ext); |
76 | static bool isSupportedExtension(StringRef Ext); |
77 | static bool isSupportedExtensionWithVersion(StringRef Ext); |
78 | static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion, |
79 | unsigned MinorVersion); |
80 | static llvm::Expected<std::unique_ptr<RISCVISAInfo>> |
81 | postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo); |
82 | static std::string getTargetFeatureForExtension(StringRef Ext); |
83 | |
84 | private: |
85 | RISCVISAInfo(unsigned XLen) |
86 | : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {} |
87 | |
88 | unsigned XLen; |
89 | unsigned FLen; |
90 | unsigned MinVLen; |
91 | unsigned MaxELen, MaxELenFp; |
92 | |
93 | OrderedExtensionMap Exts; |
94 | |
95 | void addExtension(StringRef ExtName, RISCVISAUtils::ExtensionVersion Version); |
96 | |
97 | Error checkDependency(); |
98 | |
99 | void updateImplication(); |
100 | void updateCombination(); |
101 | void updateFLen(); |
102 | void updateMinVLen(); |
103 | void updateMaxELen(); |
104 | }; |
105 | |
106 | } // namespace llvm |
107 | |
108 | #endif |
109 | |