LLVM  17.0.0git
RISCVISAInfo.h
Go to the documentation of this file.
1 //===-- RISCVISAInfo.h - RISCV 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/StringRef.h"
13 #include "llvm/Support/Error.h"
14 
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 namespace llvm {
21  std::string ExtName;
22  unsigned MajorVersion;
23  unsigned MinorVersion;
24 };
25 
26 class RISCVISAInfo {
27 public:
28  RISCVISAInfo(const RISCVISAInfo &) = delete;
29  RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
30 
31  static bool compareExtension(const std::string &LHS, const std::string &RHS);
32 
33  /// Helper class for OrderedExtensionMap.
35  bool operator()(const std::string &LHS, const std::string &RHS) const {
36  return compareExtension(LHS, RHS);
37  }
38  };
39 
40  /// OrderedExtensionMap is std::map, it's specialized to keep entries
41  /// in canonical order of extension.
42  typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
44 
45  RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
46  : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
47 
48  /// Parse RISCV ISA info from arch string.
50  parseArchString(StringRef Arch, bool EnableExperimentalExtension,
51  bool ExperimentalExtensionVersionCheck = true,
52  bool IgnoreUnknown = false);
53 
54  /// Parse RISCV ISA info from feature vector.
56  parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
57 
58  /// Convert RISCV ISA info to a feature vector.
59  void toFeatures(std::vector<StringRef> &Features,
60  llvm::function_ref<StringRef(const Twine &)> StrAlloc,
61  bool AddAllExtensions) const;
62 
63  const OrderedExtensionMap &getExtensions() const { return Exts; };
64 
65  unsigned getXLen() const { return XLen; };
66  unsigned getFLen() const { return FLen; };
67  unsigned getMinVLen() const { return MinVLen; }
68  unsigned getMaxVLen() const { return 65536; }
69  unsigned getMaxELen() const { return MaxELen; }
70  unsigned getMaxELenFp() const { return MaxELenFp; }
71 
72  bool hasExtension(StringRef Ext) const;
73  std::string toString() const;
74  std::vector<std::string> toFeatureVector() const;
76 
78  static bool isSupportedExtension(StringRef Ext);
79  static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
80  unsigned MinorVersion);
82  postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
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 
94 
95  void addExtension(StringRef ExtName, unsigned MajorVersion,
96  unsigned MinorVersion);
97 
98  Error checkDependency();
99 
100  void updateImplication();
101  void updateCombination();
102  void updateFLen();
103  void updateMinVLen();
104  void updateMaxELen();
105 };
106 
107 } // namespace llvm
108 
109 #endif
llvm::RISCVISAInfo::hasExtension
bool hasExtension(StringRef Ext) const
Definition: RISCVISAInfo.cpp:245
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::RISCVISAInfo::compareExtension
static bool compareExtension(const std::string &LHS, const std::string &RHS)
Definition: RISCVISAInfo.cpp:309
StringRef.h
llvm::RISCVISAInfo::computeDefaultABI
StringRef computeDefaultABI() const
Definition: RISCVISAInfo.cpp:1026
llvm::RISCVISAInfo::getMaxVLen
unsigned getMaxVLen() const
Definition: RISCVISAInfo.h:68
Error.h
llvm::RISCVISAInfo::RISCVISAInfo
RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
Definition: RISCVISAInfo.h:45
llvm::RISCVISAInfo::isSupportedExtension
static bool isSupportedExtension(StringRef Ext)
Definition: RISCVISAInfo.cpp:230
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::RISCVISAInfo::toFeatureVector
std::vector< std::string > toFeatureVector() const
Definition: RISCVISAInfo.cpp:999
llvm::RISCVISAInfo::getExtensions
const OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:63
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::RISCVISAInfo::getFLen
unsigned getFLen() const
Definition: RISCVISAInfo.h:66
llvm::RISCVExtensionInfo::ExtName
std::string ExtName
Definition: RISCVISAInfo.h:21
llvm::RISCVISAInfo::parseFeatures
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatures(unsigned XLen, const std::vector< std::string > &Features)
Parse RISCV ISA info from feature vector.
Definition: RISCVISAInfo.cpp:473
llvm::RISCVISAInfo::getXLen
unsigned getXLen() const
Definition: RISCVISAInfo.h:65
llvm::RISCVISAInfo::toString
std::string toString() const
Definition: RISCVISAInfo.cpp:982
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::MipsISD::Ext
@ Ext
Definition: MipsISelLowering.h:159
llvm::RISCVExtensionInfo
Definition: RISCVISAInfo.h:20
llvm::RISCVISAInfo::getMinVLen
unsigned getMinVLen() const
Definition: RISCVISAInfo.h:67
llvm::RISCVExtensionInfo::MinorVersion
unsigned MinorVersion
Definition: RISCVISAInfo.h:23
llvm::RISCVISAInfo::ExtensionComparator
Helper class for OrderedExtensionMap.
Definition: RISCVISAInfo.h:34
llvm::RISCVISAInfo::ExtensionComparator::operator()
bool operator()(const std::string &LHS, const std::string &RHS) const
Definition: RISCVISAInfo.h:35
llvm::RISCVISAInfo::getMaxELenFp
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:70
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::RISCVISAInfo::OrderedExtensionMap
std::map< std::string, RISCVExtensionInfo, ExtensionComparator > OrderedExtensionMap
OrderedExtensionMap is std::map, it's specialized to keep entries in canonical order of extension.
Definition: RISCVISAInfo.h:43
llvm::RISCVISAInfo::RISCVISAInfo
RISCVISAInfo(const RISCVISAInfo &)=delete
llvm::RISCVISAInfo::operator=
RISCVISAInfo & operator=(const RISCVISAInfo &)=delete
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::RISCVISAInfo::postProcessAndChecking
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > postProcessAndChecking(std::unique_ptr< RISCVISAInfo > &&ISAInfo)
Definition: RISCVISAInfo.cpp:1014
llvm::RISCVISAInfo::getMaxELen
unsigned getMaxELen() const
Definition: RISCVISAInfo.h:69
llvm::RISCVISAInfo
Definition: RISCVISAInfo.h:26
llvm::RISCVExtensionInfo::MajorVersion
unsigned MajorVersion
Definition: RISCVISAInfo.h:22
llvm::RISCVISAInfo::parseArchString
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true, bool IgnoreUnknown=false)
Parse RISCV ISA info from arch string.
Definition: RISCVISAInfo.cpp:507
llvm::RISCVISAInfo::isSupportedExtensionFeature
static bool isSupportedExtensionFeature(StringRef Ext)
Definition: RISCVISAInfo.cpp:221
llvm::RISCVISAInfo::toFeatures
void toFeatures(std::vector< StringRef > &Features, llvm::function_ref< StringRef(const Twine &)> StrAlloc, bool AddAllExtensions) const
Convert RISCV ISA info to a feature vector.
Definition: RISCVISAInfo.cpp:333