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
19namespace llvm {
21 unsigned MajorVersion;
22 unsigned MinorVersion;
23};
24
26public:
27 RISCVISAInfo(const RISCVISAInfo &) = delete;
29
30 static bool compareExtension(const std::string &LHS, const std::string &RHS);
31
32 /// Helper class for OrderedExtensionMap.
34 bool operator()(const std::string &LHS, const std::string &RHS) const {
35 return compareExtension(LHS, RHS);
36 }
37 };
38
39 /// OrderedExtensionMap is std::map, it's specialized to keep entries
40 /// in canonical order of extension.
41 typedef std::map<std::string, RISCVExtensionInfo, ExtensionComparator>
43
44 RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
45 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0), Exts(Exts) {}
46
47 /// Parse RISCV ISA info from arch string.
49 parseArchString(StringRef Arch, bool EnableExperimentalExtension,
50 bool ExperimentalExtensionVersionCheck = true,
51 bool IgnoreUnknown = false);
52
53 /// Parse RISCV ISA info from an arch string that is already in normalized
54 /// form (as defined in the psABI). Unlike parseArchString, this function
55 /// will not error for unrecognized extension names or extension versions.
58
59 /// Parse RISCV ISA info from feature vector.
61 parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
62
63 /// Convert RISCV ISA info to a feature vector.
64 void toFeatures(std::vector<StringRef> &Features,
65 llvm::function_ref<StringRef(const Twine &)> StrAlloc,
66 bool AddAllExtensions) const;
67
68 const OrderedExtensionMap &getExtensions() const { return Exts; };
69
70 unsigned getXLen() const { return XLen; };
71 unsigned getFLen() const { return FLen; };
72 unsigned getMinVLen() const { return MinVLen; }
73 unsigned getMaxVLen() const { return 65536; }
74 unsigned getMaxELen() const { return MaxELen; }
75 unsigned getMaxELenFp() const { return MaxELenFp; }
76
77 bool hasExtension(StringRef Ext) const;
78 std::string toString() const;
79 std::vector<std::string> toFeatureVector() const;
81
83 static bool isSupportedExtension(StringRef Ext);
84 static bool isSupportedExtension(StringRef Ext, unsigned MajorVersion,
85 unsigned MinorVersion);
87 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
88
89private:
90 RISCVISAInfo(unsigned XLen)
91 : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
92
93 unsigned XLen;
94 unsigned FLen;
95 unsigned MinVLen;
96 unsigned MaxELen, MaxELenFp;
97
99
100 void addExtension(StringRef ExtName, unsigned MajorVersion,
101 unsigned MinorVersion);
102
103 Error checkDependency();
104
105 void updateImplication();
106 void updateCombination();
107 void updateFLen();
108 void updateMinVLen();
109 void updateMaxELen();
110};
111
112} // namespace llvm
113
114#endif
Value * RHS
Value * LHS
Tagged union holding either a T or a Error.
Definition: Error.h:470
static bool isSupportedExtensionFeature(StringRef Ext)
RISCVISAInfo & operator=(const RISCVISAInfo &)=delete
unsigned getMinVLen() const
Definition: RISCVISAInfo.h:72
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseNormalizedArchString(StringRef Arch)
Parse RISCV 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:71
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:42
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:73
static bool isSupportedExtension(StringRef Ext)
static llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatures(unsigned XLen, const std::vector< std::string > &Features)
Parse RISCV ISA info from feature vector.
unsigned getMaxELen() const
Definition: RISCVISAInfo.h:74
unsigned getXLen() const
Definition: RISCVISAInfo.h:70
void toFeatures(std::vector< StringRef > &Features, llvm::function_ref< StringRef(const Twine &)> StrAlloc, bool AddAllExtensions) const
Convert RISCV ISA info to a feature vector.
RISCVISAInfo(unsigned XLen, OrderedExtensionMap &Exts)
Definition: RISCVISAInfo.h:44
const OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:68
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:75
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.
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
Helper class for OrderedExtensionMap.
Definition: RISCVISAInfo.h:33
bool operator()(const std::string &LHS, const std::string &RHS) const
Definition: RISCVISAInfo.h:34