LLVM 22.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"
21
22namespace llvm {
23
24class Triple;
25
26namespace RISCV {
27
28struct CPUModel {
32
33 bool isValid() const { return MVendorID != 0 && MArchID != 0 && MImpID != 0; }
34
35 bool operator==(const CPUModel &Other) const {
36 return MVendorID == Other.MVendorID && MArchID == Other.MArchID &&
37 MImpID == Other.MImpID;
38 }
39};
40
41struct CPUInfo {
47 bool is64Bit() const { return DefaultMarch.starts_with("rv64"); }
48};
49
50// We use 64 bits as the known part in the scalable vector types.
51static constexpr unsigned RVVBitsPerBlock = 64;
52static constexpr unsigned RVVBytesPerBlock = RVVBitsPerBlock / 8;
53
55 SmallVectorImpl<std::string> &EnabledFeatures,
56 bool NeedPlus = false);
57LLVM_ABI bool parseCPU(StringRef CPU, bool IsRV64);
58LLVM_ABI bool parseTuneCPU(StringRef CPU, bool IsRV64);
61 bool IsRV64);
63 bool IsRV64);
69
70} // namespace RISCV
71
72namespace RISCVVType {
73enum VLMUL : uint8_t {
74 LMUL_1 = 0,
82};
83
84enum {
88};
89
90// Is this a SEW value that can be encoded into the VTYPE format.
91inline static bool isValidSEW(unsigned SEW) {
92 return isPowerOf2_32(SEW) && SEW >= 8 && SEW <= 64;
93}
94
95// Is this a LMUL value that can be encoded into the VTYPE format.
96inline static bool isValidLMUL(unsigned LMUL, bool Fractional) {
97 return isPowerOf2_32(LMUL) && LMUL <= 8 && (!Fractional || LMUL != 1);
98}
99
100LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic,
101 bool MaskAgnostic, bool AltFmt = false);
102
103LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt);
104
105inline static VLMUL getVLMUL(unsigned VType) {
106 unsigned VLMul = VType & 0x7;
107 return static_cast<VLMUL>(VLMul);
108}
109
110// Decode VLMUL into 1,2,4,8 and fractional indicator.
111LLVM_ABI std::pair<unsigned, bool> decodeVLMUL(VLMUL VLMul);
112
113inline static VLMUL encodeLMUL(unsigned LMUL, bool Fractional) {
114 assert(isValidLMUL(LMUL, Fractional) && "Unsupported LMUL");
115 unsigned LmulLog2 = Log2_32(LMUL);
116 return static_cast<VLMUL>(Fractional ? 8 - LmulLog2 : LmulLog2);
117}
118
119inline static unsigned decodeVSEW(unsigned VSEW) {
120 assert(VSEW < 8 && "Unexpected VSEW value");
121 return 1 << (VSEW + 3);
122}
123
124inline static unsigned encodeSEW(unsigned SEW) {
125 assert(isValidSEW(SEW) && "Unexpected SEW value");
126 return Log2_32(SEW) - 3;
127}
128
129inline static unsigned getSEW(unsigned VType) {
130 unsigned VSEW = (VType >> 3) & 0x7;
131 return decodeVSEW(VSEW);
132}
133
134inline static unsigned decodeTWiden(unsigned TWiden) {
135 assert((TWiden == 1 || TWiden == 2 || TWiden == 3) &&
136 "Unexpected TWiden value");
137 return 1 << (TWiden - 1);
138}
139
140inline static bool hasXSfmmWiden(unsigned VType) {
141 unsigned TWiden = (VType >> 9) & 0x3;
142 return TWiden != 0;
143}
144
145inline static unsigned getXSfmmWiden(unsigned VType) {
146 unsigned TWiden = (VType >> 9) & 0x3;
147 assert(TWiden != 0 && "Invalid widen value");
148 return 1 << (TWiden - 1);
149}
150
151static inline bool isValidXSfmmVType(unsigned VTypeI) {
152 return (VTypeI & ~0x738) == 0 && RISCVVType::hasXSfmmWiden(VTypeI) &&
153 RISCVVType::getSEW(VTypeI) * RISCVVType::getXSfmmWiden(VTypeI) <= 64;
154}
155
156inline static bool isTailAgnostic(unsigned VType) { return VType & 0x40; }
157
158inline static bool isMaskAgnostic(unsigned VType) { return VType & 0x80; }
159
160inline static bool isAltFmt(unsigned VType) { return VType & 0x100; }
161
162LLVM_ABI void printVType(unsigned VType, raw_ostream &OS);
163
164LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul);
165
166LLVM_ABI std::optional<VLMUL> getSameRatioLMUL(unsigned SEW, VLMUL VLMUL,
167 unsigned EEW);
168} // namespace RISCVVType
169
170} // namespace llvm
171
172#endif
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:862
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:269
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 std::optional< VLMUL > getSameRatioLMUL(unsigned SEW, VLMUL VLMUL, unsigned EEW)
LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt)
static unsigned getXSfmmWiden(unsigned VType)
static bool isValidLMUL(unsigned LMUL, bool Fractional)
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 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)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:336
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:288
@ Other
Any other memory.
StringLiteral DefaultMarch
bool operator==(const CPUModel &Other) const