Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model accumulators as integers + support missing broadcast intrinsics. #270

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Modifications (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its
// Modifications (c) Copyright 2023-2025 Advanced Micro Devices, Inc. or its
// affiliates
//
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -2670,9 +2670,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
/// set of type specifiers.
bool isSpecifierType() const;

/// Returns true if this is a AIE ACC48.
/// Returns true if this is a AIE accumulator type.
bool isAIEAccumulatorType() const;

/// Returns true if this is a AIE integer accumulator type.
bool isAIEIntegerAccumulatorType() const;

/// Determine the linkage of this type.
Linkage getLinkage() const;

Expand Down Expand Up @@ -7745,8 +7748,9 @@ bool IsEnumDeclScoped(EnumDecl *);

inline bool Type::isIntegerType() const {
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Int128;
return isAIEIntegerAccumulatorType() ||
(BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Int128);
if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
// Incomplete enum types are not treated as integer types.
// FIXME: In C++, enum types are never integer types.
Expand Down Expand Up @@ -7803,12 +7807,10 @@ inline bool Type::isUnsignedFixedPointType() const {
}

inline bool Type::isScalarType() const {
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
if (isAIEAccumulatorType())
return true;
return BT->getKind() > BuiltinType::Void &&
BT->getKind() <= BuiltinType::NullPtr;
}
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
return isAIEAccumulatorType() || (BT->getKind() > BuiltinType::Void &&
BT->getKind() <= BuiltinType::NullPtr);

if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
// Enums are scalar types, but only if they are defined. Incomplete enums
// are not treated as scalar types.
Expand All @@ -7823,8 +7825,9 @@ inline bool Type::isScalarType() const {

inline bool Type::isIntegralOrEnumerationType() const {
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Int128;
return isAIEIntegerAccumulatorType() ||
(BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Int128);

// Check for a complete enum type; incomplete enum types are not properly an
// enumeration type in the sense required here.
Expand Down Expand Up @@ -7860,10 +7863,14 @@ inline bool Type::isTypedefNameType() const {
return false;
}

inline bool Type::isAIEAccumulatorType() const {
inline bool Type::isAIEIntegerAccumulatorType() const {
return (isSpecificBuiltinType(BuiltinType::ACC32) ||
isSpecificBuiltinType(BuiltinType::ACC48) ||
isSpecificBuiltinType(BuiltinType::ACC64) ||
isSpecificBuiltinType(BuiltinType::ACC64));
}

inline bool Type::isAIEAccumulatorType() const {
return (isAIEIntegerAccumulatorType() ||
isSpecificBuiltinType(BuiltinType::ACCFLOAT));
}

Expand Down
12 changes: 1 addition & 11 deletions clang/lib/Headers/aie2p_aie_api_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
// (c) Copyright 2024-2025 Advanced Micro Devices, Inc. or its affiliates
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -731,12 +731,6 @@ inline __attribute__((always_inline)) v16uint32 broadcast_to_v16uint32(v2uint32
inline __attribute__((always_inline)) v16cint16 broadcast_to_v16cint16(cint16 );
inline __attribute__((always_inline)) v16cint16 broadcast_to_v16cint16(v2cint16 );
inline __attribute__((always_inline)) v8cint32 broadcast_to_v8cint32(cint32 );
inline __attribute__((always_inline)) v64int8 broadcast_one_to_v64int8();
inline __attribute__((always_inline)) v32int16 broadcast_one_to_v32int16();
inline __attribute__((always_inline)) v16int32 broadcast_one_to_v16int32();
inline __attribute__((always_inline)) v64uint8 broadcast_one_to_v64uint8();
inline __attribute__((always_inline)) v32uint16 broadcast_one_to_v32uint16();
inline __attribute__((always_inline)) v16uint32 broadcast_one_to_v16uint32();
inline __attribute__((always_inline)) v16cint16 broadcast_one_to_v16cint16();
inline __attribute__((always_inline)) v8cint32 broadcast_one_to_v8cint32();
inline __attribute__((always_inline)) v16cint16 broadcast_one_c16();
Expand Down Expand Up @@ -2783,10 +2777,6 @@ inline __attribute__((always_inline)) v32acc64 mac_4x8_8x8_conf(v32int16 , int ,
inline __attribute__((always_inline)) v32acc64 msc_4x8_8x8_conf(v32int16 , int , v64int16_sparse , int , v32acc64 , int , int , int , int );
inline __attribute__((always_inline)) v32acc64 addmac_4x8_8x8_conf(v32int16 , int , v64int16_sparse , int , v32acc64 , v32acc64 , int , int , int , int , int );
inline __attribute__((always_inline)) v32acc64 addmsc_4x8_8x8_conf(v32int16 , int , v64int16_sparse , int , v32acc64 , v32acc64 , int , int , int , int , int );
inline __attribute__((always_inline)) v64acc32 clr64();
inline __attribute__((always_inline)) v64acc32 broadcast_zero_to_v64acc32();
inline __attribute__((always_inline)) v32acc64 clr32();
inline __attribute__((always_inline)) v32acc64 broadcast_zero_to_v32acc64();
inline __attribute__((always_inline)) v16cacc64 add(v16cacc64 , v16cacc64 );
inline __attribute__((always_inline)) v16cacc64 sub(v16cacc64 , v16cacc64 );
inline __attribute__((always_inline)) v16cacc64 neg(v16cacc64 );
Expand Down
42 changes: 32 additions & 10 deletions clang/lib/Headers/aie2p_scl2vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
// (c) Copyright 2024-2025 Advanced Micro Devices, Inc. or its affiliates
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -1621,16 +1621,26 @@ INTRINSIC(v16accfloat) shiftr_elem(v16accfloat v, float s) {
}
// broadcast value one(1) to all vector lanes
INTRINSIC(v64int8) broadcast_one_s8() { return broadcast_s8(1); }
INTRINSIC(v64int8) broadcast_one_to_v64int8() { return broadcast_one_s8(); }

INTRINSIC(v32int16) broadcast_one_s16() { return broadcast_s16(1); }
INTRINSIC(v32int16) broadcast_one_to_v32int16() { return broadcast_one_s16(); }

INTRINSIC(v16int32) broadcast_one_s32() { return broadcast_s32(1); }
INTRINSIC(v16int32) broadcast_one_to_v16int32() { return broadcast_one_s32(); }

INTRINSIC(v64uint8) broadcast_one_u8() { return broadcast_u8(1); }
INTRINSIC(v64uint8) broadcast_one_to_v64uint8() { return broadcast_one_u8(); }

INTRINSIC(v32uint16) broadcast_one_u16() { return broadcast_u16(1); }
INTRINSIC(v32uint16) broadcast_one_to_v32uint16() {
return broadcast_one_u16();
}

INTRINSIC(v16uint32) broadcast_one_u32() { return broadcast_u32(1); }
INTRINSIC(v16uint32) broadcast_one_to_v16uint32() {
return broadcast_one_u32();
}

INTRINSIC(v32bfloat16) broadcast_one_bfloat16() {
return broadcast_bfloat16(1);
Expand Down Expand Up @@ -1708,15 +1718,6 @@ INTRINSIC(v16uint32) broadcast_zero_to_v16uint32() { return broadcast_u32(0); }
}
INTRINSIC(v16float) broadcast_zero_to_v16float() { return broadcast_float(0); }

INTRINSIC(v16acc64) broadcast_zero_to_v16acc64() {
return __builtin_bit_cast(v16acc64, 0 - v32int32{0});
}

[[deprecated("Function 'clr' is deprecated. Please use the 'broadcast_zero_to' "
"variant instead.")]] INTRINSIC(v16acc64) clr16() {
return broadcast_zero_to_v16acc64();
}

#if 0
[[deprecated("Function 'broadcast_zero_c16' is deprecated. Please use the 'broadcast_zero_to_v16cint16' variant instead.")]] INTRINSIC(v16cint16) broadcast_zero_c16() { return broadcast_c16(0); }
INTRINSIC(v16cint16) broadcast_zero_to_v16cint16() { return broadcast_c16(0); }
Expand Down Expand Up @@ -1794,6 +1795,27 @@ broadcast_elem(v16float v, int idx) {
INTRINSIC(v64int8)
broadcast_to_v64int8(int b) { return broadcast_s8((int)b); }

INTRINSIC(v16acc64) broadcast_zero_to_v16acc64() { return v16acc64{}; }

[[deprecated("Function 'clr' is deprecated. Please use the 'broadcast_zero_to' "
"variant instead.")]] INTRINSIC(v16acc64) clr16() {
return broadcast_zero_to_v16acc64();
}

INTRINSIC(v32acc64) broadcast_zero_to_v32acc64() { return v32acc64{}; }

[[deprecated("Function 'clr' is deprecated. Please use the 'broadcast_zero_to' "
"variant instead.")]] INTRINSIC(v32acc64) clr32() {
return broadcast_zero_to_v32acc64();
}

INTRINSIC(v64acc32) broadcast_zero_to_v64acc32() { return v64acc32{}; }

[[deprecated("Function 'clr' is deprecated. Please use the 'broadcast_zero_to' "
"variant instead.")]] INTRINSIC(v64acc32) clr64() {
return broadcast_zero_to_v64acc32();
}

INTRINSIC(v16accfloat) broadcast_zero_to_v16accfloat() {
return __builtin_bit_cast(v16accfloat, (float)0 - v16float{0});
}
Expand Down
31 changes: 24 additions & 7 deletions clang/test/CodeGen/aie/aie2p/aie2p-scl2vec-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
// (c) Copyright 2024-2025 Advanced Micro Devices, Inc. or its affiliates
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -702,30 +702,47 @@ v64int8
test_broadcast_to_v64int8(int b) {
return broadcast_to_v64int8(b);
}
v16accfloat
// AIE2P-LABEL: define dso_local inreg noundef <16 x i64> @_Z31test_broadcast_zero_to_v16acc64v(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <16 x i64> zeroinitializer
//
v16acc64 test_broadcast_zero_to_v16acc64() {
return broadcast_zero_to_v16acc64();
}
// AIE2P-LABEL: define dso_local inreg noundef <32 x i64> @_Z31test_broadcast_zero_to_v32acc64v(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <32 x i64> zeroinitializer
//
v32acc64 test_broadcast_zero_to_v32acc64() { return broadcast_zero_to_v32acc64(); }
// AIE2P-LABEL: define dso_local inreg noundef <64 x i32> @_Z31test_broadcast_zero_to_v64acc32v(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <64 x i32> zeroinitializer
//
v64acc32 test_broadcast_zero_to_v64acc32() { return broadcast_zero_to_v64acc32(); }
// AIE2P-LABEL: define dso_local inreg noundef <16 x float> @_Z34test_broadcast_zero_to_v16accfloatv(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <16 x float> zeroinitializer
//
test_broadcast_zero_to_v16accfloat() {
v16accfloat test_broadcast_zero_to_v16accfloat() {
return broadcast_zero_to_v16accfloat();
}
v32accfloat
// AIE2P-LABEL: define dso_local inreg noundef <32 x float> @_Z34test_broadcast_zero_to_v32accfloatv(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <32 x float> zeroinitializer
//
test_broadcast_zero_to_v32accfloat() {
v32accfloat test_broadcast_zero_to_v32accfloat() {
return broadcast_zero_to_v32accfloat();
}
v64accfloat
// AIE2P-LABEL: define dso_local inreg noundef <64 x float> @_Z34test_broadcast_zero_to_v64accfloatv(
// AIE2P-SAME: ) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: ret <64 x float> zeroinitializer
//
test_broadcast_zero_to_v64accfloat() {
v64accfloat test_broadcast_zero_to_v64accfloat() {
return broadcast_zero_to_v64accfloat();
}
Loading