Skip to content

Commit 7134302

Browse files
[CLANG]Add Scalable vectors for mfloat8_t
This patch adds these new vector sizes for sve: svmfloat8_t According to the ARM ACLE PR#323[1]. [1] ARM-software/acle#323
1 parent 5a03823 commit 7134302

File tree

8 files changed

+91
-9
lines changed

8 files changed

+91
-9
lines changed

clang/include/clang/Basic/AArch64SVEACLETypes.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969

7070
#ifndef SVE_VECTOR_TYPE_BFLOAT
7171
#define SVE_VECTOR_TYPE_BFLOAT(Name, MangledName, Id, SingletonId, NumEls, ElBits, NF) \
72+
SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, NF, true, false, true)
73+
#endif
74+
75+
#ifndef SVE_VECTOR_TYPE_MFLOAT
76+
#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, ElBits, NF) \
7277
SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, NF, false, false, true)
7378
#endif
7479

@@ -114,6 +119,7 @@ SVE_VECTOR_TYPE_FLOAT("__SVFloat32_t", "__SVFloat32_t", SveFloat32, SveFloat32Ty
114119
SVE_VECTOR_TYPE_FLOAT("__SVFloat64_t", "__SVFloat64_t", SveFloat64, SveFloat64Ty, 2, 64, 1)
115120

116121
SVE_VECTOR_TYPE_BFLOAT("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, SveBFloat16Ty, 8, 16, 1)
122+
SVE_VECTOR_TYPE_MFLOAT("__SVMfloat8_t", "__SVMfloat8_t", SveMFloat8, SveMFloat8Ty, 16, 8, 1)
117123

118124
//
119125
// x2
@@ -183,6 +189,7 @@ SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
183189

184190
#undef SVE_VECTOR_TYPE
185191
#undef SVE_VECTOR_TYPE_BFLOAT
192+
#undef SVE_VECTOR_TYPE_MFLOAT
186193
#undef SVE_VECTOR_TYPE_FLOAT
187194
#undef SVE_VECTOR_TYPE_INT
188195
#undef SVE_PREDICATE_TYPE

clang/include/clang/Basic/arm_sve_sme_incl.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def EltTyBool16 : EltType<10>;
162162
def EltTyBool32 : EltType<11>;
163163
def EltTyBool64 : EltType<12>;
164164
def EltTyBFloat16 : EltType<13>;
165+
def EltTyMFloat8 : EltType<14>;
165166

166167
class MemEltType<int val> {
167168
int Value = val;

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ enum PredefinedTypeIDs {
11451145
///
11461146
/// Type IDs for non-predefined types will start at
11471147
/// NUM_PREDEF_TYPE_IDs.
1148-
const unsigned NUM_PREDEF_TYPE_IDS = 505;
1148+
const unsigned NUM_PREDEF_TYPE_IDS = 506;
11491149

11501150
// Ensure we do not overrun the predefined types we reserved
11511151
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,6 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
43044304
switch (Ty->getKind()) {
43054305
default:
43064306
llvm_unreachable("Unsupported builtin vector type");
4307-
43084307
#define SVE_VECTOR_TYPE_INT(Name, MangledName, Id, SingletonId, NumEls, \
43094308
ElBits, NF, IsSigned) \
43104309
case BuiltinType::Id: \
@@ -4319,12 +4318,16 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
43194318
ElBits, NF) \
43204319
case BuiltinType::Id: \
43214320
return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
4321+
#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, \
4322+
ElBits, NF) \
4323+
case BuiltinType::Id: \
4324+
return {getIntTypeForBitwidth(ElBits, false), \
4325+
llvm::ElementCount::getScalable(NumEls), NF};
43224326
#define SVE_PREDICATE_TYPE_ALL(Name, MangledName, Id, SingletonId, NumEls, NF) \
43234327
case BuiltinType::Id: \
43244328
return {BoolTy, llvm::ElementCount::getScalable(NumEls), NF};
43254329
#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
43264330
#include "clang/Basic/AArch64SVEACLETypes.def"
4327-
43284331
#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
43294332
IsSigned) \
43304333
case BuiltinType::Id: \
@@ -4384,6 +4387,13 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
43844387
EltTySize == ElBits && NumElts == (NumEls * NF) && NumFields == 1) { \
43854388
return SingletonId; \
43864389
}
4390+
#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, \
4391+
ElBits, NF) \
4392+
if (EltTy->hasIntegerRepresentation() && !EltTy->isBooleanType() && \
4393+
!EltTy->hasSignedIntegerRepresentation() && EltTySize == ElBits && \
4394+
NumElts == (NumEls * NF) && NumFields == 1) { \
4395+
return SingletonId; \
4396+
}
43874397
#define SVE_PREDICATE_TYPE_ALL(Name, MangledName, Id, SingletonId, NumEls, NF) \
43884398
if (EltTy->isBooleanType() && NumElts == (NumEls * NF) && NumFields == 1) \
43894399
return SingletonId;

clang/test/CodeGen/arm-mfp8.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// RUN: %clang_cc1 -emit-llvm -triple aarch64-arm-none-eabi -target-feature -fp8 -target-feature +sve -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-C
3+
// RUN: %clang_cc1 -emit-llvm -triple aarch64-arm-none-eabi -target-feature -fp8 -target-feature +sve -o - -x c++ %s | FileCheck %s --check-prefixes=CHECK,CHECK-CXX
4+
5+
// REQUIRES: aarch64-registered-target
6+
7+
#include <arm_sve.h>
8+
// CHECK-C-LABEL: define dso_local <vscale x 16 x i8> @test_ret_svmfloat8_t(
9+
// CHECK-C-SAME: <vscale x 16 x i8> [[V:%.*]]) #[[ATTR0:[0-9]+]] {
10+
// CHECK-C-NEXT: [[ENTRY:.*:]]
11+
// CHECK-C-NEXT: [[V_ADDR:%.*]] = alloca <vscale x 16 x i8>, align 16
12+
// CHECK-C-NEXT: store <vscale x 16 x i8> [[V]], ptr [[V_ADDR]], align 16
13+
// CHECK-C-NEXT: [[TMP0:%.*]] = load <vscale x 16 x i8>, ptr [[V_ADDR]], align 16
14+
// CHECK-C-NEXT: ret <vscale x 16 x i8> [[TMP0]]
15+
//
16+
// CHECK-CXX-LABEL: define dso_local <vscale x 16 x i8> @_Z20test_ret_svmfloat8_tu13__SVMfloat8_t(
17+
// CHECK-CXX-SAME: <vscale x 16 x i8> [[V:%.*]]) #[[ATTR0:[0-9]+]] {
18+
// CHECK-CXX-NEXT: [[ENTRY:.*:]]
19+
// CHECK-CXX-NEXT: [[V_ADDR:%.*]] = alloca <vscale x 16 x i8>, align 16
20+
// CHECK-CXX-NEXT: store <vscale x 16 x i8> [[V]], ptr [[V_ADDR]], align 16
21+
// CHECK-CXX-NEXT: [[TMP0:%.*]] = load <vscale x 16 x i8>, ptr [[V_ADDR]], align 16
22+
// CHECK-CXX-NEXT: ret <vscale x 16 x i8> [[TMP0]]
23+
//
24+
svmfloat8_t test_ret_svmfloat8_t(svmfloat8_t v) {
25+
return v;
26+
}
27+
//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
28+
// CHECK: {{.*}}

clang/test/Modules/no-external-type-id.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export module b;
2323
import a;
2424
export int b();
2525

26-
// CHECK: <DECL_FUNCTION {{.*}} op8=4056
26+
// CHECK: <DECL_FUNCTION {{.*}} op8=4064
2727
// CHECK: <TYPE_FUNCTION_PROTO
2828

2929
//--- a.v1.cppm

clang/test/Sema/arm-mfp8.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify=sve -triple aarch64-arm-none-eabi \
2+
// RUN: -target-feature -fp8 -target-feature +sve %s
3+
4+
// REQUIRES: aarch64-registered-target
5+
6+
#include <arm_sve.h>
7+
void test_vector_sve(svmfloat8_t a, svuint8_t c) {
8+
a + c; // sve-error {{cannot convert between vector and non-scalar values ('svmfloat8_t' (aka '__SVMfloat8_t') and 'svuint8_t' (aka '__SVUint8_t'))}}
9+
a - c; // sve-error {{cannot convert between vector and non-scalar values ('svmfloat8_t' (aka '__SVMfloat8_t') and 'svuint8_t' (aka '__SVUint8_t'))}}
10+
a * c; // sve-error {{cannot convert between vector and non-scalar values ('svmfloat8_t' (aka '__SVMfloat8_t') and 'svuint8_t' (aka '__SVUint8_t'))}}
11+
a / c; // sve-error {{cannot convert between vector and non-scalar values ('svmfloat8_t' (aka '__SVMfloat8_t') and 'svuint8_t' (aka '__SVUint8_t'))}}
12+
}
13+

clang/utils/TableGen/SveEmitter.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using TypeSpec = std::string;
5151

5252
namespace {
5353
class SVEType {
54-
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat;
54+
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat, MFloat;
5555
bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp,
5656
Svcount;
5757
unsigned Bitwidth, ElementBitwidth, NumVectors;
@@ -61,10 +61,10 @@ class SVEType {
6161

6262
SVEType(StringRef TS, char CharMod, unsigned NumVectors = 1)
6363
: Float(false), Signed(true), Immediate(false), Void(false),
64-
Constant(false), Pointer(false), BFloat(false), DefaultType(false),
65-
IsScalable(true), Predicate(false), PredicatePattern(false),
66-
PrefetchOp(false), Svcount(false), Bitwidth(128), ElementBitwidth(~0U),
67-
NumVectors(NumVectors) {
64+
Constant(false), Pointer(false), BFloat(false), MFloat(false),
65+
DefaultType(false), IsScalable(true), Predicate(false),
66+
PredicatePattern(false), PrefetchOp(false), Svcount(false),
67+
Bitwidth(128), ElementBitwidth(~0U), NumVectors(NumVectors) {
6868
if (!TS.empty())
6969
applyTypespec(TS);
7070
applyModifier(CharMod);
@@ -87,6 +87,10 @@ class SVEType {
8787
bool isDefault() const { return DefaultType; }
8888
bool isFloat() const { return Float && !BFloat; }
8989
bool isBFloat() const { return BFloat && !Float; }
90+
bool isMFloat() const {
91+
return MFloat && !BFloat && !Float;
92+
;
93+
}
9094
bool isFloatingPoint() const { return Float || BFloat; }
9195
bool isInteger() const {
9296
return !isFloatingPoint() && !Predicate && !Svcount;
@@ -454,6 +458,8 @@ std::string SVEType::builtin_str() const {
454458
else if (isBFloat()) {
455459
assert(ElementBitwidth == 16 && "Not a valid BFloat.");
456460
S += "y";
461+
} else if (isMFloat()) {
462+
S += "m";
457463
}
458464

459465
if (!isFloatingPoint()) {
@@ -509,6 +515,8 @@ std::string SVEType::str() const {
509515
S += "bool";
510516
else if (isBFloat())
511517
S += "bfloat";
518+
else if (isMFloat())
519+
S += "mfloat";
512520
else
513521
S += "int";
514522

@@ -574,6 +582,12 @@ void SVEType::applyTypespec(StringRef TS) {
574582
Float = false;
575583
ElementBitwidth = 16;
576584
break;
585+
case 'm':
586+
MFloat = true;
587+
Float = false;
588+
BFloat = false;
589+
ElementBitwidth = 8;
590+
break;
577591
default:
578592
llvm_unreachable("Unhandled type code!");
579593
}
@@ -1026,6 +1040,8 @@ std::string Intrinsic::replaceTemplatedArgs(std::string Name, TypeSpec TS,
10261040
TypeCode = 'b';
10271041
else if (T.isBFloat())
10281042
TypeCode = "bf";
1043+
else if (T.isMFloat())
1044+
TypeCode = "mfp";
10291045
else
10301046
TypeCode = 'f';
10311047
Ret.replace(Pos, NumChars, TypeCode + utostr(T.getElementSizeInBits()));
@@ -1119,6 +1135,11 @@ uint64_t SVEEmitter::encodeTypeFlags(const SVEType &T) {
11191135
return encodeEltType("EltTyBFloat16");
11201136
}
11211137

1138+
if (T.isMFloat()) {
1139+
assert(T.getElementSizeInBits() == 8 && "Not a valid MFloat.");
1140+
return encodeEltType("EltTyMFloat8");
1141+
}
1142+
11221143
if (T.isPredicateVector() || T.isSvcount()) {
11231144
switch (T.getElementSizeInBits()) {
11241145
case 8:
@@ -1296,6 +1317,8 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
12961317
OS << "#include <arm_bf16.h>\n";
12971318
OS << "#include <arm_vector_types.h>\n";
12981319

1320+
OS << "typedef __SVMfloat8_t svmfloat8_t;\n\n";
1321+
12991322
OS << "typedef __SVFloat32_t svfloat32_t;\n";
13001323
OS << "typedef __SVFloat64_t svfloat64_t;\n";
13011324
OS << "typedef __clang_svint8x2_t svint8x2_t;\n";

0 commit comments

Comments
 (0)