LLVM  14.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/Optional.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Error.h"
16 
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 namespace llvm {
23  std::string ExtName;
24  unsigned MajorVersion;
25  unsigned MinorVersion;
26 };
27 
28 class RISCVISAInfo {
29 public:
30  RISCVISAInfo(const RISCVISAInfo &) = delete;
31  RISCVISAInfo &operator=(const RISCVISAInfo &) = delete;
32 
33  static bool compareExtension(const std::string &LHS, const std::string &RHS);
34 
35  /// Helper class for OrderedExtensionMap.
37  bool operator()(const std::string &LHS, const std::string &RHS) const {
38  return compareExtension(LHS, RHS);
39  }
40  };
41 
42  /// OrderedExtensionMap is std::map, it's specialized to keep entries
43  /// in canonical order of extension.
44  typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
46 
47  /// Parse RISCV ISA info from arch string.
49  parseArchString(StringRef Arch, bool EnableExperimentalExtension,
50  bool ExperimentalExtensionVersionCheck = true);
51 
52  /// Parse RISCV ISA info from feature vector.
54  parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
55 
56  /// Convert RISCV ISA info to a feature vector.
57  void toFeatures(std::vector<StringRef> &Features,
58  std::function<StringRef(const Twine &)> StrAlloc) const;
59 
60  const OrderedExtensionMap &getExtensions() const { return Exts; };
61 
62  unsigned getXLen() const { return XLen; };
63  unsigned getFLen() const { return FLen; };
64  unsigned getMinVLen() const { return MinVLen; }
65  unsigned getMaxELen() const { return MaxELen; }
66  unsigned getMaxELenFp() const { return MaxELenFp; }
67 
68  bool hasExtension(StringRef Ext) const;
69  std::string toString() const;
70  std::vector<std::string> toFeatureVector() const;
71 
73  static bool isSupportedExtension(StringRef Ext);
74  static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
75  unsigned MinorVersion);
76 
77 private:
78  RISCVISAInfo(unsigned XLen)
79  : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
80 
81  unsigned XLen;
82  unsigned FLen;
83  unsigned MinVLen;
84  unsigned MaxELen, MaxELenFp;
85 
87 
88  void addExtension(StringRef ExtName, unsigned MajorVersion,
89  unsigned MinorVersion);
90 
91  Error checkDependency();
92 
93  void updateImplication();
94  void updateFLen();
95  void updateMinVLen();
96  void updateMaxELen();
97 };
98 
99 } // namespace llvm
100 
101 #endif
llvm::RISCVISAInfo::hasExtension
bool hasExtension(StringRef Ext) const
Definition: RISCVISAInfo.cpp:203
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::RISCVISAInfo::compareExtension
static bool compareExtension(const std::string &LHS, const std::string &RHS)
Definition: RISCVISAInfo.cpp:270
Optional.h
StringRef.h
Error.h
llvm::RISCVISAInfo::isSupportedExtension
static bool isSupportedExtension(StringRef Ext)
Definition: RISCVISAInfo.cpp:188
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
RHS
Value * RHS
Definition: X86PartialReduction.cpp:74
llvm::RISCVISAInfo::toFeatureVector
std::vector< std::string > toFeatureVector() const
Definition: RISCVISAInfo.cpp:876
llvm::RISCVISAInfo::getExtensions
const OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:60
LHS
Value * LHS
Definition: X86PartialReduction.cpp:73
llvm::RISCVISAInfo::getFLen
unsigned getFLen() const
Definition: RISCVISAInfo.h:63
llvm::RISCVExtensionInfo::ExtName
std::string ExtName
Definition: RISCVISAInfo.h:23
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:420
llvm::RISCVISAInfo::getXLen
unsigned getXLen() const
Definition: RISCVISAInfo.h:62
llvm::RISCVISAInfo::toString
std::string toString() const
Definition: RISCVISAInfo.cpp:859
StringMap.h
llvm::MipsISD::Ext
@ Ext
Definition: MipsISelLowering.h:156
llvm::RISCVExtensionInfo
Definition: RISCVISAInfo.h:22
llvm::RISCVISAInfo::getMinVLen
unsigned getMinVLen() const
Definition: RISCVISAInfo.h:64
llvm::RISCVExtensionInfo::MinorVersion
unsigned MinorVersion
Definition: RISCVISAInfo.h:25
llvm::RISCVISAInfo::ExtensionComparator
Helper class for OrderedExtensionMap.
Definition: RISCVISAInfo.h:36
llvm::RISCVISAInfo::parseArchString
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISCV ISA info from arch string.
Definition: RISCVISAInfo.cpp:462
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::RISCVISAInfo::ExtensionComparator::operator()
bool operator()(const std::string &LHS, const std::string &RHS) const
Definition: RISCVISAInfo.h:37
llvm::RISCVISAInfo::getMaxELenFp
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:66
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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:45
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:83
llvm::RISCVISAInfo::getMaxELen
unsigned getMaxELen() const
Definition: RISCVISAInfo.h:65
llvm::RISCVISAInfo
Definition: RISCVISAInfo.h:28
llvm::RISCVExtensionInfo::MajorVersion
unsigned MajorVersion
Definition: RISCVISAInfo.h:24
llvm::RISCVISAInfo::isSupportedExtensionFeature
static bool isSupportedExtensionFeature(StringRef Ext)
Definition: RISCVISAInfo.cpp:179
llvm::RISCVISAInfo::toFeatures
void toFeatures(std::vector< StringRef > &Features, std::function< StringRef(const Twine &)> StrAlloc) const
Convert RISCV ISA info to a feature vector.
Definition: RISCVISAInfo.cpp:294