LLVM 18.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 {
22 unsigned MajorVersion;
23 unsigned MinorVersion;
24};
25
27
29public:
30 RISCVISAInfo(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 RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
48 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
49
50 /// Parse RISC-V ISA info from arch string.
51 /// If IgnoreUnknown is set, any unrecognised extension names or
52 /// extensions with unrecognised versions will be silently dropped, except
53 /// for the special case of the base 'i' and 'e' extensions, where the
54 /// default version will be used (as ignoring the base is not possible).
56 parseArchString(StringRef Arch, bool EnableExperimentalExtension,
57 bool ExperimentalExtensionVersionCheck = true,
58 bool IgnoreUnknown = false);
59
60 /// Parse RISC-V ISA info from an arch string that is already in normalized
61 /// form (as defined in the psABI). Unlike parseArchString, this function
62 /// will not error for unrecognized extension names or extension versions.
65
66 /// Parse RISC-V ISA info from feature vector.
68 parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
69
70 /// Convert RISC-V ISA info to a feature vector.
71 void toFeatures(std::vector<StringRef> &Features,
72 llvm::function_ref<StringRef(const Twine &)> StrAlloc,
73 bool AddAllExtensions) 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;
86 std::vector<std::string> toFeatureVector() const;
88
90 static bool isSupportedExtension(StringRef Ext);
92 static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
93 unsigned MinorVersion);
95 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
96 static std::string getTargetFeatureForExtension(StringRef Ext);
97
98private:
99 RISCVISAInfo(unsigned XLen)
100 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
101
102 unsigned XLen;
103 unsigned FLen;
104 unsigned MinVLen;
105 unsigned MaxELen, MaxELenFp;
106
108
109 void addExtension(StringRef ExtName, unsigned MajorVersion,
110 unsigned MinorVersion);
111
112 Error checkDependency();
113
114 void updateImplication();
115 void updateCombination();
116 void updateFLen();
117 void updateMinVLen();
118 void updateMaxELen();
119};
120
121} // namespace llvm
122
123#endif
This file defines the StringMap class.
Value * RHS
Value * LHS
Tagged union holding either a T or a Error.
Definition: Error.h:474
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
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
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > postProcessAndChecking(std::unique_ptr< RISCVISAInfo > &&ISAInfo)
std::vector< std::string > toFeatureVector() const
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
void toFeatures(std::vector< StringRef > &Features, llvm::function_ref< StringRef(const Twine &)> StrAlloc, bool AddAllExtensions) const
Convert RISC-V ISA info to a feature vector.
RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
Definition: RISCVISAInfo.h:47
const OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:75
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:82
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)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
An efficient, type-erasing, non-owning reference to a callable.
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:36
bool operator()(const std::string &LHS, const std::string &RHS) const
Definition: RISCVISAInfo.h:37