9#ifndef CLANG_SUPPORT_RISCVVINTRINSICUTILS_H
10#define CLANG_SUPPORT_RISCVVINTRINSICUTILS_H
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/BitmaskEnum.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringRef.h"
20#include <unordered_map>
112 : TailPolicy(TailPolicy), MaskPolicy(MaskPolicy) {}
139 return TailPolicy == Other.TailPolicy && MaskPolicy == Other.MaskPolicy;
146 if (MaskPolicy != Other.MaskPolicy)
147 return Other.MaskPolicy < MaskPolicy;
148 return TailPolicy < Other.TailPolicy;
160 :
PT(static_cast<uint8_t>(
PT)),
VTM(static_cast<uint8_t>(
VTM)),
161 TM(static_cast<uint8_t>(
TM)) {}
170 return !(*
this == PD);
181 static std::optional<PrototypeDescriptor>
221 std::string
str()
const;
222 std::optional<unsigned>
getScale(
unsigned ElementBitwidth)
const;
238 bool IsPointer =
false;
240 bool IsImmediate =
false;
242 bool IsConstant =
false;
243 unsigned ElementBitwidth = 0;
247 std::string BuiltinStr;
248 std::string ClangBuiltinStr;
250 std::string ShortStr;
252 enum class FixedLMULType { LargerThan, SmallerThan };
273 if (ShortStr.empty())
279 bool isScalar()
const {
return Scale && *Scale == 0; }
280 bool isVector()
const {
return Scale && *Scale != 0; }
282 return isVector() && ElementBitwidth == Width;
292 return isFloat() && ElementBitwidth == Width;
303 bool verifyType()
const;
306 void applyBasicType();
312 void applyLog2EEW(
unsigned Log2EEW);
313 void applyFixedSEW(
unsigned NewSEW);
314 void applyFixedLog2LMUL(
int Log2LMUL,
enum FixedLMULType
Type);
317 void initBuiltinStr();
319 void initClangBuiltinStr();
330 std::unordered_map<uint64_t, RVVType> LegalTypes;
331 std::set<uint64_t> IllegalTypes;
338 std::optional<RVVTypes>
358 std::string BuiltinName;
360 std::string OverloadedName;
363 bool HasMaskedOffOperand;
366 bool SupportOverloading;
367 bool HasBuiltinAlias;
368 std::string ManualCodegen;
373 std::vector<int64_t> IntrinsicTypes;
378 RVVIntrinsic(llvm::StringRef Name, llvm::StringRef Suffix,
379 llvm::StringRef OverloadedName, llvm::StringRef OverloadedSuffix,
380 llvm::StringRef IRName,
bool IsMasked,
bool HasMaskedOffOperand,
381 bool HasVL,
PolicyScheme Scheme,
bool SupportOverloading,
382 bool HasBuiltinAlias, llvm::StringRef ManualCodegen,
384 const std::vector<int64_t> &IntrinsicTypes,
385 const std::vector<llvm::StringRef> &RequiredFeatures,
386 unsigned NF,
Policy PolicyAttrs);
392 llvm::StringRef
getName()
const {
return Name; }
395 bool hasVL()
const {
return HasVL; }
410 unsigned getNF()
const {
return NF; }
412 return IntrinsicTypes;
432 llvm_unreachable(
"unsupport policy");
445 bool IsMasked,
bool HasMaskedOffOperand,
bool HasVL,
454 std::string &Name, std::string &BuiltinName,
455 std::string &OverloadedName,
bool isTUMUPolicy() const
Policy(PolicyType TailPolicy)
bool isTUMAPolicy() const
bool operator==(const Policy &Other) const
bool isTAMUPolicy() const
bool operator!=(const Policy &Other) const
bool operator<(const Policy &Other) const
Policy(PolicyType TailPolicy, PolicyType MaskPolicy)
bool isTAMAPolicy() const
bool hasPassthruOperand() const
static llvm::SmallVector< Policy > getSupportedMaskedPolicies(bool HasTailPolicy, bool HasMaskPolicy)
llvm::StringRef getBuiltinName() const
llvm::StringRef getIRName() const
const std::vector< int64_t > & getIntrinsicTypes() const
bool hasMaskedOffOperand() const
Policy getPolicyAttrs() const
llvm::StringRef getOverloadedName() const
static std::string getSuffixStr(RVVTypeCache &TypeCache, BasicType Type, int Log2LMUL, llvm::ArrayRef< PrototypeDescriptor > PrototypeDescriptors)
bool hasPolicyOperand() const
static void updateNamesAndPolicy(bool IsMasked, bool HasPolicy, std::string &Name, std::string &BuiltinName, std::string &OverloadedName, Policy &PolicyAttrs)
static llvm::SmallVector< PrototypeDescriptor > computeBuiltinTypes(llvm::ArrayRef< PrototypeDescriptor > Prototype, bool IsMasked, bool HasMaskedOffOperand, bool HasVL, unsigned NF, PolicyScheme DefaultScheme, Policy PolicyAttrs)
bool hasManualCodegen() const
bool hasBuiltinAlias() const
static llvm::SmallVector< Policy > getSupportedUnMaskedPolicies()
RVVTypePtr getOutputType() const
unsigned getPolicyAttrsBits() const
bool supportOverloading() const
llvm::StringRef getManualCodegen() const
std::string getBuiltinTypeStr() const
const RVVTypes & getInputTypes() const
llvm::StringRef getName() const
PolicyScheme getPolicyScheme() const
std::optional< RVVTypePtr > computeType(BasicType BT, int Log2LMUL, PrototypeDescriptor Proto)
std::optional< RVVTypes > computeTypes(BasicType BT, int Log2LMUL, unsigned NF, llvm::ArrayRef< PrototypeDescriptor > Prototype)
Compute output and input types by applying different config (basic type and LMUL with type transforme...
const std::string & getTypeStr() const
ScalarTypeKind getScalarType() const
bool isFloatVector(unsigned Width) const
bool isSignedInteger() const
const std::string & getShortStr()
const std::string & getClangBuiltinStr() const
VScaleVal getScale() const
bool isFloat(unsigned Width) const
bool isVector(unsigned Width) const
unsigned getElementBitwidth() const
const std::string & getBuiltinStr() const
The base class of the type hierarchy.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const RVVIntrinsicRecord &RVVInstrRecord)
llvm::SmallVector< PrototypeDescriptor > parsePrototypes(llvm::StringRef Prototypes)
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
std::optional< unsigned > VScaleVal
@ LLVM_MARK_AS_BITMASK_ENUM
std::vector< RVVTypePtr > RVVTypes
YAML serialization mapping.
std::optional< unsigned > getScale(unsigned ElementBitwidth) const
void MulLog2LMUL(int Log2LMUL)
bool operator!=(const PrototypeDescriptor &PD) const
static std::optional< PrototypeDescriptor > parsePrototypeDescriptor(llvm::StringRef PrototypeStr)
static const PrototypeDescriptor VL
constexpr PrototypeDescriptor()=default
static const PrototypeDescriptor Mask
constexpr PrototypeDescriptor(uint8_t PT, uint8_t VTM, uint8_t TM)
static const PrototypeDescriptor Vector
constexpr PrototypeDescriptor(BaseTypeModifier PT, VectorTypeModifier VTM=VectorTypeModifier::NoModifier, TypeModifier TM=TypeModifier::NoModifier)
bool operator==(const PrototypeDescriptor &PD) const
bool operator<(const PrototypeDescriptor &PD) const
uint8_t OverloadedSuffixSize
uint8_t RequiredExtensions
uint16_t OverloadedSuffixIndex
uint8_t MaskedPolicyScheme
const char * OverloadedName
uint8_t UnMaskedPolicyScheme