Skip to content

Commit

Permalink
[Matrix] Update mangling to use paramterized vendor ext type syntax.
Browse files Browse the repository at this point in the history
The Itanium CXX ABI grammer has been extended to support parameterized
vendor extended types [1].

This patch updates Clang's mangling for matrix types to use the new
extension.

[1] itanium-cxx-abi/cxx-abi@b359d28

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D91253
  • Loading branch information
fhahn committed Nov 11, 2020
1 parent d4a1e03 commit 1d5daed
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 49 deletions.
18 changes: 13 additions & 5 deletions clang/lib/AST/ItaniumMangle.cpp
Expand Up @@ -3493,10 +3493,13 @@ void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
}

void CXXNameMangler::mangleType(const ConstantMatrixType *T) {
// Mangle matrix types using a vendor extended type qualifier:
// U<Len>matrix_type<Rows><Columns><element type>
// Mangle matrix types as a vendor extended type:
// u<Len>matrix_typeI<Rows><Columns><element type>E

StringRef VendorQualifier = "matrix_type";
Out << "U" << VendorQualifier.size() << VendorQualifier;
Out << "u" << VendorQualifier.size() << VendorQualifier;

Out << "I";
auto &ASTCtx = getASTContext();
unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
llvm::APSInt Rows(BitWidth);
Expand All @@ -3506,15 +3509,20 @@ void CXXNameMangler::mangleType(const ConstantMatrixType *T) {
Columns = T->getNumColumns();
mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
mangleType(T->getElementType());
Out << "E";
}

void CXXNameMangler::mangleType(const DependentSizedMatrixType *T) {
// U<Len>matrix_type<row expr><column expr><element type>
// Mangle matrix types as a vendor extended type:
// u<Len>matrix_typeI<row expr><column expr><element type>E
StringRef VendorQualifier = "matrix_type";
Out << "U" << VendorQualifier.size() << VendorQualifier;
Out << "u" << VendorQualifier.size() << VendorQualifier;

Out << "I";
mangleTemplateArg(T->getRowExpr());
mangleTemplateArg(T->getColumnExpr());
mangleType(T->getElementType());
Out << "E";
}

void CXXNameMangler::mangleType(const DependentAddressSpaceType *T) {
Expand Down
18 changes: 9 additions & 9 deletions clang/test/CodeGenCXX/matrix-type-builtins.cpp
Expand Up @@ -67,7 +67,7 @@ void test_transpose_rvalue() {
}

void test_transpose_const(const matrix_t<float, 3, 3> &m) {
// CHECK-LABEL: define void @_Z20test_transpose_constRKU11matrix_typeLm3ELm3Ef(
// CHECK-LABEL: define void @_Z20test_transpose_constRKu11matrix_typeILm3ELm3EfE(
// CHECK: [[MATRIX:%.*]] = load <9 x float>, <9 x float>* {{.*}}, align 4
// CHECK-NEXT: [[M_T:%.*]] = call <9 x float> @llvm.matrix.transpose.v9f32(<9 x float> [[MATRIX]], i32 3, i32 3)
// CHECK-NEXT: [[M_T_ADDR:%.*]] = bitcast [9 x float]* %m_t to <9 x float>*
Expand All @@ -90,9 +90,9 @@ matrix_t<T, R, C> column_major_load_with_stride(T *Ptr) {
void test_column_major_load_with_stride_template_double(double *Ptr) {
// CHECK-LABEL: define void @_Z50test_column_major_load_with_stride_template_doublePd(double* %Ptr)
// CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
// CHECK-NEXT: call <40 x double> @_Z29column_major_load_with_strideIdLj10ELj4ELj15EEU11matrix_typeXT0_EXT1_ET_PS0_(double* [[PTR]])
// CHECK-NEXT: call <40 x double> @_Z29column_major_load_with_strideIdLj10ELj4ELj15EEu11matrix_typeIXT0_EXT1_ET_EPS0_(double* [[PTR]])

// CHECK-LABEL: define linkonce_odr <40 x double> @_Z29column_major_load_with_strideIdLj10ELj4ELj15EEU11matrix_typeXT0_EXT1_ET_PS0_(double* %Ptr)
// CHECK-LABEL: define linkonce_odr <40 x double> @_Z29column_major_load_with_strideIdLj10ELj4ELj15EEu11matrix_typeIXT0_EXT1_ET_EPS0_(double* %Ptr)
// CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
// CHECK-NEXT: call <40 x double> @llvm.matrix.column.major.load.v40f64(double* align 8 [[PTR]], i64 15, i1 false, i32 10, i32 4)

Expand All @@ -102,9 +102,9 @@ void test_column_major_load_with_stride_template_double(double *Ptr) {
void test_column_major_load_with_stride_template_int(int *Ptr) {
// CHECK-LABEL: define void @_Z47test_column_major_load_with_stride_template_intPi(i32* %Ptr) #5 {
// CHECK: [[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
// CHECK-NEXT: call <6 x i32> @_Z29column_major_load_with_strideIiLj3ELj2ELj12EEU11matrix_typeXT0_EXT1_ET_PS0_(i32* [[PTR]])
// CHECK-NEXT: call <6 x i32> @_Z29column_major_load_with_strideIiLj3ELj2ELj12EEu11matrix_typeIXT0_EXT1_ET_EPS0_(i32* [[PTR]])

// CHECK-LABEL: define linkonce_odr <6 x i32> @_Z29column_major_load_with_strideIiLj3ELj2ELj12EEU11matrix_typeXT0_EXT1_ET_PS0_(i32* %Ptr)
// CHECK-LABEL: define linkonce_odr <6 x i32> @_Z29column_major_load_with_strideIiLj3ELj2ELj12EEu11matrix_typeIXT0_EXT1_ET_EPS0_(i32* %Ptr)
// CHECK: [[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
// CHECK-NEXT: call <6 x i32> @llvm.matrix.column.major.load.v6i32(i32* align 4 [[PTR]], i64 12, i1 false, i32 3, i32 2)

Expand Down Expand Up @@ -195,9 +195,9 @@ void column_major_store_with_stride(matrix_t<T, R, C> &m, T *Ptr) {
void test_column_major_store_with_stride_template_double(double *Ptr) {
// CHECK-LABEL: define void @_Z51test_column_major_store_with_stride_template_doublePd(double* %Ptr)
// CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
// CHECK-NEXT: call void @_Z30column_major_store_with_strideIdLj10ELj4ELj15EEvRU11matrix_typeXT0_EXT1_ET_PS0_([40 x double]* nonnull align 8 dereferenceable(320) %M1, double* [[PTR]])
// CHECK-NEXT: call void @_Z30column_major_store_with_strideIdLj10ELj4ELj15EEvRu11matrix_typeIXT0_EXT1_ET_EPS0_([40 x double]* nonnull align 8 dereferenceable(320) %M1, double* [[PTR]])

// CHECK-LABEL: define linkonce_odr void @_Z30column_major_store_with_strideIdLj10ELj4ELj15EEvRU11matrix_typeXT0_EXT1_ET_PS0_([40 x double]* nonnull align 8 dereferenceable(320) %m, double* %Ptr)
// CHECK-LABEL: define linkonce_odr void @_Z30column_major_store_with_strideIdLj10ELj4ELj15EEvRu11matrix_typeIXT0_EXT1_ET_EPS0_([40 x double]* nonnull align 8 dereferenceable(320) %m, double* %Ptr)
// CHECK: [[M:%.*]] = load <40 x double>, <40 x double>* {{.*}}, align 8
// CHECK-NEXT: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
// CHECK-NEXT: call void @llvm.matrix.column.major.store.v40f64(<40 x double> [[M]], double* align 8 [[PTR]], i64 15, i1 false, i32 10, i32 4)
Expand All @@ -209,9 +209,9 @@ void test_column_major_store_with_stride_template_double(double *Ptr) {
void test_column_major_store_with_stride_template_int(int *Ptr) {
// CHECK-LABEL: define void @_Z48test_column_major_store_with_stride_template_intPi(i32* %Ptr)
// CHECK: [[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
// CHECK-NEXT: call void @_Z30column_major_store_with_strideIiLj3ELj2ELj3EEvRU11matrix_typeXT0_EXT1_ET_PS0_([6 x i32]* nonnull align 4 dereferenceable(24) %M1, i32* [[PTR]])
// CHECK-NEXT: call void @_Z30column_major_store_with_strideIiLj3ELj2ELj3EEvRu11matrix_typeIXT0_EXT1_ET_EPS0_([6 x i32]* nonnull align 4 dereferenceable(24) %M1, i32* [[PTR]])

// CHECK-LABEL: define linkonce_odr void @_Z30column_major_store_with_strideIiLj3ELj2ELj3EEvRU11matrix_typeXT0_EXT1_ET_PS0_([6 x i32]* nonnull align 4 dereferenceable(24) %m, i32* %Ptr)
// CHECK-LABEL: define linkonce_odr void @_Z30column_major_store_with_strideIiLj3ELj2ELj3EEvRu11matrix_typeIXT0_EXT1_ET_EPS0_([6 x i32]* nonnull align 4 dereferenceable(24) %m, i32* %Ptr)
// CHECK: [[M:%.*]] = load <6 x i32>, <6 x i32>* {{.*}}, align 4
// CHECK-NEXT: [[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
// CHECK-NEXT: call void @llvm.matrix.column.major.store.v6i32(<6 x i32> [[M]], i32* align 4 [[PTR]], i64 3, i1 false, i32 3, i32 2)
Expand Down
20 changes: 10 additions & 10 deletions clang/test/CodeGenCXX/matrix-type-operators.cpp
Expand Up @@ -276,17 +276,17 @@ template <class R, class C>
auto matrix_subscript(double4x4 m, R r, C c) -> decltype(m[r][c]) {}

double test_matrix_subscript(double4x4 m) {
// CHECK-LABEL: @_Z21test_matrix_subscriptU11matrix_typeLm4ELm4Ed(
// CHECK-LABEL: @_Z21test_matrix_subscriptu11matrix_typeILm4ELm4EdE(
// CHECK: [[MAT:%.*]] = load <16 x double>, <16 x double>* {{.*}}, align 8
// CHECK-NEXT: [[CALL:%.*]] = call nonnull align 8 dereferenceable(8) double* @_Z16matrix_subscriptIiiEDTixixfp_fp0_fp1_EU11matrix_typeLm4ELm4EdT_T0_(<16 x double> [[MAT]], i32 1, i32 2)
// CHECK-NEXT: [[CALL:%.*]] = call nonnull align 8 dereferenceable(8) double* @_Z16matrix_subscriptIiiEDTixixfp_fp0_fp1_Eu11matrix_typeILm4ELm4EdET_T0_(<16 x double> [[MAT]], i32 1, i32 2)
// CHECK-NEXT: [[RES:%.*]] = load double, double* [[CALL]], align 8
// CHECK-NEXT: ret double [[RES]]

return matrix_subscript(m, 1, 2);
}

const double &test_matrix_subscript_reference(const double4x4 m) {
// CHECK-LABEL: @_Z31test_matrix_subscript_referenceU11matrix_typeLm4ELm4Ed(
// CHECK-LABEL: @_Z31test_matrix_subscript_referenceu11matrix_typeILm4ELm4EdE(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[M_ADDR:%.*]] = alloca [16 x double], align 8
// CHECK-NEXT: [[REF_TMP:%.*]] = alloca double, align 8
Expand All @@ -308,7 +308,7 @@ struct UnsignedWrapper {
};

double extract_IntWrapper_idx(double4x4 &m, IntWrapper i, UnsignedWrapper j) {
// CHECK-LABEL: define double @_Z22extract_IntWrapper_idxRU11matrix_typeLm4ELm4Ed10IntWrapper15UnsignedWrapper(
// CHECK-LABEL: define double @_Z22extract_IntWrapper_idxRu11matrix_typeILm4ELm4EdE10IntWrapper15UnsignedWrapper(
// CHECK: [[I:%.*]] = call i32 @_ZN10IntWrappercviEv(%struct.IntWrapper* %i)
// CHECK-NEXT: [[I_ADD:%.*]] = add nsw i32 [[I]], 1
// CHECK-NEXT: [[I_ADD_EXT:%.*]] = sext i32 [[I_ADD]] to i64
Expand Down Expand Up @@ -340,16 +340,16 @@ struct identmatrix_t {
constexpr identmatrix_t identmatrix;

void test_constexpr1(matrix_type<float, 4, 4> &m) {
// CHECK-LABEL: define void @_Z15test_constexpr1RU11matrix_typeLm4ELm4Ef(
// CHECK-LABEL: define void @_Z15test_constexpr1Ru11matrix_typeILm4ELm4EfE(
// CHECK: [[MAT:%.*]] = load <16 x float>, <16 x float>* {{.*}}, align 4
// CHECK-NEXT: [[IM:%.*]] = call <16 x float> @_ZNK13identmatrix_tcvU11matrix_typeXT0_EXT0_ET_IfLj4EEEv(%struct.identmatrix_t* @_ZL11identmatrix)
// CHECK-NEXT: [[IM:%.*]] = call <16 x float> @_ZNK13identmatrix_tcvu11matrix_typeIXT0_EXT0_ET_EIfLj4EEEv(%struct.identmatrix_t* @_ZL11identmatrix)
// CHECK-NEXT: [[ADD:%.*]] = fadd <16 x float> [[MAT]], [[IM]]
// CHECK-NEXT: [[MAT_ADDR:%.*]] = load [16 x float]*, [16 x float]** %m.addr, align 8
// CHECK-NEXT: [[MAT_ADDR2:%.*]] = bitcast [16 x float]* [[MAT_ADDR]] to <16 x float>*
// CHECK-NEXT: store <16 x float> [[ADD]], <16 x float>* [[MAT_ADDR2]], align 4
// CHECK-NEXT: ret voi

// CHECK-LABEL: define linkonce_odr <16 x float> @_ZNK13identmatrix_tcvU11matrix_typeXT0_EXT0_ET_IfLj4EEEv(
// CHECK-LABEL: define linkonce_odr <16 x float> @_ZNK13identmatrix_tcvu11matrix_typeIXT0_EXT0_ET_EIfLj4EEEv(
// CHECK-LABEL: for.body: ; preds = %for.cond
// CHECK-NEXT: [[I:%.*]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[I_EXT:%.*]] = zext i32 [[I]] to i64
Expand All @@ -366,8 +366,8 @@ void test_constexpr1(matrix_type<float, 4, 4> &m) {
}

void test_constexpr2(matrix_type<int, 5, 5> &m) {
// CHECK-LABEL: define void @_Z15test_constexpr2RU11matrix_typeLm5ELm5Ei(
// CHECK: [[IM:%.*]] = call <25 x i32> @_ZNK13identmatrix_tcvU11matrix_typeXT0_EXT0_ET_IiLj5EEEv(%struct.identmatrix_t* @_ZL11identmatrix)
// CHECK-LABEL: define void @_Z15test_constexpr2Ru11matrix_typeILm5ELm5EiE(
// CHECK: [[IM:%.*]] = call <25 x i32> @_ZNK13identmatrix_tcvu11matrix_typeIXT0_EXT0_ET_EIiLj5EEEv(%struct.identmatrix_t* @_ZL11identmatrix)
// CHECK: [[MAT:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
// CHECK-NEXT: [[SUB:%.*]] = sub <25 x i32> [[IM]], [[MAT]]
// CHECK-NEXT: [[SUB2:%.*]] = add <25 x i32> [[SUB]], <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>
Expand All @@ -377,7 +377,7 @@ void test_constexpr2(matrix_type<int, 5, 5> &m) {
// CHECK-NEXT: ret void
//

// CHECK-LABEL: define linkonce_odr <25 x i32> @_ZNK13identmatrix_tcvU11matrix_typeXT0_EXT0_ET_IiLj5EEEv(
// CHECK-LABEL: define linkonce_odr <25 x i32> @_ZNK13identmatrix_tcvu11matrix_typeIXT0_EXT0_ET_EIiLj5EEEv(
// CHECK-LABEL: for.body: ; preds = %for.cond
// CHECK-NEXT: [[I:%.*]] = load i32, i32* %i, align 4
// CHECK-NEXT: [[I_EXT:%.*]] = zext i32 [[I]] to i64
Expand Down

0 comments on commit 1d5daed

Please sign in to comment.