Skip to content

Commit 5d027a3

Browse files
[NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8x8 and MFloat8x16
This patch removes the builtins for MFloat8x8 and Mfloat8x16 and build these types the same way the other neon vectors are build. It uses the scalar type(mfloat8).
1 parent fcfd643 commit 5d027a3

File tree

14 files changed

+70
-42
lines changed

14 files changed

+70
-42
lines changed

clang/include/clang/AST/Type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
25212521
bool isFloat32Type() const;
25222522
bool isDoubleType() const;
25232523
bool isBFloat16Type() const;
2524+
bool isMFloat8Type() const;
25242525
bool isFloat128Type() const;
25252526
bool isIbm128Type() const;
25262527
bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
@@ -8527,6 +8528,10 @@ inline bool Type::isBFloat16Type() const {
85278528
return isSpecificBuiltinType(BuiltinType::BFloat16);
85288529
}
85298530

8531+
inline bool Type::isMFloat8Type() const {
8532+
return isSpecificBuiltinType(BuiltinType::MFloat8);
8533+
}
8534+
85308535
inline bool Type::isFloat128Type() const {
85318536
return isSpecificBuiltinType(BuiltinType::Float128);
85328537
}

clang/include/clang/Basic/AArch64SVEACLETypes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", SveBoolx4, SveBoolx4T
201201
SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
202202

203203
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8_t", "__MFloat8_t", MFloat8, MFloat8Ty, 1, 8, 1)
204-
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x8_t", "__MFloat8x8_t", MFloat8x8, MFloat8x8Ty, 8, 8, 1)
205-
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", "__MFloat8x16_t", MFloat8x16, MFloat8x16Ty, 16, 8, 1)
206204

207205
#undef SVE_VECTOR_TYPE
208206
#undef SVE_VECTOR_TYPE_BFLOAT

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ namespace clang {
198198
Float16,
199199
Float32,
200200
Float64,
201-
BFloat16
201+
BFloat16,
202+
MFloat8
202203
};
203204

204205
NeonTypeFlags(unsigned F) : Flags(F) {}
@@ -220,6 +221,7 @@ namespace clang {
220221
switch (getEltType()) {
221222
case Int8:
222223
case Poly8:
224+
case MFloat8:
223225
return 8;
224226
case Int16:
225227
case Float16:

clang/include/clang/Basic/arm_neon_incl.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def OP_UNAVAILABLE : Operation {
218218
// h: half-float
219219
// d: double
220220
// b: bfloat16
221+
// m: mfloat8
221222
//
222223
// Typespec modifiers
223224
// ------------------

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,8 @@ static StringRef mangleAArch64VectorBase(const BuiltinType *EltType) {
39023902
return "Float64";
39033903
case BuiltinType::BFloat16:
39043904
return "Bfloat16";
3905+
case BuiltinType::MFloat8:
3906+
return "Mfloat8";
39053907
default:
39063908
llvm_unreachable("Unexpected vector element base type");
39073909
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6513,6 +6513,8 @@ static llvm::FixedVectorType *GetNeonType(CodeGenFunction *CGF,
65136513
case NeonTypeFlags::Int8:
65146514
case NeonTypeFlags::Poly8:
65156515
return llvm::FixedVectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad));
6516+
case NeonTypeFlags::MFloat8:
6517+
return llvm::FixedVectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad));
65166518
case NeonTypeFlags::Int16:
65176519
case NeonTypeFlags::Poly16:
65186520
return llvm::FixedVectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad));

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
647647
case Type::ExtVector:
648648
case Type::Vector: {
649649
const auto *VT = cast<VectorType>(Ty);
650+
if (VT->getElementType()->isMFloat8Type()) {
651+
ResultType = llvm::FixedVectorType::get(
652+
llvm::Type::getInt8Ty(getLLVMContext()), VT->getNumElements());
653+
break;
654+
}
650655
// An ext_vector_type of Bool is really a vector of bits.
651656
llvm::Type *IRElemTy = VT->isExtVectorBoolType()
652657
? llvm::Type::getInt1Ty(getLLVMContext())

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,6 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadicFn,
375375
NSRN = std::min(NSRN + 1, 8u);
376376
else {
377377
switch (BT->getKind()) {
378-
case BuiltinType::MFloat8x8:
379-
case BuiltinType::MFloat8x16:
380-
NSRN = std::min(NSRN + 1, 8u);
381-
break;
382378
case BuiltinType::SveBool:
383379
case BuiltinType::SveCount:
384380
NPRN = std::min(NPRN + 1, 4u);
@@ -620,8 +616,7 @@ bool AArch64ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
620616
// but with the difference that any floating-point type is allowed,
621617
// including __fp16.
622618
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
623-
if (BT->isFloatingPoint() || BT->getKind() == BuiltinType::MFloat8x16 ||
624-
BT->getKind() == BuiltinType::MFloat8x8)
619+
if (BT->isFloatingPoint())
625620
return true;
626621
} else if (const VectorType *VT = Ty->getAs<VectorType>()) {
627622
if (auto Kind = VT->getVectorKind();

clang/lib/Sema/SemaARM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ static QualType getNeonEltType(NeonTypeFlags Flags, ASTContext &Context,
323323
switch (Flags.getEltType()) {
324324
case NeonTypeFlags::Int8:
325325
return Flags.isUnsigned() ? Context.UnsignedCharTy : Context.SignedCharTy;
326+
case NeonTypeFlags::MFloat8:
327+
return Context.MFloat8Ty;
326328
case NeonTypeFlags::Int16:
327329
return Flags.isUnsigned() ? Context.UnsignedShortTy : Context.ShortTy;
328330
case NeonTypeFlags::Int32:

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10156,6 +10156,11 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
1015610156
return HLSL().handleVectorBinOpConversion(LHS, RHS, LHSType, RHSType,
1015710157
IsCompAssign);
1015810158

10159+
// Any operation with MFloat8 type is only possible with C intrinsics
10160+
if ((LHSVecType && LHSVecType->getElementType()->isMFloat8Type()) ||
10161+
(RHSVecType && RHSVecType->getElementType()->isMFloat8Type()))
10162+
return InvalidOperands(Loc, LHS, RHS);
10163+
1015910164
// AltiVec-style "vector bool op vector bool" combinations are allowed
1016010165
// for some operators but not others.
1016110166
if (!AllowBothBool && LHSVecType &&

0 commit comments

Comments
 (0)