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>
129 : TailPolicy(TailPolicy), MaskPolicy(MaskPolicy) {}
156 return TailPolicy ==
Other.TailPolicy && MaskPolicy ==
Other.MaskPolicy;
163 if (MaskPolicy !=
Other.MaskPolicy)
164 return Other.MaskPolicy < MaskPolicy;
165 return TailPolicy <
Other.TailPolicy;
188 return !(*
this == PD);
199 static std::optional<PrototypeDescriptor>
246 std::string
str()
const;
247 std::optional<unsigned>
getScale(
unsigned ElementBitwidth)
const;
263 bool IsPointer =
false;
265 bool IsImmediate =
false;
267 bool IsConstant =
false;
268 unsigned ElementBitwidth = 0;
271 bool IsTuple =
false;
274 std::string BuiltinStr;
275 std::string ClangBuiltinStr;
277 std::string ShortStr;
279 enum class FixedLMULType { LargerThan, SmallerThan, SmallerOrEqual };
300 if (ShortStr.empty())
306 bool isScalar()
const {
return Scale && *Scale == 0; }
307 bool isVector()
const {
return Scale && *Scale != 0; }
309 return isVector() && ElementBitwidth == Width;
320 return isFloat() && ElementBitwidth == Width;
330 assert(NF > 1 && NF <= 8 &&
"Only legal NF should be fetched");
336 bool verifyType()
const;
339 void applyBasicType();
345 void applyLog2EEW(
unsigned Log2EEW);
346 void applyFixedSEW(
unsigned NewSEW);
347 void applyFixedLog2LMUL(
int Log2LMUL,
enum FixedLMULType
Type);
350 void initBuiltinStr();
352 void initClangBuiltinStr();
363 std::unordered_map<uint64_t, RVVType> LegalTypes;
364 std::set<uint64_t> IllegalTypes;
371 std::optional<RVVTypes>
385llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
enum PolicyScheme PS);
393 std::string BuiltinName;
395 std::string OverloadedName;
398 bool HasMaskedOffOperand;
401 bool SupportOverloading;
402 bool HasBuiltinAlias;
403 std::string ManualCodegen;
408 std::vector<int64_t> IntrinsicTypes;
414 RVVIntrinsic(llvm::StringRef Name, llvm::StringRef Suffix,
415 llvm::StringRef OverloadedName, llvm::StringRef OverloadedSuffix,
416 llvm::StringRef IRName,
bool IsMasked,
bool HasMaskedOffOperand,
417 bool HasVL,
PolicyScheme Scheme,
bool SupportOverloading,
418 bool HasBuiltinAlias, llvm::StringRef ManualCodegen,
420 const std::vector<int64_t> &IntrinsicTypes,
unsigned NF,
421 Policy PolicyAttrs,
bool HasFRMRoundModeOp,
unsigned TWiden,
429 bool hasVL()
const {
return HasVL; }
445 unsigned getNF()
const {
return NF; }
448 return IntrinsicTypes;
459 if (PolicyAttrs.isTUMAPolicy())
461 if (PolicyAttrs.isTAMAPolicy())
463 if (PolicyAttrs.isTUMUPolicy())
465 if (PolicyAttrs.isTAMUPolicy())
468 llvm_unreachable(
"unsupport policy");
481 bool IsMasked,
bool HasMaskedOffOperand,
bool HasVL,
483 Policy PolicyAttrs,
bool IsTuple);
490 std::string &Name, std::string &BuiltinName,
491 std::string &OverloadedName,
492 Policy &PolicyAttrs,
bool HasFRMRoundModeOp,
550llvm::raw_ostream &operator<<(
llvm::raw_ostream &OS,
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
static llvm::SmallVector< PrototypeDescriptor > computeBuiltinTypes(llvm::ArrayRef< PrototypeDescriptor > Prototype, bool IsMasked, bool HasMaskedOffOperand, bool HasVL, unsigned NF, PolicyScheme DefaultScheme, Policy PolicyAttrs, bool IsTuple)
unsigned getTWiden() const
llvm::StringRef getOverloadedName() const
static std::string getSuffixStr(RVVTypeCache &TypeCache, BasicType Type, int Log2LMUL, llvm::ArrayRef< PrototypeDescriptor > PrototypeDescriptors)
bool hasPolicyOperand() const
RVVIntrinsic(llvm::StringRef Name, llvm::StringRef Suffix, llvm::StringRef OverloadedName, llvm::StringRef OverloadedSuffix, llvm::StringRef IRName, bool IsMasked, bool HasMaskedOffOperand, bool HasVL, PolicyScheme Scheme, bool SupportOverloading, bool HasBuiltinAlias, llvm::StringRef ManualCodegen, const RVVTypes &Types, const std::vector< int64_t > &IntrinsicTypes, unsigned NF, Policy PolicyAttrs, bool HasFRMRoundModeOp, unsigned TWiden, bool AltFmt)
bool hasManualCodegen() const
bool hasBuiltinAlias() const
static void updateNamesAndPolicy(bool IsMasked, bool HasPolicy, std::string &Name, std::string &BuiltinName, std::string &OverloadedName, Policy &PolicyAttrs, bool HasFRMRoundModeOp, bool AltFmt)
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
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()
friend class RVVTypeCache
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.
std::optional< unsigned > VScaleVal
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS)
llvm::SmallVector< PrototypeDescriptor > parsePrototypes(llvm::StringRef Prototypes)
std::vector< RVVTypePtr > RVVTypes
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
@ LLVM_MARK_AS_BITMASK_ENUM
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
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
uint16_t OverloadedSuffixIndex
uint8_t MaskedPolicyScheme
const char * RequiredExtensions
const char * OverloadedName
uint8_t UnMaskedPolicyScheme