Skip to content

Commit edf2f6c

Browse files
[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] ARM-software/acle#323
1 parent 3e32e45 commit edf2f6c

30 files changed

+293
-8
lines changed

clang/include/clang/AST/Type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26442644
bool isQueueT() const; // OpenCL queue_t
26452645
bool isReserveIDT() const; // OpenCL reserve_id_t
26462646

2647+
bool isArmMFloat8Type() const; // AARCH64_OPAQUE_TYPE
2648+
26472649
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
26482650
bool is##Id##Type() const;
26492651
#include "clang/Basic/OpenCLExtensionTypes.def"
@@ -8312,6 +8314,11 @@ inline bool Type::isBitIntType() const {
83128314
return isa<BitIntType>(CanonicalType);
83138315
}
83148316

8317+
// AARCH64_OPAQUE_TYPE
8318+
inline bool Type::isArmMFloat8Type() const {
8319+
return isSpecificBuiltinType(BuiltinType::ArmMFloat8);
8320+
}
8321+
83158322
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
83168323
inline bool Type::is##Id##Type() const { \
83178324
return isSpecificBuiltinType(BuiltinType::Id); \

clang/include/clang/Basic/AArch64SVEACLETypes.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
SVE_TYPE(Name, Id, SingletonId)
9898
#endif
9999

100+
#ifndef AARCH64_OPAQUE_TYPE
101+
#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
102+
ElBits, NF) \
103+
SVE_TYPE(Name, Id, SingletonId)
104+
#endif
105+
100106
//===- Vector point types -----------------------------------------------===//
101107

102108
SVE_VECTOR_TYPE_INT("__SVInt8_t", "__SVInt8_t", SveInt8, SveInt8Ty, 16, 8, 1, true)
@@ -181,11 +187,14 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", SveBoolx4, SveBoolx4T
181187

182188
SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
183189

190+
AARCH64_OPAQUE_TYPE("__MFloat8_t", "__MFloat8_t", ArmMFloat8, ArmMFloat8Ty, 1, 8, 1)
191+
184192
#undef SVE_VECTOR_TYPE
185193
#undef SVE_VECTOR_TYPE_BFLOAT
186194
#undef SVE_VECTOR_TYPE_FLOAT
187195
#undef SVE_VECTOR_TYPE_INT
188196
#undef SVE_PREDICATE_TYPE
189197
#undef SVE_PREDICATE_TYPE_ALL
190198
#undef SVE_OPAQUE_TYPE
199+
#undef AARCH64_OPAQUE_TYPE
191200
#undef SVE_TYPE

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7931,6 +7931,8 @@ def err_bad_lvalue_to_rvalue_cast : Error<
79317931
def err_bad_rvalue_to_rvalue_cast : Error<
79327932
"cannot cast from rvalue of type %1 to rvalue reference type %2; types are "
79337933
"not compatible">;
7934+
def err_bad_mfloat8_cast : Error<
7935+
"cannot cast %0 to %1; types are not compatible">;
79347936
def err_bad_static_cast_pointer_nonpointer : Error<
79357937
"cannot cast from type %1 to pointer type %2">;
79367938
def err_bad_static_cast_member_pointer_nonmp : Error<

clang/include/clang/Basic/Specifiers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace clang {
6868
TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
6969
TST_Fract,
7070
TST_BFloat16,
71+
TST_ArmMFloat8_t, // AARCH64_OPAQUE_TYPE
7172
TST_float,
7273
TST_double,
7374
TST_float128,

clang/include/clang/Basic/TargetInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class TargetInfo : public TransferrableTargetInfo,
234234
bool HasFullBFloat16; // True if the backend supports native bfloat16
235235
// arithmetic. Used to determine excess precision
236236
// support in the frontend.
237+
bool HasMFloat8;
237238
bool HasIbm128;
238239
bool HasLongDouble;
239240
bool HasFPReturn;
@@ -700,6 +701,9 @@ class TargetInfo : public TransferrableTargetInfo,
700701
return HasBFloat16 || HasFullBFloat16;
701702
}
702703

704+
/// Determine whether the _mfp8 type is supported on this target.
705+
virtual bool hasArmMFloat8Type() const { return HasMFloat8; }
706+
703707
/// Determine whether the BFloat type is fully supported on this target, i.e
704708
/// arithemtic operations.
705709
virtual bool hasFullBFloat16Type() const { return HasFullBFloat16; }

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ KEYWORD(__bool , KEYALTIVEC|KEYZVECTOR)
675675
// ARM NEON extensions.
676676
ALIAS("__fp16", half , KEYALL)
677677
KEYWORD(__bf16 , KEYALL)
678+
KEYWORD(__mfp8 , KEYALL)
678679

679680
// OpenCL Extension.
680681
KEYWORD(half , HALFSUPPORT)

clang/include/clang/Sema/DeclSpec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ class DeclSpec {
325325
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
326326
static const TST TST_##Name = clang::TST_##Name;
327327
#include "clang/Basic/HLSLIntangibleTypes.def"
328+
// AARCH64_OPAQUE_TYPE
329+
static const TST TST_ArmMFloat8_t = clang::TST_ArmMFloat8_t;
328330
static const TST TST_error = clang::TST_error;
329331

330332
// type-qualifiers

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ enum PredefinedTypeIDs {
11391139
///
11401140
/// Type IDs for non-predefined types will start at
11411141
/// NUM_PREDEF_TYPE_IDs.
1142-
const unsigned NUM_PREDEF_TYPE_IDS = 505;
1142+
const unsigned NUM_PREDEF_TYPE_IDS = 506;
11431143

11441144
// Ensure we do not overrun the predefined types we reserved
11451145
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
13911391
}
13921392

13931393
if (Target.hasAArch64SVETypes() ||
1394-
(AuxTarget && AuxTarget->hasAArch64SVETypes())) {
1394+
(AuxTarget && AuxTarget->hasAArch64SVETypes()) ||
1395+
Target.hasArmMFloat8Type()) {
13951396
#define SVE_TYPE(Name, Id, SingletonId) \
13961397
InitBuiltinType(SingletonId, BuiltinType::Id);
13971398
#include "clang/Basic/AArch64SVEACLETypes.def"
@@ -2218,6 +2219,12 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
22182219
Width = 0; \
22192220
Align = 16; \
22202221
break;
2222+
#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
2223+
ElBits, NF)
2224+
case BuiltinType::ArmMFloat8:
2225+
Width = Target->getCharWidth();
2226+
Align = Target->getCharAlign();
2227+
break;
22212228
#include "clang/Basic/AArch64SVEACLETypes.def"
22222229
#define PPC_VECTOR_TYPE(Name, Id, Size) \
22232230
case BuiltinType::Id: \
@@ -4302,6 +4309,8 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
43024309
case BuiltinType::Id: \
43034310
return {BoolTy, llvm::ElementCount::getScalable(NumEls), NF};
43044311
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
4312+
#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
4313+
ElBits, NF)
43054314
#include "clang/Basic/AArch64SVEACLETypes.def"
43064315

43074316
#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
@@ -4367,6 +4376,8 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
43674376
if (EltTy->isBooleanType() && NumElts == (NumEls * NF) && NumFields == 1) \
43684377
return SingletonId;
43694378
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
4379+
#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
4380+
ElBits, NF)
43704381
#include "clang/Basic/AArch64SVEACLETypes.def"
43714382
} else if (Target->hasRISCVVTypes()) {
43724383
uint64_t EltTySize = getTypeSize(EltTy);

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
34063406
type_name = MangledName; \
34073407
Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
34083408
break;
3409+
#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
3410+
ElBits, NF) \
3411+
case BuiltinType::Id: \
3412+
type_name = MangledName; \
3413+
Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
3414+
break;
34093415
#include "clang/Basic/AArch64SVEACLETypes.def"
34103416
#define PPC_VECTOR_TYPE(Name, Id, Size) \
34113417
case BuiltinType::Id: \

0 commit comments

Comments
 (0)