LLVM 23.0.0git
RISCVTargetParser.h
Go to the documentation of this file.
1//===-- RISCVTargetParser - Parser for target features ----------*- 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// This file implements a target parser to recognise hardware features
10// for RISC-V CPUs.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGETPARSER_RISCVTARGETPARSER_H
15#define LLVM_TARGETPARSER_RISCVTARGETPARSER_H
16
17#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Error.h"
22
23namespace llvm {
24
25class Triple;
26
27namespace RISCV {
28
29struct CPUModel {
33
34 bool isValid() const { return MVendorID != 0 && MArchID != 0 && MImpID != 0; }
35
36 bool operator==(const CPUModel &Other) const {
37 return MVendorID == Other.MVendorID && MArchID == Other.MArchID &&
38 MImpID == Other.MImpID;
39 }
40};
41
50
51/// Fatal errors encountered during parsing.
52struct ParserError : public ErrorInfo<ParserError, StringError> {
54 explicit ParserError(const Twine &S)
56 static char ID;
57};
58
59/// Warnings encountered during parsing.
60struct ParserWarning : public ErrorInfo<ParserWarning, StringError> {
62 explicit ParserWarning(const Twine &S)
64 static char ID;
65};
66
67// We use 64 bits as the known part in the scalable vector types.
68static constexpr unsigned RVVBitsPerBlock = 64;
69static constexpr unsigned RVVBytesPerBlock = RVVBitsPerBlock / 8;
70
72 SmallVectorImpl<std::string> &EnabledFeatures,
73 bool NeedPlus = false);
75LLVM_ABI void
77 SmallVectorImpl<StringRef> &Directives);
78/// Parse the tune feature string with the respective processor. If \p ProcName
79/// is empty, directives are not filtered by processor.
82 SmallVectorImpl<std::string> &TuneFeatures);
83LLVM_ABI bool parseCPU(StringRef CPU, bool IsRV64);
84LLVM_ABI bool parseTuneCPU(StringRef CPU, bool IsRV64);
87 bool IsRV64);
89 bool IsRV64);
95
96} // namespace RISCV
97
98namespace RISCVVType {
109
110enum {
114};
115
116// Is this a SEW value that can be encoded into the VTYPE format.
117inline static bool isValidSEW(unsigned SEW) {
118 return isPowerOf2_32(SEW) && SEW >= 8 && SEW <= 64;
119}
120
121// Is this a LMUL value that can be encoded into the VTYPE format.
122inline static bool isValidLMUL(unsigned LMUL, bool Fractional) {
123 return isPowerOf2_32(LMUL) && LMUL <= 8 && (!Fractional || LMUL != 1);
124}
125
126LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic,
127 bool MaskAgnostic, bool AltFmt = false);
128
129LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt);
130
131inline static VLMUL getVLMUL(unsigned VType) {
132 unsigned VLMul = VType & 0x7;
133 return static_cast<VLMUL>(VLMul);
134}
135
136// Decode VLMUL into 1,2,4,8 and fractional indicator.
137LLVM_ABI std::pair<unsigned, bool> decodeVLMUL(VLMUL VLMul);
138
139inline static VLMUL encodeLMUL(unsigned LMUL, bool Fractional) {
140 assert(isValidLMUL(LMUL, Fractional) && "Unsupported LMUL");
141 unsigned LmulLog2 = Log2_32(LMUL);
142 return static_cast<VLMUL>(Fractional ? 8 - LmulLog2 : LmulLog2);
143}
144
145inline static unsigned decodeVSEW(unsigned VSEW) {
146 assert(VSEW < 8 && "Unexpected VSEW value");
147 return 1 << (VSEW + 3);
148}
149
150inline static unsigned encodeSEW(unsigned SEW) {
151 assert(isValidSEW(SEW) && "Unexpected SEW value");
152 return Log2_32(SEW) - 3;
153}
154
155inline static unsigned getSEW(unsigned VType) {
156 unsigned VSEW = (VType >> 3) & 0x7;
157 return decodeVSEW(VSEW);
158}
159
160inline static unsigned decodeTWiden(unsigned TWiden) {
161 assert((TWiden == 1 || TWiden == 2 || TWiden == 3) &&
162 "Unexpected TWiden value");
163 return 1 << (TWiden - 1);
164}
165
166inline static bool hasXSfmmWiden(unsigned VType) {
167 unsigned TWiden = (VType >> 9) & 0x3;
168 return TWiden != 0;
169}
170
171inline static unsigned getXSfmmWiden(unsigned VType) {
172 unsigned TWiden = (VType >> 9) & 0x3;
173 assert(TWiden != 0 && "Invalid widen value");
174 return 1 << (TWiden - 1);
175}
176
177static inline bool isValidXSfmmVType(unsigned VTypeI) {
178 return (VTypeI & ~0x738) == 0 && RISCVVType::hasXSfmmWiden(VTypeI) &&
179 RISCVVType::getSEW(VTypeI) * RISCVVType::getXSfmmWiden(VTypeI) <= 64;
180}
181
182inline static bool isTailAgnostic(unsigned VType) { return VType & 0x40; }
183
184inline static bool isMaskAgnostic(unsigned VType) { return VType & 0x80; }
185
186inline static bool isAltFmt(unsigned VType) { return VType & 0x100; }
187
188LLVM_ABI void printVType(unsigned VType, raw_ostream &OS);
189
190LLVM_ABI void printXSfmmVType(unsigned VType, raw_ostream &OS);
191
192LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul);
193
194LLVM_ABI std::optional<VLMUL> getSameRatioLMUL(unsigned Ratio, unsigned EEW);
195} // namespace RISCVVType
196
197} // namespace llvm
198
199#endif
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringError(std::string &&S, std::error_code EC, bool PrintMsgOnly)
Definition Error.cpp:142
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:882
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
static bool isTailAgnostic(unsigned VType)
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
static unsigned decodeVSEW(unsigned VSEW)
LLVM_ABI void printXSfmmVType(unsigned VType, raw_ostream &OS)
LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt)
static unsigned getXSfmmWiden(unsigned VType)
static bool isValidLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI std::optional< VLMUL > getSameRatioLMUL(unsigned Ratio, unsigned EEW)
static bool isMaskAgnostic(unsigned VType)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
static bool hasXSfmmWiden(unsigned VType)
static unsigned encodeSEW(unsigned SEW)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
static bool isValidSEW(unsigned SEW)
LLVM_ABI void printVType(unsigned VType, raw_ostream &OS)
static bool isValidXSfmmVType(unsigned VTypeI)
static unsigned decodeTWiden(unsigned TWiden)
static bool isAltFmt(unsigned VType)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
static unsigned getSEW(unsigned VType)
static VLMUL getVLMUL(unsigned VType)
LLVM_ABI bool hasFastVectorUnalignedAccess(StringRef CPU)
LLVM_ABI void getFeaturesForCPU(StringRef CPU, SmallVectorImpl< std::string > &EnabledFeatures, bool NeedPlus=false)
LLVM_ABI void fillValidTuneCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
LLVM_ABI CPUModel getCPUModel(StringRef CPU)
LLVM_ABI Error parseTuneFeatureString(StringRef ProcName, StringRef TFString, SmallVectorImpl< std::string > &TuneFeatures)
Parse the tune feature string with the respective processor.
LLVM_ABI void getAllTuneFeatures(SmallVectorImpl< StringRef > &TuneFeatures)
LLVM_ABI StringRef getMArchFromMcpu(StringRef CPU)
LLVM_ABI bool parseCPU(StringRef CPU, bool IsRV64)
LLVM_ABI bool hasFastScalarUnalignedAccess(StringRef CPU)
static constexpr unsigned RVVBitsPerBlock
LLVM_ABI bool hasValidCPUModel(StringRef CPU)
LLVM_ABI StringRef getCPUNameFromCPUModel(const CPUModel &Model)
static constexpr unsigned RVVBytesPerBlock
LLVM_ABI bool parseTuneCPU(StringRef CPU, bool IsRV64)
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
LLVM_ABI void getCPUConfigurableTuneFeatures(StringRef CPU, SmallVectorImpl< StringRef > &Directives)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:331
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
@ Other
Any other memory.
Definition ModRef.h:68
bool operator==(const CPUModel &Other) const