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>
126 : TailPolicy(TailPolicy), MaskPolicy(MaskPolicy) {}
153 return TailPolicy == Other.TailPolicy && MaskPolicy == Other.MaskPolicy;
160 if (MaskPolicy != Other.MaskPolicy)
161 return Other.MaskPolicy < MaskPolicy;
162 return TailPolicy < Other.TailPolicy;
174 :
PT(static_cast<uint8_t>(
PT)),
VTM(static_cast<uint8_t>(
VTM)),
175 TM(static_cast<uint8_t>(
TM)) {}
184 return !(*
this == PD);
195 static std::optional<PrototypeDescriptor>
236 std::string
str()
const;
237 std::optional<unsigned>
getScale(
unsigned ElementBitwidth)
const;
253 bool IsPointer =
false;
255 bool IsImmediate =
false;
257 bool IsConstant =
false;
258 unsigned ElementBitwidth = 0;
261 bool IsTuple =
false;
264 std::string BuiltinStr;
265 std::string ClangBuiltinStr;
267 std::string ShortStr;
269 enum class FixedLMULType { LargerThan, SmallerThan, SmallerOrEqual };
290 if (ShortStr.empty())
296 bool isScalar()
const {
return Scale && *Scale == 0; }
297 bool isVector()
const {
return Scale && *Scale != 0; }
299 return isVector() && ElementBitwidth == Width;
309 return isFloat() && ElementBitwidth == Width;
319 assert(NF > 1 && NF <= 8 &&
"Only legal NF should be fetched");
325 bool verifyType()
const;
328 void applyBasicType();
334 void applyLog2EEW(
unsigned Log2EEW);
335 void applyFixedSEW(
unsigned NewSEW);
336 void applyFixedLog2LMUL(
int Log2LMUL,
enum FixedLMULType
Type);
339 void initBuiltinStr();
341 void initClangBuiltinStr();
352 std::unordered_map<uint64_t, RVVType> LegalTypes;
353 std::set<uint64_t> IllegalTypes;
360 std::optional<RVVTypes>
380 std::string BuiltinName;
382 std::string OverloadedName;
385 bool HasMaskedOffOperand;
388 bool SupportOverloading;
389 bool HasBuiltinAlias;
390 std::string ManualCodegen;
395 std::vector<int64_t> IntrinsicTypes;
400 RVVIntrinsic(llvm::StringRef Name, llvm::StringRef Suffix,
401 llvm::StringRef OverloadedName, llvm::StringRef OverloadedSuffix,
402 llvm::StringRef IRName,
bool IsMasked,
bool HasMaskedOffOperand,
403 bool HasVL,
PolicyScheme Scheme,
bool SupportOverloading,
404 bool HasBuiltinAlias, llvm::StringRef ManualCodegen,
406 const std::vector<int64_t> &IntrinsicTypes,
407 const std::vector<llvm::StringRef> &RequiredFeatures,
408 unsigned NF,
Policy PolicyAttrs,
bool HasFRMRoundModeOp);
414 llvm::StringRef
getName()
const {
return Name; }
417 bool hasVL()
const {
return HasVL; }
432 unsigned getNF()
const {
return NF; }
434 return IntrinsicTypes;
454 llvm_unreachable(
"unsupport policy");
467 bool IsMasked,
bool HasMaskedOffOperand,
bool HasVL,
469 Policy PolicyAttrs,
bool IsTuple);
476 std::string &Name, std::string &BuiltinName,
477 std::string &OverloadedName,
478 Policy &PolicyAttrs,
bool HasFRMRoundModeOp);
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)
static void updateNamesAndPolicy(bool IsMasked, bool HasPolicy, std::string &Name, std::string &BuiltinName, std::string &OverloadedName, Policy &PolicyAttrs, bool HasFRMRoundModeOp)
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 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
uint16_t RequiredExtensions
uint16_t OverloadedSuffixIndex
uint8_t MaskedPolicyScheme
const char * OverloadedName
uint8_t UnMaskedPolicyScheme