LLVM 22.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"
15#include "llvm/Support/Error.h"
17
18#include <map>
19#include <set>
20#include <string>
21#include <vector>
22
23namespace llvm {
24
26public:
27 RISCVISAInfo(const RISCVISAInfo &) = delete;
29
30 /// Parse RISC-V ISA info from arch string.
31 /// If IgnoreUnknown is set, any unrecognised extension names or
32 /// extensions with unrecognised versions will be silently dropped, except
33 /// for the special case of the base 'i' and 'e' extensions, where the
34 /// default version will be used (as ignoring the base is not possible).
36 parseArchString(StringRef Arch, bool EnableExperimentalExtension,
37 bool ExperimentalExtensionVersionCheck = true);
38
39 /// Parse RISC-V ISA info from an arch string that is already in normalized
40 /// form (as defined in the psABI). Unlike parseArchString, this function
41 /// will not error for unrecognized extension names or extension versions.
44
45 /// Parse RISC-V ISA info from feature vector.
47 parseFeatures(unsigned XLen, const std::vector<std::string> &Features);
48
50 createFromExtMap(unsigned XLen,
52
53 /// Convert RISC-V ISA info to a feature vector.
54 LLVM_ABI std::vector<std::string> toFeatures(bool AddAllExtensions = false,
55 bool IgnoreUnknown = true) const;
56
58 return Exts;
59 }
60
61 unsigned getXLen() const { return XLen; }
62 unsigned getFLen() const { return FLen; }
63 unsigned getMinVLen() const { return MinVLen; }
64 unsigned getMaxVLen() const { return 65536; }
65 unsigned getMaxELen() const { return MaxELen; }
66 unsigned getMaxELenFp() const { return MaxELenFp; }
67
68 LLVM_ABI bool hasExtension(StringRef Ext) const;
69 LLVM_ABI std::string toString() const;
71
76 unsigned MajorVersion,
77 unsigned MinorVersion);
78 LLVM_ABI static std::string getTargetFeatureForExtension(StringRef Ext);
79
81 LLVM_ABI static void
82 printEnabledExtensions(bool IsRV64, std::set<StringRef> &EnabledFeatureNames,
83 StringMap<StringRef> &DescMap);
84
85 /// Return the group id and bit position of __riscv_feature_bits. Returns
86 /// <-1, -1> if not supported.
87 LLVM_ABI static std::pair<int, int> getRISCVFeaturesBitsInfo(StringRef Ext);
88
89 // The maximum value of the group ID obtained from getRISCVFeaturesBitsInfo.
90 static constexpr unsigned FeatureBitSize = 2;
91
92private:
93 RISCVISAInfo(unsigned XLen) : XLen(XLen) {}
94
95 unsigned XLen;
96 unsigned FLen = 0;
97 unsigned MinVLen = 0;
98 unsigned MaxELen = 0, MaxELenFp = 0;
99
101
102 Error checkDependency();
103
104 void updateImplication();
105 void updateCombination();
106
107 /// Update FLen, MinVLen, MaxELen, and MaxELenFp.
108 void updateImpliedLengths();
109
111 postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo);
112};
113
114} // namespace llvm
115
116#endif
This file defines the StringMap class.
#define LLVM_ABI
Definition: Compiler.h:213
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
static LLVM_ABI bool isSupportedExtensionFeature(StringRef Ext)
static constexpr unsigned FeatureBitSize
Definition: RISCVISAInfo.h:90
RISCVISAInfo & operator=(const RISCVISAInfo &)=delete
static LLVM_ABI std::string getTargetFeatureForExtension(StringRef Ext)
unsigned getMinVLen() const
Definition: RISCVISAInfo.h:63
static LLVM_ABI 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...
LLVM_ABI bool hasExtension(StringRef Ext) const
RISCVISAInfo(const RISCVISAInfo &)=delete
unsigned getFLen() const
Definition: RISCVISAInfo.h:62
LLVM_ABI std::string toString() const
const RISCVISAUtils::OrderedExtensionMap & getExtensions() const
Definition: RISCVISAInfo.h:57
LLVM_ABI StringRef computeDefaultABI() const
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISC-V ISA info from arch string.
unsigned getMaxVLen() const
Definition: RISCVISAInfo.h:64
static LLVM_ABI bool isSupportedExtension(StringRef Ext)
static LLVM_ABI void printEnabledExtensions(bool IsRV64, std::set< StringRef > &EnabledFeatureNames, StringMap< StringRef > &DescMap)
static LLVM_ABI void printSupportedExtensions(StringMap< StringRef > &DescMap)
static LLVM_ABI 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:65
unsigned getXLen() const
Definition: RISCVISAInfo.h:61
static LLVM_ABI std::pair< int, int > getRISCVFeaturesBitsInfo(StringRef Ext)
Return the group id and bit position of __riscv_feature_bits.
unsigned getMaxELenFp() const
Definition: RISCVISAInfo.h:66
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > createFromExtMap(unsigned XLen, const RISCVISAUtils::OrderedExtensionMap &Exts)
LLVM_ABI std::vector< std::string > toFeatures(bool AddAllExtensions=false, bool IgnoreUnknown=true) const
Convert RISC-V ISA info to a feature vector.
static LLVM_ABI bool isSupportedExtensionWithVersion(StringRef Ext)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::map< std::string, ExtensionVersion, ExtensionComparator > OrderedExtensionMap
OrderedExtensionMap is std::map, it's specialized to keep entries in canonical order of extension.
Definition: RISCVISAUtils.h:44
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18