Skip to content

Commit

Permalink
[CLANG]Add Scalable vectors for mfloat8_t (#101644)
Browse files Browse the repository at this point in the history
This patch adds these new vector sizes for sve:
    svmfloat8_t

According to the ARM ACLE PR#323[1].

[1] ARM-software/acle#323
  • Loading branch information
CarolineConcatto authored Oct 17, 2024
1 parent 4cda28c commit cb43021
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 10 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/AArch64SVEACLETypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ SVE_VECTOR_TYPE_FLOAT("__SVFloat64_t", "__SVFloat64_t", SveFloat64, SveFloat64Ty

SVE_VECTOR_TYPE_BFLOAT("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, SveBFloat16Ty, 8, 16, 1)

// This is a 8 bits opaque type.
SVE_VECTOR_TYPE_INT("__SVMfloat8_t", "__SVMfloat8_t", SveMFloat8, SveMFloat8Ty, 16, 8, 1, false)

//
// x2
//
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/arm_sve_sme_incl.td
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def EltTyBool16 : EltType<10>;
def EltTyBool32 : EltType<11>;
def EltTyBool64 : EltType<12>;
def EltTyBFloat16 : EltType<13>;
def EltTyMFloat8 : EltType<14>;

class MemEltType<int val> {
int Value = val;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Serialization/ASTBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,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.
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,7 @@ bool Type::isSveVLSBuiltinType() const {
case BuiltinType::SveBool:
case BuiltinType::SveBoolx2:
case BuiltinType::SveBoolx4:
case BuiltinType::SveMFloat8:
return true;
default:
return false;
Expand Down
3 changes: 3 additions & 0 deletions clang/test/AST/ast-dump-aarch64-sve-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
// CHECK: TypedefDecl {{.*}} implicit __SVBfloat16_t '__SVBfloat16_t'
// CHECK-NEXT: -BuiltinType {{.*}} '__SVBfloat16_t'

// CHECK: TypedefDecl {{.*}} implicit __SVMfloat8_t '__SVMfloat8_t'
// CHECK-NEXT: -BuiltinType {{.*}} '__SVMfloat8_t'

// CHECK: TypedefDecl {{.*}} implicit __SVBool_t '__SVBool_t'
// CHECK-NEXT: -BuiltinType {{.*}} '__SVBool_t'

Expand Down
2 changes: 2 additions & 0 deletions clang/test/CodeGen/aarch64-sve.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// CHECK: %f16 = alloca <vscale x 8 x half>, align 16
// CHECK: %f32 = alloca <vscale x 4 x float>, align 16
// CHECK: %f64 = alloca <vscale x 2 x double>, align 16
// CHECK: %mf8 = alloca <vscale x 16 x i8>, align 16
// CHECK: %bf16 = alloca <vscale x 8 x bfloat>, align 16
// CHECK: %b8 = alloca <vscale x 16 x i1>, align 2

Expand All @@ -33,6 +34,7 @@ void test_locals(void) {
__SVFloat32_t f32;
__SVFloat64_t f64;

__SVMfloat8_t mf8;
__SVBfloat16_t bf16;

__SVBool_t b8;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void f(__SVFloat16_t, __SVFloat16_t);
void f(__SVFloat32_t, __SVFloat32_t);
void f(__SVFloat64_t, __SVFloat64_t);
void f(__SVBfloat16_t, __SVBfloat16_t);
void f(__SVMfloat8_t, __SVMfloat8_t);
void f(__SVBool_t, __SVBool_t);
void f(__SVCount_t, __SVCount_t);

Expand Down Expand Up @@ -150,6 +151,7 @@ void f(__clang_svboolx4_t, __clang_svboolx4_t);
// CHECK-NEXT: call void @_Z1fu13__SVFloat16_tS_(<vscale x 8 x half> zeroinitializer, <vscale x 8 x half> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu13__SVFloat32_tS_(<vscale x 4 x float> zeroinitializer, <vscale x 4 x float> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu13__SVFloat64_tS_(<vscale x 2 x double> zeroinitializer, <vscale x 2 x double> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu13__SVMfloat8_tS_(<vscale x 16 x i8> zeroinitializer, <vscale x 16 x i8> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu14__SVBfloat16_tS_(<vscale x 8 x bfloat> zeroinitializer, <vscale x 8 x bfloat> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu10__SVBool_tS_(<vscale x 16 x i1> zeroinitializer, <vscale x 16 x i1> zeroinitializer)
// CHECK-NEXT: call void @_Z1fu11__SVCount_tS_(target("aarch64.svcount") zeroinitializer, target("aarch64.svcount") zeroinitializer)
Expand Down Expand Up @@ -664,6 +666,7 @@ void f(__clang_svboolx4_t, __clang_svboolx4_t);
// COMPAT_17-NEXT: call void @_Z1fu13__SVFloat16_tu13__SVFloat16_t(<vscale x 8 x half> zeroinitializer, <vscale x 8 x half> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu13__SVFloat32_tu13__SVFloat32_t(<vscale x 4 x float> zeroinitializer, <vscale x 4 x float> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu13__SVFloat64_tu13__SVFloat64_t(<vscale x 2 x double> zeroinitializer, <vscale x 2 x double> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu13__SVMfloat8_tu13__SVMfloat8_t(<vscale x 16 x i8> zeroinitializer, <vscale x 16 x i8> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu14__SVBFloat16_tu14__SVBFloat16_t(<vscale x 8 x bfloat> zeroinitializer, <vscale x 8 x bfloat> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu10__SVBool_tu10__SVBool_t(<vscale x 16 x i1> zeroinitializer, <vscale x 16 x i1> zeroinitializer)
// COMPAT_17-NEXT: call void @_Z1fu11__SVCount_tu11__SVCount_t(target("aarch64.svcount") zeroinitializer, target("aarch64.svcount") zeroinitializer)
Expand Down Expand Up @@ -1100,6 +1103,7 @@ void foo() {
f(__SVFloat16_t(), __SVFloat16_t());
f(__SVFloat32_t(), __SVFloat32_t());
f(__SVFloat64_t(), __SVFloat64_t());
f(__SVMfloat8_t(), __SVMfloat8_t());
f(__SVBfloat16_t(), __SVBfloat16_t());
f(__SVBool_t(), __SVBool_t());
f(__SVCount_t(), __SVCount_t());
Expand Down
5 changes: 5 additions & 0 deletions clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ auto &f64 = typeid(__SVFloat64_t);

auto &bf16 = typeid(__SVBfloat16_t);

auto &mf8 = typeid(__SVMfloat8_t);

auto &b8 = typeid(__SVBool_t);
auto &c8 = typeid(__SVCount_t);

Expand Down Expand Up @@ -60,6 +62,9 @@ auto &c8 = typeid(__SVCount_t);
// CHECK-DAG: @_ZTSu14__SVBfloat16_t = {{.*}} c"u14__SVBfloat16_t\00"
// CHECK-DAG: @_ZTIu14__SVBfloat16_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu14__SVBfloat16_t

// CHECK-DAG: @_ZTSu13__SVMfloat8_t = {{.*}} c"u13__SVMfloat8_t\00"
// CHECK-DAG: @_ZTIu13__SVMfloat8_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu13__SVMfloat8_t

// CHECK-DAG: @_ZTSu10__SVBool_t = {{.*}} c"u10__SVBool_t\00"
// CHECK-DAG: @_ZTIu10__SVBool_t = {{.*}} @_ZTVN10__cxxabiv123__fundamental_type_infoE, {{.*}} @_ZTSu10__SVBool_t

Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// CHECK-NEXT: [[U16:%.*]] = alloca <vscale x 8 x i16>, align 16
// CHECK-NEXT: [[U32:%.*]] = alloca <vscale x 4 x i32>, align 16
// CHECK-NEXT: [[U64:%.*]] = alloca <vscale x 2 x i64>, align 16
// CHECK-NEXT: [[MF8:%.*]] = alloca <vscale x 16 x i8>, align 16
// CHECK-NEXT: [[F16:%.*]] = alloca <vscale x 8 x half>, align 16
// CHECK-NEXT: [[F32:%.*]] = alloca <vscale x 4 x float>, align 16
// CHECK-NEXT: [[F64:%.*]] = alloca <vscale x 2 x double>, align 16
Expand Down Expand Up @@ -64,6 +65,7 @@
// CHECK-NEXT: store <vscale x 8 x i16> zeroinitializer, ptr [[U16]], align 16
// CHECK-NEXT: store <vscale x 4 x i32> zeroinitializer, ptr [[U32]], align 16
// CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[U64]], align 16
// CHECK-NEXT: store <vscale x 16 x i8> zeroinitializer, ptr [[MF8]], align 16
// CHECK-NEXT: store <vscale x 8 x half> zeroinitializer, ptr [[F16]], align 16
// CHECK-NEXT: store <vscale x 4 x float> zeroinitializer, ptr [[F32]], align 16
// CHECK-NEXT: store <vscale x 2 x double> zeroinitializer, ptr [[F64]], align 16
Expand Down Expand Up @@ -119,6 +121,7 @@ void test_locals(void) {
__SVUint16_t u16{};
__SVUint32_t u32{};
__SVUint64_t u64{};
__SVMfloat8_t mf8{};
__SVFloat16_t f16{};
__SVFloat32_t f32{};
__SVFloat64_t f64{};
Expand Down Expand Up @@ -282,6 +285,20 @@ void test_copy_u64(__SVUint64_t a) {
__SVUint64_t b{a};
}

// CHECK-LABEL: define dso_local void @_Z13test_copy_mf8u13__SVMfloat8_t
// CHECK-SAME: (<vscale x 16 x i8> [[A:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca <vscale x 16 x i8>, align 16
// CHECK-NEXT: [[B:%.*]] = alloca <vscale x 16 x i8>, align 16
// CHECK-NEXT: store <vscale x 16 x i8> [[A]], ptr [[A_ADDR]], align 16
// CHECK-NEXT: [[TMP0:%.*]] = load <vscale x 16 x i8>, ptr [[A_ADDR]], align 16
// CHECK-NEXT: store <vscale x 16 x i8> [[TMP0]], ptr [[B]], align 16
// CHECK-NEXT: ret void
//
void test_copy_mf8(__SVMfloat8_t a) {
__SVMfloat8_t b{a};
}

// CHECK-LABEL: define dso_local void @_Z13test_copy_f16u13__SVFloat16_t
// CHECK-SAME: (<vscale x 8 x half> [[A:%.*]]) #[[ATTR0]] {
// CHECK-NEXT: entry:
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGenObjC/aarch64-sve-types.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
// CHECK: error: cannot yet @encode type __SVBfloat16_t
const char bf16[] = @encode(__SVBfloat16_t);

// CHECK: error: cannot yet @encode type __SVMfloat8_t
const char mf8[] = @encode(__SVMfloat8_t);

// CHECK: error: cannot yet @encode type __SVBool_t
const char b8[] = @encode(__SVBool_t);
2 changes: 1 addition & 1 deletion clang/test/Modules/no-external-type-id.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Sema/aarch64-sve-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void f(void) {
int size_bf16[sizeof(__SVBfloat16_t) == 0 ? 1 : -1]; // expected-error {{invalid application of 'sizeof' to sizeless type '__SVBfloat16_t'}}
int align_bf16[__alignof__(__SVBfloat16_t) == 16 ? 1 : -1]; // expected-error {{invalid application of '__alignof' to sizeless type '__SVBfloat16_t'}}

int size_mf8[sizeof(__SVMfloat8_t) == 0 ? 1 : -1]; // expected-error {{invalid application of 'sizeof' to sizeless type '__SVMfloat8_t'}}
int align_mf8[__alignof__(__SVMfloat8_t) == 16 ? 1 : -1]; // expected-error {{invalid application of '__alignof' to sizeless type '__SVMfloat8_t'}}

int size_b8[sizeof(__SVBool_t) == 0 ? 1 : -1]; // expected-error {{invalid application of 'sizeof' to sizeless type '__SVBool_t'}}
int align_b8[__alignof__(__SVBool_t) == 2 ? 1 : -1]; // expected-error {{invalid application of '__alignof' to sizeless type '__SVBool_t'}}
}
13 changes: 13 additions & 0 deletions clang/test/Sema/arm-mfp8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -fsyntax-only -verify=sve -triple aarch64-arm-none-eabi \
// RUN: -target-feature -fp8 -target-feature +sve %s

// REQUIRES: aarch64-registered-target

#include <arm_sve.h>
void test_vector_sve(svmfloat8_t a, svuint8_t c) {
a + c; // sve-error {{cannot convert between vector type 'svuint8_t' (aka '__SVUint8_t') and vector type 'svmfloat8_t' (aka '__SVMfloat8_t') as implicit conversion would cause truncation}}
a - c; // sve-error {{cannot convert between vector type 'svuint8_t' (aka '__SVUint8_t') and vector type 'svmfloat8_t' (aka '__SVMfloat8_t') as implicit conversion would cause truncation}}
a * c; // sve-error {{cannot convert between vector type 'svuint8_t' (aka '__SVUint8_t') and vector type 'svmfloat8_t' (aka '__SVMfloat8_t') as implicit conversion would cause truncation}}
a / c; // sve-error {{cannot convert between vector type 'svuint8_t' (aka '__SVUint8_t') and vector type 'svmfloat8_t' (aka '__SVMfloat8_t') as implicit conversion would cause truncation}}
}

2 changes: 2 additions & 0 deletions clang/test/SemaObjC/aarch64-sve-types.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ @interface foo

@property(nullable) __SVBfloat16_t bf16; // expected-error {{cannot be applied to non-pointer type}}

@property(nullable) __SVMfloat8_t mf8; // expected-error {{cannot be applied to non-pointer type}}

@property(nullable) __SVBool_t b8; // expected-error {{cannot be applied to non-pointer type}}
@end
41 changes: 33 additions & 8 deletions clang/utils/TableGen/SveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using TypeSpec = std::string;

namespace {
class SVEType {
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat;
bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat, MFloat;
bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp,
Svcount;
unsigned Bitwidth, ElementBitwidth, NumVectors;
Expand All @@ -61,10 +61,10 @@ class SVEType {

SVEType(StringRef TS, char CharMod, unsigned NumVectors = 1)
: Float(false), Signed(true), Immediate(false), Void(false),
Constant(false), Pointer(false), BFloat(false), DefaultType(false),
IsScalable(true), Predicate(false), PredicatePattern(false),
PrefetchOp(false), Svcount(false), Bitwidth(128), ElementBitwidth(~0U),
NumVectors(NumVectors) {
Constant(false), Pointer(false), BFloat(false), MFloat(false),
DefaultType(false), IsScalable(true), Predicate(false),
PredicatePattern(false), PrefetchOp(false), Svcount(false),
Bitwidth(128), ElementBitwidth(~0U), NumVectors(NumVectors) {
if (!TS.empty())
applyTypespec(TS);
applyModifier(CharMod);
Expand All @@ -82,11 +82,14 @@ class SVEType {
bool isVector() const { return NumVectors > 0; }
bool isScalableVector() const { return isVector() && IsScalable; }
bool isFixedLengthVector() const { return isVector() && !IsScalable; }
bool isChar() const { return ElementBitwidth == 8; }
bool isChar() const { return ElementBitwidth == 8 && !MFloat; }
bool isVoid() const { return Void && !Pointer; }
bool isDefault() const { return DefaultType; }
bool isFloat() const { return Float && !BFloat; }
bool isBFloat() const { return BFloat && !Float; }
bool isFloat() const { return Float && !BFloat && !MFloat; }
bool isBFloat() const { return BFloat && !Float && !MFloat; }
bool isMFloat() const {
return MFloat && !BFloat && !Float;
}
bool isFloatingPoint() const { return Float || BFloat; }
bool isInteger() const {
return !isFloatingPoint() && !Predicate && !Svcount;
Expand Down Expand Up @@ -454,6 +457,9 @@ std::string SVEType::builtin_str() const {
else if (isBFloat()) {
assert(ElementBitwidth == 16 && "Not a valid BFloat.");
S += "y";
} else if (isMFloat()) {
assert(ElementBitwidth == 8 && "Not a valid MFloat.");
S += "m";
}

if (!isFloatingPoint()) {
Expand Down Expand Up @@ -509,6 +515,8 @@ std::string SVEType::str() const {
S += "bool";
else if (isBFloat())
S += "bfloat";
else if (isMFloat())
S += "mfloat";
else
S += "int";

Expand Down Expand Up @@ -572,8 +580,16 @@ void SVEType::applyTypespec(StringRef TS) {
case 'b':
BFloat = true;
Float = false;
MFloat = false;
ElementBitwidth = 16;
break;
case 'm':
Signed = false;
MFloat = true;
Float = false;
BFloat = false;
ElementBitwidth = 8;
break;
default:
llvm_unreachable("Unhandled type code!");
}
Expand Down Expand Up @@ -1037,6 +1053,8 @@ std::string Intrinsic::replaceTemplatedArgs(std::string Name, TypeSpec TS,
TypeCode = 'b';
else if (T.isBFloat())
TypeCode = "bf";
else if (T.isMFloat())
TypeCode = "mfp";
else
TypeCode = 'f';
Ret.replace(Pos, NumChars, TypeCode + utostr(T.getElementSizeInBits()));
Expand Down Expand Up @@ -1130,6 +1148,11 @@ uint64_t SVEEmitter::encodeTypeFlags(const SVEType &T) {
return encodeEltType("EltTyBFloat16");
}

if (T.isMFloat()) {
assert(T.getElementSizeInBits() == 8 && "Not a valid MFloat.");
return encodeEltType("EltTyMFloat8");
}

if (T.isPredicateVector() || T.isSvcount()) {
switch (T.getElementSizeInBits()) {
case 8:
Expand Down Expand Up @@ -1305,6 +1328,8 @@ void SVEEmitter::createHeader(raw_ostream &OS) {
OS << "#include <arm_bf16.h>\n";
OS << "#include <arm_vector_types.h>\n";

OS << "typedef __SVMfloat8_t svmfloat8_t;\n\n";

OS << "typedef __SVFloat32_t svfloat32_t;\n";
OS << "typedef __SVFloat64_t svfloat64_t;\n";
OS << "typedef __clang_svint8x2_t svint8x2_t;\n";
Expand Down

0 comments on commit cb43021

Please sign in to comment.