Skip to content

Commit 4da98aa

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 9e63632 commit 4da98aa

File tree

8 files changed

+75
-7
lines changed

8 files changed

+75
-7
lines changed

clang/include/clang/Basic/AArch64SVEACLETypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SVE_VECTOR_TYPE("__SVFloat32_t", "__SVFloat32_t", SveFloat32, SveFloat32Ty, 4, 3
7272
SVE_VECTOR_TYPE("__SVFloat64_t", "__SVFloat64_t", SveFloat64, SveFloat64Ty, 2, 64, true, true, false)
7373

7474
SVE_VECTOR_TYPE("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, SveBFloat16Ty, 8, 16, true, false, true)
75+
SVE_VECTOR_TYPE("__SVMfloat8_t", "__SVMfloat8_t", SveMFloat8, SveMFloat8Ty, 16, 8, false, false, false)
7576

7677
//
7778
// x2

clang/include/clang/Basic/arm_sve_sme_incl.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def EltTyBool16 : EltType<10>;
160160
def EltTyBool32 : EltType<11>;
161161
def EltTyBool64 : EltType<12>;
162162
def EltTyBFloat16 : EltType<13>;
163+
def EltTyMFloat8 : EltType<14>;
163164

164165
class MemEltType<int val> {
165166
int Value = val;

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ enum PredefinedTypeIDs {
11091109
///
11101110
/// Type IDs for non-predefined types will start at
11111111
/// NUM_PREDEF_TYPE_IDs.
1112-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1112+
const unsigned NUM_PREDEF_TYPE_IDS = 505;
11131113

11141114
// Ensure we do not overrun the predefined types we reserved
11151115
// in the enum PredefinedTypeIDs above.

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,7 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType *Ty) const {
39083908
llvm_unreachable("Unsupported builtin vector type");
39093909
case BuiltinType::SveInt8:
39103910
return SVE_INT_ELTTY(8, 16, true, 1);
3911+
case BuiltinType::SveMFloat8:
39113912
case BuiltinType::SveUint8:
39123913
return SVE_INT_ELTTY(8, 16, false, 1);
39133914
case BuiltinType::SveInt8x2:

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
493493
case BuiltinType::SveBFloat16:
494494
case BuiltinType::SveBFloat16x2:
495495
case BuiltinType::SveBFloat16x3:
496-
case BuiltinType::SveBFloat16x4: {
496+
case BuiltinType::SveBFloat16x4:
497+
case BuiltinType::SveMFloat8: {
497498
ASTContext::BuiltinVectorTypeInfo Info =
498499
Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
499500
return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),

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 +neon -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 +neon -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]] {
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]] {
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/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=scalar,neon,sve -triple aarch64-arm-none-eabi \
2+
// RUN: -target-feature -fp8 -target-feature +neon -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
@@ -67,7 +67,7 @@ class ImmCheck {
6767
};
6868

6969
class SVEType {
70-
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat;
70+
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat, MFloat;
7171
bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp,
7272
Svcount;
7373
unsigned Bitwidth, ElementBitwidth, NumVectors;
@@ -77,10 +77,10 @@ class SVEType {
7777

7878
SVEType(StringRef TS, char CharMod, unsigned NumVectors = 1)
7979
: Float(false), Signed(true), Immediate(false), Void(false),
80-
Constant(false), Pointer(false), BFloat(false), DefaultType(false),
81-
IsScalable(true), Predicate(false), PredicatePattern(false),
82-
PrefetchOp(false), Svcount(false), Bitwidth(128), ElementBitwidth(~0U),
83-
NumVectors(NumVectors) {
80+
Constant(false), Pointer(false), BFloat(false), MFloat(false),
81+
DefaultType(false), IsScalable(true), Predicate(false),
82+
PredicatePattern(false), PrefetchOp(false), Svcount(false),
83+
Bitwidth(128), ElementBitwidth(~0U), NumVectors(NumVectors) {
8484
if (!TS.empty())
8585
applyTypespec(TS);
8686
applyModifier(CharMod);
@@ -103,6 +103,10 @@ class SVEType {
103103
bool isDefault() const { return DefaultType; }
104104
bool isFloat() const { return Float && !BFloat; }
105105
bool isBFloat() const { return BFloat && !Float; }
106+
bool isMFloat() const {
107+
return MFloat && !BFloat && !Float;
108+
;
109+
}
106110
bool isFloatingPoint() const { return Float || BFloat; }
107111
bool isInteger() const {
108112
return !isFloatingPoint() && !Predicate && !Svcount;
@@ -447,6 +451,8 @@ std::string SVEType::builtin_str() const {
447451
else if (isBFloat()) {
448452
assert(ElementBitwidth == 16 && "Not a valid BFloat.");
449453
S += "y";
454+
} else if (isMFloat()) {
455+
S += "m";
450456
}
451457

452458
if (!isFloatingPoint()) {
@@ -502,6 +508,8 @@ std::string SVEType::str() const {
502508
S += "bool";
503509
else if (isBFloat())
504510
S += "bfloat";
511+
else if (isMFloat())
512+
S += "mfloat";
505513
else
506514
S += "int";
507515

@@ -567,6 +575,12 @@ void SVEType::applyTypespec(StringRef TS) {
567575
Float = false;
568576
ElementBitwidth = 16;
569577
break;
578+
case 'm':
579+
MFloat = true;
580+
Float = false;
581+
BFloat = false;
582+
ElementBitwidth = 8;
583+
break;
570584
default:
571585
llvm_unreachable("Unhandled type code!");
572586
}
@@ -1018,6 +1032,8 @@ std::string Intrinsic::replaceTemplatedArgs(std::string Name, TypeSpec TS,
10181032
TypeCode = 'b';
10191033
else if (T.isBFloat())
10201034
TypeCode = "bf";
1035+
else if (T.isMFloat())
1036+
TypeCode = "mfp";
10211037
else
10221038
TypeCode = 'f';
10231039
Ret.replace(Pos, NumChars, TypeCode + utostr(T.getElementSizeInBits()));
@@ -1111,6 +1127,11 @@ uint64_t SVEEmitter::encodeTypeFlags(const SVEType &T) {
11111127
return encodeEltType("EltTyBFloat16");
11121128
}
11131129

1130+
if (T.isMFloat()) {
1131+
assert(T.getElementSizeInBits() == 8 && "Not a valid MFloat.");
1132+
return encodeEltType("EltTyMFloat8");
1133+
}
1134+
11141135
if (T.isPredicateVector() || T.isSvcount()) {
11151136
switch (T.getElementSizeInBits()) {
11161137
case 8:
@@ -1288,6 +1309,8 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
12881309
OS << "#include <arm_bf16.h>\n";
12891310
OS << "#include <arm_vector_types.h>\n";
12901311

1312+
OS << "typedef __SVMfloat8_t svmfloat8_t;\n\n";
1313+
12911314
OS << "typedef __SVFloat32_t svfloat32_t;\n";
12921315
OS << "typedef __SVFloat64_t svfloat64_t;\n";
12931316
OS << "typedef __clang_svint8x2_t svint8x2_t;\n";

0 commit comments

Comments
 (0)