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 <set> 19 #include <string> 20 #include <vector> 21 22 namespace llvm { 23 24 class RISCVISAInfo { 25 public: 26 RISCVISAInfo(const RISCVISAInfo &) = delete; 27 RISCVISAInfo &operator=(const RISCVISAInfo &) = delete; 28 29 /// Parse RISC-V ISA info from arch string. 30 /// If IgnoreUnknown is set, any unrecognised extension names or 31 /// extensions with unrecognised versions will be silently dropped, except 32 /// for the special case of the base 'i' and 'e' extensions, where the 33 /// default version will be used (as ignoring the base is not possible). 34 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 35 parseArchString(StringRef Arch, bool EnableExperimentalExtension, 36 bool ExperimentalExtensionVersionCheck = true); 37 38 /// Parse RISC-V ISA info from an arch string that is already in normalized 39 /// form (as defined in the psABI). Unlike parseArchString, this function 40 /// will not error for unrecognized extension names or extension versions. 41 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 42 parseNormalizedArchString(StringRef Arch); 43 44 /// Parse RISC-V ISA info from feature vector. 45 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 46 parseFeatures(unsigned XLen, const std::vector<std::string> &Features); 47 48 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 49 createFromExtMap(unsigned XLen, 50 const RISCVISAUtils::OrderedExtensionMap &Exts); 51 52 /// Convert RISC-V ISA info to a feature vector. 53 std::vector<std::string> toFeatures(bool AddAllExtensions = false, 54 bool IgnoreUnknown = true) const; 55 getExtensions()56 const RISCVISAUtils::OrderedExtensionMap &getExtensions() const { 57 return Exts; 58 } 59 getXLen()60 unsigned getXLen() const { return XLen; } getFLen()61 unsigned getFLen() const { return FLen; } getMinVLen()62 unsigned getMinVLen() const { return MinVLen; } getMaxVLen()63 unsigned getMaxVLen() const { return 65536; } getMaxELen()64 unsigned getMaxELen() const { return MaxELen; } getMaxELenFp()65 unsigned getMaxELenFp() const { return MaxELenFp; } 66 67 bool hasExtension(StringRef Ext) const; 68 std::string toString() const; 69 StringRef computeDefaultABI() const; 70 71 static bool isSupportedExtensionFeature(StringRef Ext); 72 static bool isSupportedExtension(StringRef Ext); 73 static bool isSupportedExtensionWithVersion(StringRef Ext); 74 static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion, 75 unsigned MinorVersion); 76 static std::string getTargetFeatureForExtension(StringRef Ext); 77 78 static void printSupportedExtensions(StringMap<StringRef> &DescMap); 79 static void printEnabledExtensions(bool IsRV64, 80 std::set<StringRef> &EnabledFeatureNames, 81 StringMap<StringRef> &DescMap); 82 83 private: RISCVISAInfo(unsigned XLen)84 RISCVISAInfo(unsigned XLen) : XLen(XLen) {} 85 86 unsigned XLen; 87 unsigned FLen = 0; 88 unsigned MinVLen = 0; 89 unsigned MaxELen = 0, MaxELenFp = 0; 90 91 RISCVISAUtils::OrderedExtensionMap Exts; 92 93 Error checkDependency(); 94 95 void updateImplication(); 96 void updateCombination(); 97 98 /// Update FLen, MinVLen, MaxELen, and MaxELenFp. 99 void updateImpliedLengths(); 100 101 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 102 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo); 103 }; 104 105 } // namespace llvm 106 107 #endif 108