[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 21 04:27:31 PDT 2024
https://github.com/CarolineConcatto updated https://github.com/llvm/llvm-project/pull/97277
>From edf2f6c977d06627f7a752a0128ffcb04c082c38 Mon Sep 17 00:00:00 2001
From: Caroline Concatto <caroline.concatto at arm.com>
Date: Mon, 24 Jun 2024 09:59:24 +0000
Subject: [PATCH] [CLANG][AArch64] Add the modal 8 bit floating-point scalar
type
ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.
>From the PR#323:
```
ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.
````
The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.
This patch is an attempt to the add the MFloat8_t scalar type.
It has a parser and codegen for the new scalar type.
The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.
[1] https://github.com/ARM-software/acle/pull/323
---
clang/include/clang/AST/Type.h | 7 ++
.../clang/Basic/AArch64SVEACLETypes.def | 9 ++
.../clang/Basic/DiagnosticSemaKinds.td | 2 +
clang/include/clang/Basic/Specifiers.h | 1 +
clang/include/clang/Basic/TargetInfo.h | 4 +
clang/include/clang/Basic/TokenKinds.def | 1 +
clang/include/clang/Sema/DeclSpec.h | 2 +
.../include/clang/Serialization/ASTBitCodes.h | 2 +-
clang/lib/AST/ASTContext.cpp | 13 ++-
clang/lib/AST/ItaniumMangle.cpp | 6 ++
clang/lib/AST/Type.cpp | 25 ++++-
clang/lib/Basic/TargetInfo.cpp | 1 +
clang/lib/Basic/Targets/AArch64.cpp | 6 ++
clang/lib/Basic/Targets/AArch64.h | 3 +
clang/lib/CodeGen/CGDebugInfo.cpp | 7 ++
clang/lib/CodeGen/CodeGenTypes.cpp | 6 +-
clang/lib/Parse/ParseDecl.cpp | 7 ++
clang/lib/Parse/ParseExpr.cpp | 1 +
clang/lib/Parse/ParseExprCXX.cpp | 4 +
clang/lib/Parse/ParseTentative.cpp | 2 +
clang/lib/Sema/DeclSpec.cpp | 3 +
clang/lib/Sema/SemaCast.cpp | 8 ++
clang/lib/Sema/SemaExpr.cpp | 6 ++
clang/lib/Sema/SemaTemplateVariadic.cpp | 1 +
clang/lib/Sema/SemaType.cpp | 6 +-
clang/test/AST/arm-mfp8.cpp | 94 +++++++++++++++++++
clang/test/CodeGen/arm-mfp8.c | 26 +++++
clang/test/Modules/no-external-type-id.cppm | 2 +-
clang/test/Sema/arm-mfp8.c | 11 +++
clang/test/Sema/arm-mfp8.cpp | 35 +++++++
30 files changed, 293 insertions(+), 8 deletions(-)
create mode 100644 clang/test/AST/arm-mfp8.cpp
create mode 100644 clang/test/CodeGen/arm-mfp8.c
create mode 100644 clang/test/Sema/arm-mfp8.c
create mode 100644 clang/test/Sema/arm-mfp8.cpp
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..195d471bb155fb 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2644,6 +2644,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
bool isQueueT() const; // OpenCL queue_t
bool isReserveIDT() const; // OpenCL reserve_id_t
+ bool isArmMFloat8Type() const; // AARCH64_OPAQUE_TYPE
+
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
bool is##Id##Type() const;
#include "clang/Basic/OpenCLExtensionTypes.def"
@@ -8312,6 +8314,11 @@ inline bool Type::isBitIntType() const {
return isa<BitIntType>(CanonicalType);
}
+// AARCH64_OPAQUE_TYPE
+inline bool Type::isArmMFloat8Type() const {
+ return isSpecificBuiltinType(BuiltinType::ArmMFloat8);
+}
+
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
inline bool Type::is##Id##Type() const { \
return isSpecificBuiltinType(BuiltinType::Id); \
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 55ed9c36f6c5cd..53644905b789b7 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -97,6 +97,12 @@
SVE_TYPE(Name, Id, SingletonId)
#endif
+#ifndef AARCH64_OPAQUE_TYPE
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF) \
+ SVE_TYPE(Name, Id, SingletonId)
+#endif
+
//===- Vector point types -----------------------------------------------===//
SVE_VECTOR_TYPE_INT("__SVInt8_t", "__SVInt8_t", SveInt8, SveInt8Ty, 16, 8, 1, true)
@@ -181,6 +187,8 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", SveBoolx4, SveBoolx4T
SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
+AARCH64_OPAQUE_TYPE("__MFloat8_t", "__MFloat8_t", ArmMFloat8, ArmMFloat8Ty, 1, 8, 1)
+
#undef SVE_VECTOR_TYPE
#undef SVE_VECTOR_TYPE_BFLOAT
#undef SVE_VECTOR_TYPE_FLOAT
@@ -188,4 +196,5 @@ SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
#undef SVE_PREDICATE_TYPE
#undef SVE_PREDICATE_TYPE_ALL
#undef SVE_OPAQUE_TYPE
+#undef AARCH64_OPAQUE_TYPE
#undef SVE_TYPE
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d42558d2223aae..16f58efbdfc91c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7931,6 +7931,8 @@ def err_bad_lvalue_to_rvalue_cast : Error<
def err_bad_rvalue_to_rvalue_cast : Error<
"cannot cast from rvalue of type %1 to rvalue reference type %2; types are "
"not compatible">;
+def err_bad_mfloat8_cast : Error<
+ "cannot cast %0 to %1; types are not compatible">;
def err_bad_static_cast_pointer_nonpointer : Error<
"cannot cast from type %1 to pointer type %2">;
def err_bad_static_cast_member_pointer_nonmp : Error<
diff --git a/clang/include/clang/Basic/Specifiers.h b/clang/include/clang/Basic/Specifiers.h
index 9c089908fdc130..8216d35bd68800 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -68,6 +68,7 @@ namespace clang {
TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
TST_Fract,
TST_BFloat16,
+ TST_ArmMFloat8_t, // AARCH64_OPAQUE_TYPE
TST_float,
TST_double,
TST_float128,
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index f31d88a354ea28..674f312d23e4dc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -234,6 +234,7 @@ class TargetInfo : public TransferrableTargetInfo,
bool HasFullBFloat16; // True if the backend supports native bfloat16
// arithmetic. Used to determine excess precision
// support in the frontend.
+ bool HasMFloat8;
bool HasIbm128;
bool HasLongDouble;
bool HasFPReturn;
@@ -700,6 +701,9 @@ class TargetInfo : public TransferrableTargetInfo,
return HasBFloat16 || HasFullBFloat16;
}
+ /// Determine whether the _mfp8 type is supported on this target.
+ virtual bool hasArmMFloat8Type() const { return HasMFloat8; }
+
/// Determine whether the BFloat type is fully supported on this target, i.e
/// arithemtic operations.
virtual bool hasFullBFloat16Type() const { return HasFullBFloat16; }
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 00e150dbd7a3a7..0c24844e691301 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -675,6 +675,7 @@ KEYWORD(__bool , KEYALTIVEC|KEYZVECTOR)
// ARM NEON extensions.
ALIAS("__fp16", half , KEYALL)
KEYWORD(__bf16 , KEYALL)
+KEYWORD(__mfp8 , KEYALL)
// OpenCL Extension.
KEYWORD(half , HALFSUPPORT)
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index 06243f2624876f..cbafa9aa06ced7 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -325,6 +325,8 @@ class DeclSpec {
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
static const TST TST_##Name = clang::TST_##Name;
#include "clang/Basic/HLSLIntangibleTypes.def"
+ // AARCH64_OPAQUE_TYPE
+ static const TST TST_ArmMFloat8_t = clang::TST_ArmMFloat8_t;
static const TST TST_error = clang::TST_error;
// type-qualifiers
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 4410df296d8efc..2b2da106cb64dc 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1139,7 +1139,7 @@ enum PredefinedTypeIDs {
///
/// Type IDs for non-predefined types will start at
/// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 505;
+const unsigned NUM_PREDEF_TYPE_IDS = 506;
// Ensure we do not overrun the predefined types we reserved
// in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7cc69ca4a8a814..53dc75f4ab412e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1391,7 +1391,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
}
if (Target.hasAArch64SVETypes() ||
- (AuxTarget && AuxTarget->hasAArch64SVETypes())) {
+ (AuxTarget && AuxTarget->hasAArch64SVETypes()) ||
+ Target.hasArmMFloat8Type()) {
#define SVE_TYPE(Name, Id, SingletonId) \
InitBuiltinType(SingletonId, BuiltinType::Id);
#include "clang/Basic/AArch64SVEACLETypes.def"
@@ -2218,6 +2219,12 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
Width = 0; \
Align = 16; \
break;
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
+ case BuiltinType::ArmMFloat8:
+ Width = Target->getCharWidth();
+ Align = Target->getCharAlign();
+ break;
#include "clang/Basic/AArch64SVEACLETypes.def"
#define PPC_VECTOR_TYPE(Name, Id, Size) \
case BuiltinType::Id: \
@@ -4302,6 +4309,8 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
case BuiltinType::Id: \
return {BoolTy, llvm::ElementCount::getScalable(NumEls), NF};
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
#include "clang/Basic/AArch64SVEACLETypes.def"
#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
@@ -4367,6 +4376,8 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
if (EltTy->isBooleanType() && NumElts == (NumEls * NF) && NumFields == 1) \
return SingletonId;
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
#include "clang/Basic/AArch64SVEACLETypes.def"
} else if (Target->hasRISCVVTypes()) {
uint64_t EltTySize = getTypeSize(EltTy);
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6e1da0c3192da..2ab4c9eb15a9eb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3406,6 +3406,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
type_name = MangledName; \
Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
break;
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF) \
+ case BuiltinType::Id: \
+ type_name = MangledName; \
+ Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
+ break;
#include "clang/Basic/AArch64SVEACLETypes.def"
#define PPC_VECTOR_TYPE(Name, Id, Size) \
case BuiltinType::Id: \
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index a55e6c8bf02611..8f3bedd38c6854 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2484,9 +2484,18 @@ bool Type::isSVESizelessBuiltinType() const {
if (const BuiltinType *BT = getAs<BuiltinType>()) {
switch (BT->getKind()) {
// SVE Types
-#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
+ case BuiltinType::Id:
+#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
+ case BuiltinType::Id:
+#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
+ case BuiltinType::Id:
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
#include "clang/Basic/AArch64SVEACLETypes.def"
return true;
+ case BuiltinType::ArmMFloat8:
+ return false;
default:
return false;
}
@@ -3437,9 +3446,19 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
case Id: \
return #ExtType;
#include "clang/Basic/OpenCLExtensionTypes.def"
-#define SVE_TYPE(Name, Id, SingletonId) \
- case Id: \
+#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
+ case Id: \
+ return Name;
+#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
+ case Id: \
+ return Name;
+#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
+ case Id: \
return Name;
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
+ case ArmMFloat8:
+ return "__mfp8";
#include "clang/Basic/AArch64SVEACLETypes.def"
#define PPC_VECTOR_TYPE(Name, Id, Size) \
case Id: \
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 29f5cd14e46e11..040b49bb115b89 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -60,6 +60,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
NoAsmVariants = false;
HasLegalHalfType = false;
HalfArgsAndReturns = false;
+ HasMFloat8 = false;
HasFloat128 = false;
HasIbm128 = false;
HasFloat16 = false;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 63fc15f916c558..b5931e63a56983 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -741,6 +741,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
.Case("sha3", HasSHA3)
.Cases("aes", "pmull", HasAES)
.Cases("fp16", "fullfp16", HasFullFP16)
+ .Case("fp8", HasMFloat8)
.Case("dit", HasDIT)
.Case("dpb", HasCCPP)
.Case("dpb2", HasCCDP)
@@ -988,6 +989,9 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
FPU |= NeonMode;
HasSM4 = true;
}
+ if (Feature == "+fp8") {
+ HasMFloat8 = true;
+ }
if (Feature == "+strict-align")
HasUnalignedAccess = false;
@@ -1229,6 +1233,8 @@ bool AArch64TargetInfo::hasBFloat16Type() const {
return true;
}
+bool AArch64TargetInfo::hasArmMFloat8Type() const { return true; }
+
TargetInfo::CallingConvCheckResult
AArch64TargetInfo::checkCallingConvention(CallingConv CC) const {
switch (CC) {
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 526f7f30a38618..544ee206fdb618 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -47,6 +47,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasLS64 = false;
bool HasRandGen = false;
bool HasMatMul = false;
+ bool HasMFloat8 = false;
bool HasBFloat16 = false;
bool HasSVE2 = false;
bool HasSVE2p1 = false;
@@ -169,6 +170,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool hasBFloat16Type() const override;
+ bool hasArmMFloat8Type() const override;
+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
bool isCLZForZeroUndef() const override;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6c433cf6a85d5e..20e37992f745c5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -782,6 +782,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
#include "clang/Basic/AArch64SVEACLETypes.def"
{
+ if (BT->getKind() == BuiltinType::ArmMFloat8) {
+ Encoding = llvm::dwarf::DW_ATE_unsigned_char;
+ BTName = BT->getName(CGM.getLangOpts());
+ // Bit size and offset of the type.
+ uint64_t Size = CGM.getContext().getTypeSize(BT);
+ return DBuilder.createBasicType(BTName, Size, Encoding);
+ }
ASTContext::BuiltinVectorTypeInfo Info =
// For svcount_t, only the lower 2 bytes are relevant.
BT->getKind() == BuiltinType::SveCount
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index d087e714882b33..4942e6f3fcb0e8 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -476,7 +476,6 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
Context.getFloatTypeSemantics(T),
/* UseNativeHalf = */ false);
break;
-
case BuiltinType::NullPtr:
// Model std::nullptr_t as i8*
ResultType = llvm::PointerType::getUnqual(getLLVMContext());
@@ -504,6 +503,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
case BuiltinType::Id:
#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
case BuiltinType::Id:
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ ElBits, NF)
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
#include "clang/Basic/AArch64SVEACLETypes.def"
{
@@ -526,6 +527,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
}
case BuiltinType::SveCount:
return llvm::TargetExtType::get(getLLVMContext(), "aarch64.svcount");
+ case BuiltinType::ArmMFloat8:
+ ResultType = llvm::Type::getInt8Ty(getLLVMContext());
+ break;
#define PPC_VECTOR_TYPE(Name, Id, Size) \
case BuiltinType::Id: \
ResultType = \
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 1f56884be392d6..df5104958199f7 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4547,6 +4547,10 @@ void Parser::ParseDeclarationSpecifiers(
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec,
DiagID, Policy);
break;
+ case tok::kw___mfp8: // AARCH64_OPAQUE_TYPE
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_ArmMFloat8_t, Loc, PrevSpec,
+ DiagID, Policy);
+ break;
case tok::kw_half:
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec,
DiagID, Policy);
@@ -5828,6 +5832,7 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
case tok::kw__ExtInt:
case tok::kw__BitInt:
case tok::kw___bf16:
+ case tok::kw___mfp8:
case tok::kw_half:
case tok::kw_float:
case tok::kw_double:
@@ -5913,6 +5918,7 @@ bool Parser::isTypeSpecifierQualifier() {
case tok::kw_int:
case tok::kw__ExtInt:
case tok::kw__BitInt:
+ case tok::kw___mfp8:
case tok::kw_half:
case tok::kw___bf16:
case tok::kw_float:
@@ -6137,6 +6143,7 @@ bool Parser::isDeclarationSpecifier(
case tok::kw_int:
case tok::kw__ExtInt:
case tok::kw__BitInt:
+ case tok::kw___mfp8:
case tok::kw_half:
case tok::kw___bf16:
case tok::kw_float:
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e7514500dc53a4..815eeedec0d2dc 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1625,6 +1625,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
case tok::kw__BitInt:
case tok::kw_signed:
case tok::kw_unsigned:
+ case tok::kw___mfp8:
case tok::kw_half:
case tok::kw_float:
case tok::kw_double:
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e96cddf88a1346..bb5bcec18e1a5a 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2408,6 +2408,10 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
case tok::kw___int128:
DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID, Policy);
break;
+ case tok::kw___mfp8: // AARCH64_OPAQUE_TYPE
+ DS.SetTypeSpecType(DeclSpec::TST_ArmMFloat8_t, Loc, PrevSpec, DiagID,
+ Policy);
+ break;
case tok::kw___bf16:
DS.SetTypeSpecType(DeclSpec::TST_BFloat16, Loc, PrevSpec, DiagID, Policy);
break;
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 9f6b4f6118ede2..b3bfc8082345b7 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1788,6 +1788,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
case tok::kw_short:
case tok::kw_int:
case tok::kw_long:
+ case tok::kw___mfp8:
case tok::kw___int64:
case tok::kw___int128:
case tok::kw_signed:
@@ -1918,6 +1919,7 @@ bool Parser::isCXXDeclarationSpecifierAType() {
case tok::kw_long:
case tok::kw___int64:
case tok::kw___int128:
+ case tok::kw___mfp8:
case tok::kw_signed:
case tok::kw_unsigned:
case tok::kw_half:
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 12d2d3f6060c63..2bd44949e5eda1 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -379,6 +379,7 @@ bool Declarator::isDeclarationOfFunction() const {
#include "clang/Basic/OpenCLImageTypes.def"
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
#include "clang/Basic/HLSLIntangibleTypes.def"
+ case TST_ArmMFloat8_t: // AARCH64_OPAQUE_TYPE
return false;
case TST_decltype_auto:
@@ -613,6 +614,8 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
case DeclSpec::TST_##Name: \
return #Name;
+ case DeclSpec::TST_ArmMFloat8_t: // AARCH64_OPAQUE_TYPE
+ return "__mfp8";
#include "clang/Basic/HLSLIntangibleTypes.def"
case DeclSpec::TST_error: return "(error)";
}
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index f01b22a72915c8..4e1ea65d681bb3 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2986,6 +2986,14 @@ void CastOperation::CheckCStyleCast() {
return;
}
+ if ((DestType->isArmMFloat8Type() && !SrcType->isArmMFloat8Type()) ||
+ (!DestType->isArmMFloat8Type() && SrcType->isArmMFloat8Type())) {
+ Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_bad_mfloat8_cast)
+ << SrcType << DestType << SrcExpr.get()->getSourceRange();
+ SrcExpr = ExprError();
+ return;
+ }
+
// Allow casting a sizeless built-in type to itself.
if (DestType->isSizelessBuiltinType() &&
Self.Context.hasSameUnqualifiedType(DestType, SrcType)) {
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..9962336087929d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8434,6 +8434,12 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
return QualType();
}
+ if (LHSTy->isArmMFloat8Type() || RHSTy->isArmMFloat8Type()) {
+ Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
+ << LHSTy << RHSTy << LHS.get()->getSourceRange()
+ << RHS.get()->getSourceRange();
+ }
+
// Diagnose attempts to convert between __ibm128, __float128 and long double
// where such conversions currently can't be handled.
if (unsupportedTypeConversion(*this, LHSTy, RHSTy)) {
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 40522a07f6339c..bbf3a37aff4667 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -962,6 +962,7 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
#include "clang/Basic/OpenCLImageTypes.def"
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
#include "clang/Basic/HLSLIntangibleTypes.def"
+ case TST_ArmMFloat8_t: // AARCH64_OPAQUE_TYPE
case TST_unknown_anytype:
case TST_error:
break;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11adfb0d7f3e98..cb80e03fdabc94 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1375,7 +1375,11 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
Result = Context.SingletonId; \
break;
#include "clang/Basic/HLSLIntangibleTypes.def"
-
+ case DeclSpec::TST_ArmMFloat8_t: // AARCH64_OPAQUE_TYPE
+ if (!S.Context.getTargetInfo().hasArmMFloat8Type())
+ S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__mfp8";
+ Result = Context.ArmMFloat8Ty;
+ break;
case DeclSpec::TST_error:
Result = Context.IntTy;
declarator.setInvalidType(true);
diff --git a/clang/test/AST/arm-mfp8.cpp b/clang/test/AST/arm-mfp8.cpp
new file mode 100644
index 00000000000000..d99b7cd062e305
--- /dev/null
+++ b/clang/test/AST/arm-mfp8.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -std=c++11 -triple aarch64-arm-none-eabi -target-feature -fp8 -ast-dump %s | \
+// RUN: FileCheck %s --strict-whitespace
+
+// REQUIRES: aarch64-registered-target || arm-registered-target
+
+/* Various contexts where type __mfp8 can appear. */
+
+/* Namespace */
+namespace {
+ __mfp8 f2n;
+ __mfp8 arr1n[10];
+}
+
+//CHECK: |-NamespaceDecl {{.*}}
+//CHECK-NEXT: | |-VarDecl {{.*}} f2n '__mfp8'
+//CHECK-NEXT: | `-VarDecl {{.*}} arr1n '__mfp8[10]'
+
+ __mfp8 arr1[10];
+ //__mfp8 arr2n[] { 1, 3, 3 }; cannot initialize
+
+ const __mfp8 func1n(const __mfp8 mfp8) {
+ // this should fail
+ __mfp8 f1n;
+ f1n = mfp8;
+ return f1n;
+ }
+
+//CHECK: |-VarDecl {{.*}} '__mfp8[10]'
+
+//CHECK: | `-VarDecl {{.*}} f1n '__mfp8'
+//CHECK-NEXT: |-BinaryOperator {{.*}} '__mfp8' lvalue '='
+//CHECK-NEXT: | |-DeclRefExpr {{.*}} '__mfp8' lvalue Var {{.*}} 'f1n' '__mfp8'
+//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: | `-DeclRefExpr {{.*}} 'const __mfp8' lvalue ParmVar {{.*}} 'mfp8' 'const __mfp8'
+//CHECK-NEXT: `-ReturnStmt {{.*}}
+//CHECK-NEXT: `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: `-DeclRefExpr {{.*}} '__mfp8' lvalue Var {{.*}} 'f1n' '__mfp8'
+
+
+/* Class */
+
+class C1 {
+ __mfp8 f1c;
+ static const __mfp8 f2c;
+ volatile __mfp8 f3c;
+public:
+ C1(__mfp8 arg) : f1c(arg), f3c(arg) { }
+ __mfp8 func1c(__mfp8 arg ) {
+ return arg;
+ }
+ static __mfp8 func2c(__mfp8 arg) {
+ return arg;
+ }
+};
+
+//CHECK: | |-CXXRecordDecl {{.*}} referenced class C1
+//CHECK-NEXT: | |-FieldDecl {{.*}} f1c '__mfp8'
+//CHECK-NEXT: | |-VarDecl {{.*}} f2c 'const __mfp8' static
+//CHECK-NEXT: | |-FieldDecl {{.*}} f3c 'volatile __mfp8'
+//CHECK-NEXT: | |-AccessSpecDecl {{.*}}
+//CHECK-NEXT: | |-CXXConstructorDecl {{.*}} C1 'void (__mfp8)' implicit-inline
+//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8'
+//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f1c' '__mfp8'
+//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
+//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f3c' 'volatile __mfp8'
+//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
+//CHECK-NEXT: | | `-CompoundStmt {{.*}}
+//CHECK-NEXT: | |-CXXMethodDecl {{.*}} func1c '__mfp8 (__mfp8)' implicit-inline
+//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8'
+//CHECK-NEXT: | | `-CompoundStmt {{.*}}
+//CHECK-NEXT: | | `-ReturnStmt {{.*}}
+//CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}}8 'arg' '__mfp8'
+//CHECK-NEXT: | `-CXXMethodDecl {{.*}} func2c '__mfp8 (__mfp8)' static implicit-inline
+//CHECK-NEXT: | |-ParmVarDecl {{.*}} arg '__mfp8'
+//CHECK-NEXT: | `-CompoundStmt {{.*}}
+//CHECK-NEXT: | `-ReturnStmt {{.*}}
+//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
+//CHECK-NEXT: | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
+
+template <class C> struct S1 {
+ C mem1;
+};
+
+template <> struct S1<__mfp8> {
+ __mfp8 mem2;
+};
+
+//CHECK: |-TemplateArgument type '__mfp8'
+//CHECK-NEXT: | `-BuiltinType {{.*}} '__mfp8'
+//CHECK-NEXT: |-CXXRecordDecl {{.*}} implicit struct S1
+//CHECK-NEXT: `-FieldDecl {{.*}} mem2 '__mfp8'
diff --git a/clang/test/CodeGen/arm-mfp8.c b/clang/test/CodeGen/arm-mfp8.c
new file mode 100644
index 00000000000000..81fb9b257b4789
--- /dev/null
+++ b/clang/test/CodeGen/arm-mfp8.c
@@ -0,0 +1,26 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
+// RUN: %clang_cc1 -emit-llvm -triple aarch64-arm-none-eabi -target-feature -fp8 -o - %s | FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+// CHECK-LABEL: define dso_local i8 @func1n(
+// CHECK-SAME: i8 [[MFP8:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[MFP8_ADDR:%.*]] = alloca i8, align 1
+// CHECK-NEXT: [[F1N:%.*]] = alloca [10 x i8], align 1
+// CHECK-NEXT: store i8 [[MFP8]], ptr [[MFP8_ADDR]], align 1
+// CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[MFP8_ADDR]], align 1
+// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [10 x i8], ptr [[F1N]], i64 0, i64 2
+// CHECK-NEXT: store i8 [[TMP0]], ptr [[ARRAYIDX]], align 1
+// CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [10 x i8], ptr [[F1N]], i64 0, i64 2
+// CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[ARRAYIDX1]], align 1
+// CHECK-NEXT: ret i8 [[TMP1]]
+//
+__mfp8 func1n(__mfp8 mfp8) {
+ __mfp8 f1n[10];
+ f1n[2] = mfp8;
+ return f1n[2];
+}
+
+
+
diff --git a/clang/test/Modules/no-external-type-id.cppm b/clang/test/Modules/no-external-type-id.cppm
index 068e52646dcc1c..a4ca389739fbb5 100644
--- a/clang/test/Modules/no-external-type-id.cppm
+++ b/clang/test/Modules/no-external-type-id.cppm
@@ -23,7 +23,7 @@ export module b;
import a;
export int b();
-// CHECK: <DECL_FUNCTION {{.*}} op8=4056
+// CHECK: <DECL_FUNCTION {{.*}} op8=4064
// CHECK: <TYPE_FUNCTION_PROTO
//--- a.v1.cppm
diff --git a/clang/test/Sema/arm-mfp8.c b/clang/test/Sema/arm-mfp8.c
new file mode 100644
index 00000000000000..c1e74a18b647d2
--- /dev/null
+++ b/clang/test/Sema/arm-mfp8.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-arm-none-eabi -target-feature -fp8 %s
+
+// REQUIRES: aarch64-registered-target
+
+__mfp8 test_cast_from_float(unsigned in) {
+ return (__mfp8)in; // expected-error {{cannot cast 'unsigned int' to '__mfp8'; types are not compatible}}
+}
+
+unsigned test_cast_to_int(__mfp8 in) {
+ return (unsigned)in; // expected-error {{cannot cast '__mfp8' to 'unsigned int'; types are not compatible}}
+}
diff --git a/clang/test/Sema/arm-mfp8.cpp b/clang/test/Sema/arm-mfp8.cpp
new file mode 100644
index 00000000000000..d9e03dc0e3f0de
--- /dev/null
+++ b/clang/test/Sema/arm-mfp8.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=scalar -triple aarch64-arm-none-eabi -target-feature -fp8 %s
+
+// REQUIRES: aarch64-registered-target
+__mfp8 test_static_cast_from_char(char in) {
+ return static_cast<__mfp8>(in); // scalar-error {{static_cast from 'char' to '__mfp8' is not allowed}}
+}
+
+char test_static_cast_to_char(__mfp8 in) {
+ return static_cast<char>(in); // scalar-error {{static_cast from '__mfp8' to 'char' is not allowed}}
+}
+void test(bool b) {
+ __mfp8 mfp8;
+
+ mfp8 + mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
+ mfp8 - mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
+ mfp8 * mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
+ mfp8 / mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
+ ++mfp8; // scalar-error {{cannot increment value of type '__mfp8'}}
+ --mfp8; // scalar-error {{cannot decrement value of type '__mfp8'}}
+
+ char u8;
+
+ mfp8 + u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
+ u8 + mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
+ mfp8 - u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
+ u8 - mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
+ mfp8 * u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
+ u8 * mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
+ mfp8 / u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
+ u8 / mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
+ mfp8 = u8; // scalar-error {{assigning to '__mfp8' from incompatible type 'char'}}
+ u8 = mfp8; // scalar-error {{assigning to 'char' from incompatible type '__mfp8'}}
+ mfp8 + (b ? u8 : mfp8); // scalar-error {{incompatible operand types ('char' and '__mfp8')}}
+}
+
More information about the cfe-commits
mailing list