Skip to content

Commit

Permalink
[Clang][AArch64]Fix Name and Mangle name for scalar fp8 (#114983)
Browse files Browse the repository at this point in the history
The scalar __mfp8 type has the wrong name and mangle name in
AArch64SVEACLETypes.def

According to the ACLE[1] the name should be __mfp8

This patch fixes this problem by replacing
the Name __MFloat8_t by __mfp8
and
the Mangle Name __MFloat8_t by u6__mfp8

And we revert the incorrect typedef in NeonEmitter.

[1]https://github.com/ARM-software/acle
  • Loading branch information
CarolineConcatto authored Nov 15, 2024
1 parent fda4a32 commit 91aad9b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 73 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/AArch64SVEACLETypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", SveBoolx4, SveBoolx4T

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

AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8_t", "__MFloat8_t", MFloat8, MFloat8Ty, 1, 8, 1)
AARCH64_VECTOR_TYPE_MFLOAT("__mfp8", "__mfp8", MFloat8, MFloat8Ty, 1, 8, 1)
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x8_t", "__MFloat8x8_t", MFloat8x8, MFloat8x8Ty, 8, 8, 1)
AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", "__MFloat8x16_t", MFloat8x16, MFloat8x16Ty, 16, 8, 1)

Expand Down
57 changes: 28 additions & 29 deletions clang/test/AST/arm-mfp8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

/* Various contexts where type __mfp8 can appear. */

#include<arm_neon.h>
/* Namespace */
namespace {
__mfp8 f2n;
__mfp8 arr1n[10];
}

//CHECK: |-NamespaceDecl {{.*}}
//CHECK-NEXT: | |-VarDecl {{.*}} f2n '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | |-VarDecl {{.*}} f2n '__mfp8'
//CHECK-NEXT: | `-VarDecl {{.*}} arr1n '__mfp8[10]'


Expand All @@ -24,22 +23,22 @@ namespace {
return f1n;
}
//CHECK: |-FunctionDecl {{.*}} func1n 'const __mfp8 (const __mfp8)'
//CHECK: | `-VarDecl {{.*}} f1n '__mfp8':'__MFloat8_t'
//CHECK-NEXT: |-BinaryOperator {{.*}} '__mfp8':'__MFloat8_t' lvalue '='
//CHECK-NEXT: | |-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue Var {{.*}} 'f1n' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: | `-DeclRefExpr {{.*}} 'const __mfp8':'const __MFloat8_t' lvalue ParmVar {{.*}} 'mfp8' 'const __mfp8':'const __MFloat8_t'
//CHECK: | `-VarDecl {{.*}} f1n '__mfp8'
//CHECK-NEXT: |-BinaryOperator {{.*}} '__mfp8' lvalue '='
//CHECK-NEXT: | |-DeclRefExpr {{.*}} '__mfp8' lvalue Var {{.*}} 'f1n' '__mfp8'
//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: | `-DeclRefExpr {{.*}} 'const __mfp8' lvalue ParmVar {{.*}} 'mfp8' 'const __mfp8'
//CHECK-NEXT: `-ReturnStmt {{.*}}
//CHECK-NEXT: `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: `-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue Var {{.*}} 'f1n' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: `-DeclRefExpr {{.*}} '__mfp8' lvalue Var {{.*}} 'f1n' '__mfp8'


/* Class */

class C1 {
__mfp8 f1c;
static const __mfp8 f2c;
volatile __MFloat8_t f3c;
volatile __mfp8 f3c;
public:
C1(__mfp8 arg) : f1c(arg), f3c(arg) { }
__mfp8 func1c(__mfp8 arg ) {
Expand All @@ -51,31 +50,31 @@ class C1 {
};

//CHECK: | |-CXXRecordDecl {{.*}} referenced class C1
//CHECK-NEXT: | |-FieldDecl {{.*}} f1c '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | |-VarDecl {{.*}} f2c 'const __mfp8':'const __MFloat8_t' static
//CHECK-NEXT: | |-FieldDecl {{.*}} f3c 'volatile __MFloat8_t'
//CHECK-NEXT: | |-FieldDecl {{.*}} f1c '__mfp8'
//CHECK-NEXT: | |-VarDecl {{.*}} f2c 'const __mfp8' static
//CHECK-NEXT: | |-FieldDecl {{.*}} f3c 'volatile __mfp8'
//CHECK-NEXT: | |-AccessSpecDecl {{.*}}
//CHECK-NEXT: | |-CXXConstructorDecl {{.*}} C1 'void (__mfp8)' implicit-inline
//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f1c' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue ParmVar {{.*}} 'arg' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f3c' 'volatile __MFloat8_t'
//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue ParmVar {{.*}} 'arg' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8'
//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f1c' '__mfp8'
//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
//CHECK-NEXT: | | |-CXXCtorInitializer {{.*}} 'f3c' 'volatile __mfp8'
//CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: | | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
//CHECK-NEXT: | | `-CompoundStmt {{.*}}
//CHECK-NEXT: | |-CXXMethodDecl {{.*}} func1c '__mfp8 (__mfp8)' implicit-inline
//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | |-ParmVarDecl {{.*}} arg '__mfp8'
//CHECK-NEXT: | | `-CompoundStmt {{.*}}
//CHECK-NEXT: | | `-ReturnStmt {{.*}}
//CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: | | `-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue ParmVar {{.*}} 'arg' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: | | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'
//CHECK-NEXT: | `-CXXMethodDecl {{.*}} func2c '__mfp8 (__mfp8)' static implicit-inline
//CHECK-NEXT: | |-ParmVarDecl {{.*}} arg '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | |-ParmVarDecl {{.*}} arg '__mfp8'
//CHECK-NEXT: | `-CompoundStmt {{.*}}
//CHECK-NEXT: | `-ReturnStmt {{.*}}
//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8':'__MFloat8_t' <LValueToRValue>
//CHECK-NEXT: | `-DeclRefExpr {{.*}} '__mfp8':'__MFloat8_t' lvalue ParmVar {{.*}} 'arg' '__mfp8':'__MFloat8_t'
//CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__mfp8' <LValueToRValue>
//CHECK-NEXT: | `-DeclRefExpr {{.*}} '__mfp8' lvalue ParmVar {{.*}} 'arg' '__mfp8'

template <class C> struct S1 {
C mem1;
Expand All @@ -85,7 +84,7 @@ template <> struct S1<__mfp8> {
__mfp8 mem2;
};

//CHECK: |-TemplateArgument type '__MFloat8_t'
//CHECK-NEXT: | `-BuiltinType {{.*}} '__MFloat8_t'
//CHECK: |-TemplateArgument type '__mfp8'
//CHECK-NEXT: | `-BuiltinType {{.*}} '__mfp8'
//CHECK-NEXT: |-CXXRecordDecl {{.*}} implicit struct S1
//CHECK-NEXT: `-FieldDecl {{.*}} mem2 '__mfp8':'__MFloat8_t'
//CHECK-NEXT: `-FieldDecl {{.*}} mem2 '__mfp8'
10 changes: 4 additions & 6 deletions clang/test/CodeGen/AArch64/debug-types.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 \
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature -fp8 \
// RUN: -emit-llvm -o - %s -debug-info-kind=limited 2>&1 | FileCheck %s

// REQUIRES: aarch64-registered-target

#include<arm_neon.h>

void test_locals(void) {
// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "__MFloat8_t", {{.*}}, baseType: ![[ELTTYU8:[0-9]+]]
// CHECK-DAG: ![[ELTTYU8]] = !DIBasicType(name: "__MFloat8_t", size: 8, encoding: DW_ATE_unsigned_char)
__MFloat8_t mfp8;
// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "__mfp8", {{.*}}, baseType: ![[ELTTYU8:[0-9]+]]
// CHECK-DAG: ![[ELTTYU8]] = !DIBasicType(name: "__mfp8", size: 8, encoding: DW_ATE_unsigned_char)
__mfp8 mfp8;
}
2 changes: 1 addition & 1 deletion clang/test/CodeGen/arm-mfp8.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mfloat8x8_t test_ret_mfloat8x8_t(mfloat8x8_t v) {
// CHECK-C-NEXT: [[TMP1:%.*]] = load <1 x i8>, ptr [[ARRAYIDX1]], align 1
// CHECK-C-NEXT: ret <1 x i8> [[TMP1]]
//
// CHECK-CXX-LABEL: define dso_local <1 x i8> @_Z6func1nu11__MFloat8_t(
// CHECK-CXX-LABEL: define dso_local <1 x i8> @_Z6func1nu6__mfp8(
// CHECK-CXX-SAME: <1 x i8> [[MFP8:%.*]]) #[[ATTR0]] {
// CHECK-CXX-NEXT: [[ENTRY:.*:]]
// CHECK-CXX-NEXT: [[MFP8_ADDR:%.*]] = alloca <1 x i8>, align 1
Expand Down
5 changes: 2 additions & 3 deletions clang/test/Sema/arm-mfp8.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-arm-none-eabi -target-feature -fp8 %s

// REQUIRES: aarch64-registered-target
#include<arm_neon.h>
__mfp8 test_cast_from_float(unsigned in) {
return (__mfp8)in; // expected-error {{used type '__mfp8' (aka '__MFloat8_t') where arithmetic or pointer type is required}}
return (__mfp8)in; // expected-error {{used type '__mfp8' where arithmetic or pointer type is required}}
}

unsigned test_cast_to_int(__mfp8 in) {
return (unsigned)in; // expected-error {{operand of type '__mfp8' (aka '__MFloat8_t') where arithmetic or pointer type is required}}
return (unsigned)in; // expected-error {{operand of type '__mfp8' where arithmetic or pointer type is required}}
}
65 changes: 33 additions & 32 deletions clang/test/Sema/arm-mfp8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@

// REQUIRES: aarch64-registered-target

__mfp8 test_static_cast_from_char(char in) {
return static_cast<__mfp8>(in); // scalar-error {{static_cast from 'char' to '__mfp8' is not allowed}}
}

char test_static_cast_to_char(__mfp8 in) {
return static_cast<char>(in); // scalar-error {{static_cast from '__mfp8' to 'char' is not allowed}}
}

void test(bool b) {
__mfp8 mfp8;

mfp8 + mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
mfp8 - mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
mfp8 * mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
mfp8 / mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' and '__mfp8')}}
++mfp8; // scalar-error {{cannot increment value of type '__mfp8'}}
--mfp8; // scalar-error {{cannot decrement value of type '__mfp8'}}

char u8;

mfp8 + u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
u8 + mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
mfp8 - u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
u8 - mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
mfp8 * u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
u8 * mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
mfp8 / u8; // scalar-error {{invalid operands to binary expression ('__mfp8' and 'char')}}
u8 / mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8')}}
mfp8 = u8; // scalar-error {{assigning to '__mfp8' from incompatible type 'char'}}
u8 = mfp8; // scalar-error {{assigning to 'char' from incompatible type '__mfp8'}}
mfp8 + (b ? u8 : mfp8); // scalar-error {{incompatible operand types ('char' and '__mfp8')}}
}

#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}}
Expand All @@ -29,35 +62,3 @@ void test_vector(mfloat8x8_t a, mfloat8x16_t b, uint8x8_t c) {
c * b; // neon-error {{cannot convert between vector and non-scalar values ('uint8x8_t' (vector of 8 'uint8_t' values) and 'mfloat8x16_t' (aka '__MFloat8x16_t'))}}
c / b; // neon-error {{cannot convert between vector and non-scalar values ('uint8x8_t' (vector of 8 'uint8_t' values) and 'mfloat8x16_t' (aka '__MFloat8x16_t'))}}
}
__mfp8 test_static_cast_from_char(char in) {
return static_cast<__mfp8>(in); // scalar-error {{static_cast from 'char' to '__mfp8' (aka '__MFloat8_t') is not allowed}}
}

char test_static_cast_to_char(__mfp8 in) {
return static_cast<char>(in); // scalar-error {{static_cast from '__mfp8' (aka '__MFloat8_t') to 'char' is not allowed}}
}
void test(bool b) {
__mfp8 mfp8;

mfp8 + mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and '__mfp8')}}
mfp8 - mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and '__mfp8')}}
mfp8 * mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and '__mfp8')}}
mfp8 / mfp8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and '__mfp8')}}
++mfp8; // scalar-error {{cannot increment value of type '__mfp8' (aka '__MFloat8_t')}}
--mfp8; // scalar-error {{cannot decrement value of type '__mfp8' (aka '__MFloat8_t')}}

char u8;

mfp8 + u8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and 'char')}}
u8 + mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8' (aka '__MFloat8_t'))}}
mfp8 - u8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and 'char')}}
u8 - mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8' (aka '__MFloat8_t'))}}
mfp8 * u8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and 'char')}}
u8 * mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8' (aka '__MFloat8_t'))}}
mfp8 / u8; // scalar-error {{invalid operands to binary expression ('__mfp8' (aka '__MFloat8_t') and 'char')}}
u8 / mfp8; // scalar-error {{invalid operands to binary expression ('char' and '__mfp8' (aka '__MFloat8_t'))}}
mfp8 = u8; // scalar-error {{assigning to '__mfp8' (aka '__MFloat8_t') from incompatible type 'char'}}
u8 = mfp8; // scalar-error {{assigning to 'char' from incompatible type '__mfp8' (aka '__MFloat8_t')}}
mfp8 + (b ? u8 : mfp8); // scalar-error {{incompatible operand types ('char' and '__mfp8' (aka '__MFloat8_t'))}}
}

2 changes: 1 addition & 1 deletion clang/utils/TableGen/NeonEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ void NeonEmitter::runVectorTypes(raw_ostream &OS) {
OS << "typedef __fp16 float16_t;\n";

OS << "#if defined(__aarch64__) || defined(__arm64ec__)\n";
OS << "typedef __MFloat8_t __mfp8;\n";
OS << "typedef __mfp8 mfloat8_t;\n";
OS << "typedef __MFloat8x8_t mfloat8x8_t;\n";
OS << "typedef __MFloat8x16_t mfloat8x16_t;\n";
OS << "typedef double float64_t;\n";
Expand Down

0 comments on commit 91aad9b

Please sign in to comment.