Skip to content

Commit fbeca5c

Browse files
[WIP][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 `__fpm8` 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 fpm8_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 9e63632 commit fbeca5c

25 files changed

+171
-2
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
11151115
CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
11161116
CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
11171117
SatUnsignedLongFractTy;
1118+
CanQualType Fpm8Ty;
11181119
CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
11191120
CanQualType BFloat16Ty;
11201121
CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3

clang/include/clang/AST/BuiltinTypes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty)
221221
// '__ibm128'
222222
FLOATING_TYPE(Ibm128, Ibm128Ty)
223223

224+
225+
// '__fpm8'
226+
UNSIGNED_TYPE(Fpm8, Fpm8Ty)
227+
224228
//===- Language-specific types --------------------------------------------===//
225229

226230
// This is the type of C++0x 'nullptr'.

clang/include/clang/AST/Type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
24922492
bool isDoubleType() const;
24932493
bool isBFloat16Type() const;
24942494
bool isFloat128Type() const;
2495+
bool isFpm8Type() const;
24952496
bool isIbm128Type() const;
24962497
bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
24972498
bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
@@ -7944,6 +7945,10 @@ inline bool Type::isBFloat16Type() const {
79447945
return isSpecificBuiltinType(BuiltinType::BFloat16);
79457946
}
79467947

7948+
inline bool Type::isFpm8Type() const {
7949+
return isSpecificBuiltinType(BuiltinType::Fpm8);
7950+
}
7951+
79477952
inline bool Type::isFloat128Type() const {
79487953
return isSpecificBuiltinType(BuiltinType::Float128);
79497954
}

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_Fpm8,
7172
TST_float,
7273
TST_double,
7374
TST_float128,

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ KEYWORD(__bool , KEYALTIVEC|KEYZVECTOR)
655655
// ARM NEON extensions.
656656
ALIAS("__fp16", half , KEYALL)
657657
KEYWORD(__bf16 , KEYALL)
658+
KEYWORD(__fpm8 , KEYALL)
658659

659660
// OpenCL Extension.
660661
KEYWORD(half , HALFSUPPORT)

clang/include/clang/Sema/DeclSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class DeclSpec {
287287
static const TST TST_bitint = clang::TST_bitint;
288288
static const TST TST_half = clang::TST_half;
289289
static const TST TST_BFloat16 = clang::TST_BFloat16;
290+
static const TST TST_Fpm8 = clang::TST_Fpm8;
290291
static const TST TST_float = clang::TST_float;
291292
static const TST TST_double = clang::TST_double;
292293
static const TST TST_float16 = clang::TST_Float16;

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,8 @@ enum PredefinedTypeIDs {
10781078
/// \brief The '__ibm128' type
10791079
PREDEF_TYPE_IBM128_ID = 74,
10801080

1081+
PREDEF_TYPE_FPM8_ID = 75,
1082+
10811083
/// OpenCL image types with auto numeration
10821084
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
10831085
PREDEF_TYPE_##Id##_ID,
@@ -1109,7 +1111,7 @@ enum PredefinedTypeIDs {
11091111
///
11101112
/// Type IDs for non-predefined types will start at
11111113
/// NUM_PREDEF_TYPE_IDs.
1112-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1114+
const unsigned NUM_PREDEF_TYPE_IDS = 504;
11131115

11141116
// Ensure we do not overrun the predefined types we reserved
11151117
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
14081408
// half type (OpenCL 6.1.1.1) / ARM NEON __fp16
14091409
InitBuiltinType(HalfTy, BuiltinType::Half);
14101410

1411+
InitBuiltinType(Fpm8Ty, BuiltinType::Fpm8);
1412+
14111413
InitBuiltinType(BFloat16Ty, BuiltinType::BFloat16);
14121414

14131415
// Builtin type used to help define __builtin_va_list.
@@ -1977,6 +1979,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
19771979
Width = Target->getBoolWidth();
19781980
Align = Target->getBoolAlign();
19791981
break;
1982+
case BuiltinType::Fpm8:
19801983
case BuiltinType::Char_S:
19811984
case BuiltinType::Char_U:
19821985
case BuiltinType::UChar:
@@ -8129,6 +8132,7 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
81298132
case BuiltinType::LongDouble: return 'D';
81308133
case BuiltinType::NullPtr: return '*'; // like char*
81318134

8135+
case BuiltinType::Fpm8:
81328136
case BuiltinType::BFloat16:
81338137
case BuiltinType::Float16:
81348138
case BuiltinType::Float128:
@@ -11466,6 +11470,9 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
1146611470
else
1146711471
Type = Context.CharTy;
1146811472
break;
11473+
case '£':
11474+
Type = Context.Fpm8Ty;
11475+
break;
1146911476
case 'b': // boolean
1147011477
assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!");
1147111478
Type = Context.BoolTy;

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
31813181
case BuiltinType::SChar:
31823182
Out << 'a';
31833183
break;
3184+
case BuiltinType::Fpm8:
31843185
case BuiltinType::WChar_S:
31853186
case BuiltinType::WChar_U:
31863187
Out << 'w';

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,6 +3372,8 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
33723372
return "unsigned __int128";
33733373
case Half:
33743374
return Policy.Half ? "half" : "__fp16";
3375+
case Fpm8:
3376+
return "__fpm8";
33753377
case BFloat16:
33763378
return "__bf16";
33773379
case Float:

0 commit comments

Comments
 (0)