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