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 RISCVISAInfo(unsigned XLen,RISCVISAUtils::OrderedExtensionMap & Exts)29 RISCVISAInfo(unsigned XLen, RISCVISAUtils::OrderedExtensionMap &Exts) 30 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {} 31 32 /// Parse RISC-V ISA info from arch string. 33 /// If IgnoreUnknown is set, any unrecognised extension names or 34 /// extensions with unrecognised versions will be silently dropped, except 35 /// for the special case of the base 'i' and 'e' extensions, where the 36 /// default version will be used (as ignoring the base is not possible). 37 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 38 parseArchString(StringRef Arch, bool EnableExperimentalExtension, 39 bool ExperimentalExtensionVersionCheck = true, 40 bool IgnoreUnknown = false); 41 42 /// Parse RISC-V ISA info from an arch string that is already in normalized 43 /// form (as defined in the psABI). Unlike parseArchString, this function 44 /// will not error for unrecognized extension names or extension versions. 45 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 46 parseNormalizedArchString(StringRef Arch); 47 48 /// Parse RISC-V ISA info from feature vector. 49 static llvm::Expected<std::unique_ptr<RISCVISAInfo>> 50 parseFeatures(unsigned XLen, const std::vector<std::string> &Features); 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 llvm::Expected<std::unique_ptr<RISCVISAInfo>> 77 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo); 78 static std::string getTargetFeatureForExtension(StringRef Ext); 79 80 private: RISCVISAInfo(unsigned XLen)81 RISCVISAInfo(unsigned XLen) : XLen(XLen) {} 82 83 unsigned XLen; 84 unsigned FLen = 0; 85 unsigned MinVLen = 0; 86 unsigned MaxELen = 0, MaxELenFp = 0; 87 88 RISCVISAUtils::OrderedExtensionMap Exts; 89 90 bool addExtension(StringRef ExtName, RISCVISAUtils::ExtensionVersion Version); 91 92 Error checkDependency(); 93 94 void updateImplication(); 95 void updateCombination(); 96 97 /// Update FLen, MinVLen, MaxELen, and MaxELenFp. 98 void updateImpliedLengths(); 99 }; 100 101 } // namespace llvm 102 103 #endif 104