Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:37

0001 //===-- RISCVISAInfo.h - RISC-V ISA Information -----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
0010 #define LLVM_SUPPORT_RISCVISAINFO_H
0011 
0012 #include "llvm/ADT/StringMap.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/Support/Error.h"
0015 #include "llvm/Support/RISCVISAUtils.h"
0016 
0017 #include <map>
0018 #include <set>
0019 #include <string>
0020 #include <vector>
0021 
0022 namespace llvm {
0023 
0024 class RISCVISAInfo {
0025 public:
0026   RISCVISAInfo(const RISCVISAInfo &) = delete;
0027   RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
0028 
0029   /// Parse RISC-V ISA info from arch string.
0030   /// If IgnoreUnknown is set, any unrecognised extension names or
0031   /// extensions with unrecognised versions will be silently dropped, except
0032   /// for the special case of the base 'i' and 'e' extensions, where the
0033   /// default version will be used (as ignoring the base is not possible).
0034   static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
0035   parseArchString(StringRef Arch, bool EnableExperimentalExtension,
0036                   bool ExperimentalExtensionVersionCheck = true);
0037 
0038   /// Parse RISC-V ISA info from an arch string that is already in normalized
0039   /// form (as defined in the psABI). Unlike parseArchString, this function
0040   /// will not error for unrecognized extension names or extension versions.
0041   static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
0042   parseNormalizedArchString(StringRef Arch);
0043 
0044   /// Parse RISC-V ISA info from feature vector.
0045   static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
0046   parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
0047 
0048   static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
0049   createFromExtMap(unsigned XLen,
0050                    const RISCVISAUtils::OrderedExtensionMap &Exts);
0051 
0052   /// Convert RISC-V ISA info to a feature vector.
0053   std::vector<std::string> toFeatures(bool AddAllExtensions = false,
0054                                       bool IgnoreUnknown = true) const;
0055 
0056   const RISCVISAUtils::OrderedExtensionMap &getExtensions() const {
0057     return Exts;
0058   }
0059 
0060   unsigned getXLen() const { return XLen; }
0061   unsigned getFLen() const { return FLen; }
0062   unsigned getMinVLen() const { return MinVLen; }
0063   unsigned getMaxVLen() const { return 65536; }
0064   unsigned getMaxELen() const { return MaxELen; }
0065   unsigned getMaxELenFp() const { return MaxELenFp; }
0066 
0067   bool hasExtension(StringRef Ext) const;
0068   std::string toString() const;
0069   StringRef computeDefaultABI() const;
0070 
0071   static bool isSupportedExtensionFeature(StringRef Ext);
0072   static bool isSupportedExtension(StringRef Ext);
0073   static bool isSupportedExtensionWithVersion(StringRef Ext);
0074   static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
0075                                    unsigned MinorVersion);
0076   static std::string getTargetFeatureForExtension(StringRef Ext);
0077 
0078   static void printSupportedExtensions(StringMap<StringRef> &DescMap);
0079   static void printEnabledExtensions(bool IsRV64,
0080                                      std::set<StringRef> &EnabledFeatureNames,
0081                                      StringMap<StringRef> &DescMap);
0082 
0083   /// Return the group id and bit position of __riscv_feature_bits.  Returns
0084   /// <-1, -1> if not supported.
0085   static std::pair<int, int> getRISCVFeaturesBitsInfo(StringRef Ext);
0086 
0087   // The maximum value of the group ID obtained from getRISCVFeaturesBitsInfo.
0088   static constexpr unsigned FeatureBitSize = 2;
0089 
0090 private:
0091   RISCVISAInfo(unsigned XLen) : XLen(XLen) {}
0092 
0093   unsigned XLen;
0094   unsigned FLen = 0;
0095   unsigned MinVLen = 0;
0096   unsigned MaxELen = 0, MaxELenFp = 0;
0097 
0098   RISCVISAUtils::OrderedExtensionMap Exts;
0099 
0100   Error checkDependency();
0101 
0102   void updateImplication();
0103   void updateCombination();
0104 
0105   /// Update FLen, MinVLen, MaxELen, and MaxELenFp.
0106   void updateImpliedLengths();
0107 
0108   static llvm::Expected<std::unique_ptr<RISCVISAInfo>>
0109   postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
0110 };
0111 
0112 } // namespace llvm
0113 
0114 #endif