Skip to content

Commit fa5b05a

Browse files
author
Greg Roth
committed
revert cpp test changes and revise matrix printing
To make this perfectly limited to HLSL, revert matrix cpp test Revise matrix printing so that should they have pointers or references in HLSL, they will be printed properly as well
1 parent de15228 commit fa5b05a

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -855,48 +855,48 @@ void TypePrinter::printConstantMatrixBefore(const ConstantMatrixType *T,
855855
if (Policy.UseHLSLTypes)
856856
OS << "matrix<";
857857
printBefore(T->getElementType(), OS);
858-
if (!Policy.UseHLSLTypes) {
858+
if (!Policy.UseHLSLTypes)
859859
OS << " __attribute__((matrix_type(";
860-
OS << T->getNumRows() << ", " << T->getNumColumns();
860+
else
861+
OS << ", ";
862+
OS << T->getNumRows() << ", " << T->getNumColumns();
863+
if (!Policy.UseHLSLTypes)
861864
OS << ")))";
862-
}
865+
else
866+
OS << ">";
863867
}
864868

865869
void TypePrinter::printConstantMatrixAfter(const ConstantMatrixType *T,
866870
raw_ostream &OS) {
867871
printAfter(T->getElementType(), OS);
868-
if (Policy.UseHLSLTypes) {
869-
OS << ", ";
870-
OS << T->getNumRows() << ", " << T->getNumColumns();
871-
OS << ">";
872-
}
873872
}
874873

875874
void TypePrinter::printDependentSizedMatrixBefore(
876875
const DependentSizedMatrixType *T, raw_ostream &OS) {
877876
if (Policy.UseHLSLTypes)
878877
OS << "matrix<";
879878
printBefore(T->getElementType(), OS);
880-
}
881-
882-
void TypePrinter::printDependentSizedMatrixAfter(
883-
const DependentSizedMatrixType *T, raw_ostream &OS) {
884-
printAfter(T->getElementType(), OS);
885-
if (Policy.UseHLSLTypes)
886-
OS << ", ";
887-
else
879+
if (!Policy.UseHLSLTypes)
888880
OS << " __attribute__((matrix_type(";
881+
else
882+
OS << ", ";
889883

890884
if (Expr *E = T->getRowExpr())
891885
E->printPretty(OS, nullptr, Policy);
892886
OS << ", ";
893887
if (Expr *E = T->getColumnExpr())
894888
E->printPretty(OS, nullptr, Policy);
895889

896-
if (Policy.UseHLSLTypes)
897-
OS << ">";
898-
else
890+
OS << ", ";
891+
if (!Policy.UseHLSLTypes)
899892
OS << ")))";
893+
else
894+
OS << ">";
895+
}
896+
897+
void TypePrinter::printDependentSizedMatrixAfter(
898+
const DependentSizedMatrixType *T, raw_ostream &OS) {
899+
printAfter(T->getElementType(), OS);
900900
}
901901

902902
void

clang/test/CodeGenCXX/matrix-type-operators.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -O0 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck --check-prefixes=CHECK,NOOPT %s
22
// RUN: %clang_cc1 -O1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck --check-prefixes=CHECK,OPT %s
3+
typedef double dx5x5_t __attribute__((matrix_type(5, 5)));
4+
using fx2x3_t = float __attribute__((matrix_type(2, 3)));
35

46
template <typename EltTy, unsigned Rows, unsigned Columns>
57
struct MyMatrix {
@@ -138,7 +140,7 @@ void test_IntWrapper_Add(MyMatrix<double, 10, 9> &m) {
138140
// NOOPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8{{$}}
139141
// OPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8, !tbaa !{{[0-9]+}}{{$}}
140142
// CHECK-NEXT: [[SCALAR:%.*]] = call noundef i32 @_ZN10IntWrappercviEv(ptr {{[^,]*}} %w3)
141-
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 [[SCALAR]] to double
143+
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 %call to double
142144
// CHECK-NEXT: [[SCALAR_EMBED:%.*]] = insertelement <90 x double> poison, double [[SCALAR_FP]], i64 0
143145
// CHECK-NEXT: [[SCALAR_EMBED1:%.*]] = shufflevector <90 x double> [[SCALAR_EMBED]], <90 x double> poison, <90 x i32> zeroinitializer
144146
// CHECK-NEXT: [[RES:%.*]] = fadd <90 x double> [[MATRIX]], [[SCALAR_EMBED1]]
@@ -152,7 +154,7 @@ void test_IntWrapper_Add(MyMatrix<double, 10, 9> &m) {
152154
void test_IntWrapper_Sub(MyMatrix<double, 10, 9> &m) {
153155
// CHECK-LABEL: define{{.*}} void @_Z19test_IntWrapper_SubR8MyMatrixIdLj10ELj9EE(
154156
// CHECK: [[SCALAR:%.*]] = call noundef i32 @_ZN10IntWrappercviEv(ptr {{[^,]*}} %w3)
155-
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 [[SCALAR]] to double
157+
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 %call to double
156158
// NOOPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8{{$}}
157159
// OPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8, !tbaa !{{[0-9]+}}{{$}}
158160
// CHECK-NEXT: [[SCALAR_EMBED:%.*]] = insertelement <90 x double> poison, double [[SCALAR_FP]], i64 0
@@ -195,7 +197,7 @@ MyMatrix<float, 2, 2> test_multiply_template(MyMatrix<float, 2, 5> Mat1,
195197
void test_IntWrapper_Multiply(MyMatrix<double, 10, 9> &m, IntWrapper &w3) {
196198
// CHECK-LABEL: define{{.*}} void @_Z24test_IntWrapper_MultiplyR8MyMatrixIdLj10ELj9EER10IntWrapper(
197199
// CHECK: [[SCALAR:%.*]] = call noundef i32 @_ZN10IntWrappercviEv(ptr noundef {{.*}})
198-
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 [[SCALAR]] to double
200+
// CHECK-NEXT: [[SCALAR_FP:%.*]] = sitofp i32 %call to double
199201
// NOOPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8{{$}}
200202
// OPT: [[MATRIX:%.*]] = load <90 x double>, ptr {{.*}}, align 8, !tbaa !{{[0-9]+}}{{$}}
201203
// CHECK-NEXT: [[SCALAR_EMBED:%.*]] = insertelement <90 x double> poison, double [[SCALAR_FP]], i64 0

0 commit comments

Comments
 (0)