diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1007,6 +1007,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ CanQualType SingletonId; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + CanQualType Id##Ty; +#include "clang/Basic/PPCTypes.def" // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -2487,6 +2487,9 @@ // SVE Types #define SVE_TYPE(Name, Id, SingletonId) Id, #include "clang/Basic/AArch64SVEACLETypes.def" +// PPC MMA Types +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) Id, +#include "clang/Basic/PPCTypes.def" // All other builtin types #define BUILTIN_TYPE(Id, SingletonId) Id, #define LAST_BUILTIN_TYPE(Id) LastKind = Id diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -761,6 +761,10 @@ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(NAME, ID, SIZE) \ + case BuiltinType::ID: return ctx.ID##Ty; +#include "clang/Basic/PPCTypes.def" + #define BUILTIN_TYPE(ID, SINGLETON_ID) \ case BuiltinType::ID: return ctx.SINGLETON_ID; #include "clang/AST/BuiltinTypes.def" diff --git a/clang/include/clang/Basic/PPCTypes.def b/clang/include/clang/Basic/PPCTypes.def new file mode 100644 --- /dev/null +++ b/clang/include/clang/Basic/PPCTypes.def @@ -0,0 +1,20 @@ +//===-- PPCTypes.def - Metadata about PPC types -----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines PPC types. +// Custom code should define this macro: +// +// PPC_MMA_VECTOR_TYPE(Name, Id, Size) - A MMA vector type of a given size +// (in bits). +// +//===----------------------------------------------------------------------===// + +PPC_MMA_VECTOR_TYPE(__vector_quad, VectorQuad, 512) +PPC_MMA_VECTOR_TYPE(__vector_pair, VectorPair, 256) + +#undef PPC_MMA_VECTOR_TYPE diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1080,6 +1080,9 @@ // \brief SVE types with auto numeration #define SVE_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID, #include "clang/Basic/AArch64SVEACLETypes.def" + // \brief PowerPC MMA types with auto numeration +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) PREDEF_TYPE_##Id##_ID, +#include "clang/Basic/PPCTypes.def" }; /// The number of predefined type IDs that are reserved for diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1423,6 +1423,12 @@ #include "clang/Basic/AArch64SVEACLETypes.def" } + if (Target.getTriple().isPPC64() && Target.hasFeature("mma")) { +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + InitBuiltinType(Id##Ty, BuiltinType::Id); +#include "clang/Basic/PPCTypes.def" + } + // Builtin type for __objc_yes and __objc_no ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? SignedCharTy : BoolTy); @@ -2148,6 +2154,12 @@ Align = 16; \ break; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + Width = Size; \ + Align = Size; \ + break; +#include "clang/Basic/PPCTypes.def" } break; case Type::ObjCObjectPointer: @@ -7207,6 +7219,9 @@ case BuiltinType::OCLReserveID: case BuiltinType::OCLSampler: case BuiltinType::Dependent: +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" #define BUILTIN_TYPE(KIND, ID) #define PLACEHOLDER_TYPE(KIND, ID) \ case BuiltinType::KIND: diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1035,6 +1035,10 @@ case BuiltinType::Id: \ return Importer.getToContext().SingletonId; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + return Importer.getToContext().Id##Ty; +#include "clang/Basic/PPCTypes.def" #define SHARED_SINGLETON_TYPE(Expansion) #define BUILTIN_TYPE(Id, SingletonId) \ case BuiltinType::Id: return Importer.getToContext().SingletonId; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -10882,6 +10882,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" return GCCTypeClass::None; case BuiltinType::Dependent: diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2828,6 +2828,12 @@ << type_name; \ break; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + type_name = #Name; \ + Out << 'u' << type_name.size() << type_name; \ + break; +#include "clang/Basic/PPCTypes.def" } } diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -2118,6 +2118,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::ShortAccum: case BuiltinType::Accum: case BuiltinType::LongAccum: diff --git a/clang/lib/AST/NSAPI.cpp b/clang/lib/AST/NSAPI.cpp --- a/clang/lib/AST/NSAPI.cpp +++ b/clang/lib/AST/NSAPI.cpp @@ -474,6 +474,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::BoundMember: case BuiltinType::Dependent: case BuiltinType::Overload: diff --git a/clang/lib/AST/PrintfFormatString.cpp b/clang/lib/AST/PrintfFormatString.cpp --- a/clang/lib/AST/PrintfFormatString.cpp +++ b/clang/lib/AST/PrintfFormatString.cpp @@ -791,6 +791,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" #define SIGNED_TYPE(Id, SingletonId) #define UNSIGNED_TYPE(Id, SingletonId) #define FLOATING_TYPE(Id, SingletonId) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3084,6 +3084,10 @@ case Id: \ return Name; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case Id: \ + return #Name; +#include "clang/Basic/PPCTypes.def" } llvm_unreachable("Invalid builtin type."); @@ -4101,6 +4105,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::BuiltinFn: case BuiltinType::NullPtr: case BuiltinType::IncompleteMatrixIdx: diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp --- a/clang/lib/AST/TypeLoc.cpp +++ b/clang/lib/AST/TypeLoc.cpp @@ -403,6 +403,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::BuiltinFn: case BuiltinType::IncompleteMatrixIdx: case BuiltinType::OMPArraySection: diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -752,6 +752,13 @@ return DBuilder.createVectorType(/*Size*/ 0, Align, ElemTy, SubscriptArray); } + // It doesn't make sense to generate debug info for PowerPC MMA vector types. + // So we return a safe type here to avoid generating an error. +#define PPC_MMA_VECTOR_TYPE(Name, Id, size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" + return CreateType(cast(CGM.getContext().IntTy)); + case BuiltinType::UChar: case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -589,6 +589,12 @@ Info.EC.getKnownMinValue() * Info.NumVectors); } +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + ResultType = \ + llvm::FixedVectorType::get(ConvertType(Context.BoolTy), Size); \ + break; +#include "clang/Basic/PPCTypes.def" case BuiltinType::Dependent: #define BUILTIN_TYPE(Id, SingletonId) #define PLACEHOLDER_TYPE(Id, SingletonId) \ diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3093,6 +3093,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::ShortAccum: case BuiltinType::Accum: case BuiltinType::LongAccum: diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -729,6 +729,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" case BuiltinType::ShortAccum: case BuiltinType::Accum: case BuiltinType::LongAccum: diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -369,6 +369,13 @@ #include "clang/Basic/AArch64SVEACLETypes.def" } + if (Context.getTargetInfo().getTriple().isPPC64() && + Context.getTargetInfo().hasFeature("mma")) { +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + addImplicitTypedef(#Name, Context.Id##Ty); +#include "clang/Basic/PPCTypes.def" + } + if (Context.getTargetInfo().hasBuiltinMSVaList()) { DeclarationName MSVaList = &Context.Idents.get("__builtin_ms_va_list"); if (IdResolver.begin(MSVaList) == IdResolver.end()) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5982,6 +5982,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" #define PLACEHOLDER_TYPE(ID, SINGLETON_ID) #define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID: #include "clang/AST/BuiltinTypes.def" @@ -19198,6 +19201,9 @@ #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" #define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id: #define PLACEHOLDER_TYPE(Id, SingletonId) #include "clang/AST/BuiltinTypes.def" diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp --- a/clang/lib/Serialization/ASTCommon.cpp +++ b/clang/lib/Serialization/ASTCommon.cpp @@ -237,6 +237,11 @@ ID = PREDEF_TYPE_##Id##_ID; \ break; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + ID = PREDEF_TYPE_##Id##_ID; \ + break; +#include "clang/Basic/PPCTypes.def" case BuiltinType::BuiltinFn: ID = PREDEF_TYPE_BUILTIN_FN; break; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -7039,6 +7039,11 @@ T = Context.SingletonId; \ break; #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) \ + case PREDEF_TYPE_##Id##_ID: \ + T = Context.Id##Ty; \ + break; +#include "clang/Basic/PPCTypes.def" } assert(!T.isNull() && "Unknown predefined type"); diff --git a/clang/test/AST/ast-dump-ppc-mma-types.c b/clang/test/AST/ast-dump-ppc-mma-types.c new file mode 100644 --- /dev/null +++ b/clang/test/AST/ast-dump-ppc-mma-types.c @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -target-cpu future \ +// RUN: -ast-dump -ast-dump-filter __vector %s | FileCheck %s +// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -target-cpu future \ +// RUN: -target-feature -mma -ast-dump %s | FileCheck %s \ +// RUN: --check-prefix=CHECK-NO-MMA +// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -target-cpu pwr9 \ +// RUN: -ast-dump %s | FileCheck %s --check-prefix=CHECK-PWR9 +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck %s \ +// RUN: --check-prefix=CHECK-X86_64 +// RUN: %clang_cc1 -triple arm-unknown-unknown -ast-dump %s | FileCheck %s \ +// RUN: --check-prefix=CHECK-ARM +// RUN: %clang_cc1 -triple riscv64-unknown-unknown -ast-dump %s | FileCheck %s \ +// RUN: --check-prefix=CHECK-RISCV64 + +// This test case checks that the PowerPC __vector_pair and __vector_quad types +// are correctly defined. These types should only be defined on PowerPC targets +// supporting the mma feature. We also added checks on a couple of other targets +// to ensure the types are target-dependent. + +// CHECK: TypedefDecl {{.*}} implicit __vector_quad '__vector_quad' +// CHECK-NEXT: -BuiltinType {{.*}} '__vector_quad' +// CHECK: TypedefDecl {{.*}} implicit __vector_pair '__vector_pair' +// CHECK-NEXT: -BuiltinType {{.*}} '__vector_pair' + +// CHECK-NO-MMA-NOT: __vector_quad +// CHECK-NO-MMA-NOT: __vector_pair + +// CHECK-PWR9-NOT: __vector_quad +// CHECK-PWR9-NOT: __vector_pair + +// CHECK-X86_64-NOT: __vector_quad +// CHECK-X86_64-NOT: __vector_pair + +// CHECK-ARM-NOT: __vector_quad +// CHECK-ARM-NOT: __vector_pair + +// CHECK-RISCV64-NOT: __vector_quad +// CHECK-RISCV64-NOT: __vector_pair diff --git a/clang/test/CodeGen/ppc-mma-types.c b/clang/test/CodeGen/ppc-mma-types.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/ppc-mma-types.c @@ -0,0 +1,27 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple powerpc64le-linux-unknown -target-cpu future \ +// RUN: -emit-llvm -O3 -o - %s | FileCheck %s + +// CHECK-LABEL: @test1( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds <512 x i1>, <512 x i1>* [[PTR1:%.*]], i64 2 +// CHECK-NEXT: [[TMP0:%.*]] = load <512 x i1>, <512 x i1>* [[ADD_PTR]], align 64, [[TBAA2:!tbaa !.*]] +// CHECK-NEXT: [[ADD_PTR1:%.*]] = getelementptr inbounds <512 x i1>, <512 x i1>* [[PTR2:%.*]], i64 1 +// CHECK-NEXT: store <512 x i1> [[TMP0]], <512 x i1>* [[ADD_PTR1]], align 64, [[TBAA2]] +// CHECK-NEXT: ret void +// +void test1(__vector_quad *ptr1, __vector_quad *ptr2) { + *(ptr2 + 1) = *(ptr1 + 2); +} + +// CHECK-LABEL: @test2( +// CHECK-NEXT: entry: +// CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds <256 x i1>, <256 x i1>* [[PTR1:%.*]], i64 2 +// CHECK-NEXT: [[TMP0:%.*]] = load <256 x i1>, <256 x i1>* [[ADD_PTR]], align 32, [[TBAA6:!tbaa !.*]] +// CHECK-NEXT: [[ADD_PTR1:%.*]] = getelementptr inbounds <256 x i1>, <256 x i1>* [[PTR2:%.*]], i64 1 +// CHECK-NEXT: store <256 x i1> [[TMP0]], <256 x i1>* [[ADD_PTR1]], align 32, [[TBAA6]] +// CHECK-NEXT: ret void +// +void test2(__vector_pair *ptr1, __vector_pair *ptr2) { + *(ptr2 + 1) = *(ptr1 + 2); +} diff --git a/clang/test/CodeGenCXX/ppc-mangle-mma-types.cpp b/clang/test/CodeGenCXX/ppc-mangle-mma-types.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/ppc-mangle-mma-types.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple powerpc64le-linux-unknown -target-cpu future %s \ +// RUN: -emit-llvm -o - | FileCheck %s + +// CHECK: _Z2f1Pu13__vector_quad +void f1(__vector_quad *vq) {} + +// CHECK: _Z2f2Pu13__vector_pair +void f2(__vector_pair *vp) {} + +// CHECK: _Z2f3Pu13__vector_quad +void f3(__vector_quad *vq) {} + +// CHECK: _Z2f3Pu13__vector_pair +void f3(__vector_pair *vp) {} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1546,6 +1546,8 @@ case BuiltinType::OCLReserveID: #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" +#define PPC_MMA_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id: +#include "clang/Basic/PPCTypes.def" #define BUILTIN_TYPE(Id, SingletonId) #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: