LLVM 19.0.0git
RISCVISAInfo.h
Go to the documentation of this file.
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
16#include <map>
17#include <string>
18#include <vector>
19
20namespace llvm {
21void riscvExtensionsHelp(StringMap<StringRef> DescMap);
22
24public:
25 RISCVISAInfo(const RISCVISAInfo &) = delete;
27
28 /// Represents the major and version number components of a RISC-V extension.
30 unsigned Major;
31 unsigned Minor;
32 };
33
34 static bool compareExtension(const std::string &LHS, const std::string &RHS);
35
36 /// Helper class for OrderedExtensionMap.
38 bool operator()(const std::string &LHS, const std::string &RHS) const {
39 return compareExtension(LHS, RHS);
40 }
41 };
42
43 /// OrderedExtensionMap is std::map, it's specialized to keep entries
44 /// in canonical order of extension.
45 typedef std::map<std::string, ExtensionVersion, ExtensionComparator>
47
48 RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
49 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
50
51 /// Parse RISC-V ISA info from arch string.
52 /// If IgnoreUnknown is set, any unrecognised extension names or
53 /// extensions with unrecognised versions will be silently dropped, except
54 /// for the special case of the base 'i' and 'e' extensions, where the
55 /// default version will be used (as ignoring the base is not possible).
57 parseArchString(StringRef Arch, bool EnableExperimentalExtension,
58 bool ExperimentalExtensionVersionCheck = true,
59 bool IgnoreUnknown = false);
60
61 /// Parse RISC-V ISA info from an arch string that is already in normalized
62 /// form (as defined in the psABI). Unlike parseArchString, this function
63 /// will not error for unrecognized extension names or extension versions.
66
67 /// Parse RISC-V ISA info from feature vector.
69 parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
70
71 /// Convert RISC-V ISA info to a feature vector.
72 std::vector<std::string> toFeatures(bool AddAllExtensions = false,
73 bool IgnoreUnknown = true) const;
74
75 const OrderedExtensionMap &getExtensions() const { return Exts; }
76
77 unsigned getXLen() const { return XLen; }
78 unsigned getFLen() const { return FLen; }
79 unsigned getMinVLen() const { return MinVLen; }
80 unsigned getMaxVLen() const { return 65536; }
81 unsigned getMaxELen() const { return MaxELen; }
82 unsigned getMaxELenFp() const { return MaxELenFp; }
83
84 bool hasExtension(StringRef Ext) const;
85 std::string toString() const;
87
89 static bool isSupportedExtension(StringRef Ext);
91 static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
92 unsigned MinorVersion);
94 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
95 static std::string getTargetFeatureForExtension(StringRef Ext);
96
97private:
98 RISCVISAInfo(unsigned XLen)
99 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
100
101 unsigned XLen;
102 unsigned FLen;
103 unsigned MinVLen;
104 unsigned MaxELen, MaxELenFp;
105
107
108 void addExtension(StringRef ExtName, ExtensionVersion Version);
109
110 Error checkDependency();
111
112 void updateImplication();
113 void updateCombination();
114 void updateFLen();
115 void updateMinVLen();
116 void updateMaxELen();
117};
118
119} // namespace llvm
120
121#endif
This file defines the StringMap class.
Value * RHS
Value * LHS
Tagged union holding either a T or a Error.
Definition: Error.h:474
std::map< std::string, ExtensionVersion, ExtensionComparator > OrderedExtensionMap
OrderedExtensionMap is std::map, it's specialized to keep entries in canonical order of extension.
Definition: RISCVISAInfo.h:46
static bool isSupportedExtensionFeature(StringRef Ext)
RISCVISAInfo & operator=(const RISCVISAInfo &)=delete
static std::string getTargetFeatureForExtension(StringRef Ext)
unsigned getMinVLen() const
Definition: RISCVISAInfo.h:79
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseNormalizedArchString(StringRef Arch)
Parse RISC-V ISA info from an arch string that is already in normalized form (as defined in the psABI...
bool hasExtension(StringRef Ext) const
RISCVISAInfo(const RISCVISAInfo &)=delete
unsigned getFLen() const
Definition: RISCVISAInfo.h:78
static bool compareExtension(const std::string &LHS, const std::string &RHS)
std::string toString() const
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > postProcessAndChecking(std::unique_ptr< RISCVISAInfo > &&ISAInfo)
StringRef computeDefaultABI() const
unsigned getMaxVLen() const
Definition: RISCVISAInfo.h:80
static bool isSupportedExtension(StringRef Ext)
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatures(unsigned XLen, const std::vector< std::string > &Features)
Parse RISC-V ISA info from feature vector.
unsigned getMaxELen() const
Definition: RISCVISAInfo.h:81
unsigned getXLen() const
Definition: RISCVISAInfo.h:77
RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
Definition: RISCVISAInfo.h:48
const OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:75
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:82
std::vector< std::string > toFeatures(bool AddAllExtensions=false, bool IgnoreUnknown=true) const
Convert RISC-V ISA info to a feature vector.
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true, bool IgnoreUnknown=false)
Parse RISC-V ISA info from arch string.
static bool isSupportedExtensionWithVersion(StringRef Ext)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void riscvExtensionsHelp(StringMap< StringRef > DescMap)
Helper class for OrderedExtensionMap.
Definition: RISCVISAInfo.h:37
bool operator()(const std::string &LHS, const std::string &RHS) const
Definition: RISCVISAInfo.h:38
Represents the major and version number components of a RISC-V extension.
Definition: RISCVISAInfo.h:29