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>
132 : TailPolicy(TailPolicy), MaskPolicy(MaskPolicy) {}
159 return TailPolicy ==
Other.TailPolicy && MaskPolicy ==
Other.MaskPolicy;
166 if (MaskPolicy !=
Other.MaskPolicy)
167 return Other.MaskPolicy < MaskPolicy;
168 return TailPolicy <
Other.TailPolicy;
191 return !(*
this == PD);
202 static std::optional<PrototypeDescriptor>
249 std::string
str()
const;
250 std::optional<unsigned>
getScale(
unsigned ElementBitwidth)
const;
266 bool IsPointer =
false;
268 bool IsImmediate =
false;
270 bool IsConstant =
false;
271 unsigned ElementBitwidth = 0;
274 bool IsTuple =
false;
277 std::string BuiltinStr;
278 std::string ClangBuiltinStr;
280 std::string ShortStr;
282 enum class FixedLMULType { LargerThan, SmallerThan, SmallerOrEqual };
303 if (ShortStr.empty())
309 bool isScalar()
const {
return Scale && *Scale == 0; }
310 bool isVector()
const {
return Scale && *Scale != 0; }
312 return isVector() && ElementBitwidth == Width;
323 return isFloat() && ElementBitwidth == Width;
333 assert(NF > 1 && NF <= 8 &&
"Only legal NF should be fetched");
339 bool verifyType()
const;
342 void applyBasicType();
348 void applyLog2EEW(
unsigned Log2EEW);
349 void applyFixedSEW(
unsigned NewSEW);
350 void applyFixedLog2LMUL(
int Log2LMUL,
enum FixedLMULType
Type);
353 void initBuiltinStr();
355 void initClangBuiltinStr();
366 std::unordered_map<uint64_t, RVVType> LegalTypes;
367 std::set<uint64_t> IllegalTypes;
374 std::optional<RVVTypes>
388llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
enum PolicyScheme PS);
396 std::string BuiltinName;
398 std::string OverloadedName;
401 bool HasMaskedOffOperand;
404 bool SupportOverloading;
405 bool HasBuiltinAlias;
406 std::string ManualCodegen;
411 std::vector<int64_t> IntrinsicTypes;
413 bool HasSegInstSEW =
false;
418 RVVIntrinsic(llvm::StringRef Name, llvm::StringRef Suffix,
419 llvm::StringRef OverloadedName, llvm::StringRef OverloadedSuffix,
420 llvm::StringRef IRName,
bool IsMasked,
bool HasMaskedOffOperand,
421 bool HasVL,
PolicyScheme Scheme,
bool SupportOverloading,
422 bool HasBuiltinAlias, llvm::StringRef ManualCodegen,
424 const std::vector<int64_t> &IntrinsicTypes,
unsigned NF,
425 bool HasSegInstSEW,
Policy PolicyAttrs,
bool HasFRMRoundModeOp,
426 unsigned TWiden,
bool AltFmt);
433 bool hasVL()
const {
return HasVL; }
449 unsigned getNF()
const {
return NF; }
453 return IntrinsicTypes;
464 if (PolicyAttrs.isTUMAPolicy())
466 if (PolicyAttrs.isTAMAPolicy())
468 if (PolicyAttrs.isTUMUPolicy())
470 if (PolicyAttrs.isTAMUPolicy())
473 llvm_unreachable(
"unsupport policy");
486 bool IsMasked,
bool HasMaskedOffOperand,
487 bool MaskedPrototypeHasResultMask,
bool HasVL,
489 Policy PolicyAttrs,
bool IsTuple);
496 std::string &Name, std::string &BuiltinName,
497 std::string &OverloadedName,
498 Policy &PolicyAttrs,
bool HasFRMRoundModeOp,
557llvm::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
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, bool HasSegInstSEW, Policy PolicyAttrs, bool HasFRMRoundModeOp, unsigned TWiden, bool AltFmt)
bool hasPassthruOperand() const
static llvm::SmallVector< Policy > getSupportedMaskedPolicies(bool HasTailPolicy, bool HasMaskPolicy)
static llvm::SmallVector< PrototypeDescriptor > computeBuiltinTypes(llvm::ArrayRef< PrototypeDescriptor > Prototype, bool IsMasked, bool HasMaskedOffOperand, bool MaskedPrototypeHasResultMask, bool HasVL, unsigned NF, PolicyScheme DefaultScheme, Policy PolicyAttrs, bool IsTuple)
llvm::StringRef getBuiltinName() const
llvm::StringRef getIRName() const
const std::vector< int64_t > & getIntrinsicTypes() const
bool hasMaskedOffOperand() const
bool hasSegInstSEW() const
Policy getPolicyAttrs() const
unsigned getTWiden() const
llvm::StringRef getOverloadedName() const
static std::string getSuffixStr(RVVTypeCache &TypeCache, BasicType Type, int Log2LMUL, llvm::ArrayRef< PrototypeDescriptor > PrototypeDescriptors)
bool hasPolicyOperand() const
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_MARK_AS_BITMASK_ENUM
llvm::SmallVector< PrototypeDescriptor > parsePrototypes(llvm::StringRef Prototypes)
std::vector< RVVTypePtr > RVVTypes
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
Top level wrappers for InstallAPI frontend operations.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
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
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
constexpr PrototypeDescriptor(uint8_t PT, uint8_t VTM, uint16_t TM)
uint8_t OverloadedSuffixSize
bool MaskedPrototypeHasResultMask
uint16_t OverloadedSuffixIndex
uint8_t MaskedPolicyScheme
const char * RequiredExtensions
const char * OverloadedName
uint8_t UnMaskedPolicyScheme