[PATCH] D72772: [Matrix] Add __builtin_matrix_extract to Clang (WIP).

2020-03-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn abandoned this revision.
fhahn added a comment.

superseded by D76791  using operators.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72772/new/

https://reviews.llvm.org/D72772



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72772: [Matrix] Add __builtin_matrix_extract to Clang (WIP).

2020-01-15 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72772/new/

https://reviews.llvm.org/D72772



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72772: [Matrix] Add __builtin_matrix_extract to Clang (WIP).

2020-01-15 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
Herald added a subscriber: tschuett.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72772

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-matrix.c
  clang/test/CodeGenCXX/builtin-matrix.cpp
  clang/test/Sema/builtin-matrix.c
  clang/test/SemaCXX/builtin-matrix.cpp

Index: clang/test/SemaCXX/builtin-matrix.cpp
===
--- clang/test/SemaCXX/builtin-matrix.cpp
+++ clang/test/SemaCXX/builtin-matrix.cpp
@@ -7,6 +7,13 @@
   char *s;
 };
 
+template 
+struct MyMatrix {
+  using matrix_t = EltTy __attribute__((matrix_type(Rows, Columns)));
+
+  matrix_t value;
+};
+
 void insert(sx10x10_t *a, float f) {
   *a = __builtin_matrix_insert(
   10, // expected-error {{First argument must be a matrix}}
@@ -23,3 +30,15 @@
   *a = __builtin_matrix_insert(*a, f, // expected-error {{Row argument must be an unsigned integer}}
5u, 10.0); // expected-error {{Column argument must be an unsigned integer}}
 }
+
+template 
+EltTy extract(MyMatrix ) {
+  char *v1 = __builtin_matrix_extract(Mat.value, 1u, 0u); // expected-error {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int'}}
+  return __builtin_matrix_extract(Mat.value, 1u, 0u);
+}
+
+void test_extract_template(unsigned *Ptr1, float *Ptr2) {
+  MyMatrix Mat1;
+  Mat1.value = *((decltype(Mat1)::matrix_t*) Ptr1);
+  unsigned v1 = extract(Mat1); // expected-note {{in instantiation of function template specialization 'extract' requested here}}
+}
Index: clang/test/Sema/builtin-matrix.c
===
--- /dev/null
+++ clang/test/Sema/builtin-matrix.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fenable-matrix -pedantic -verify -triple=x86_64-apple-darwin9
+
+typedef float sx10x10_t __attribute__((matrix_type(10, 10)));
+sx10x10_t a;
+
+struct Foo {
+  char *s;
+};
+
+void insert(sx10x10_t *a, float f) {
+  *a = __builtin_matrix_insert(
+  10, // expected-error {{First argument must be a matrix}}
+  a,  // expected-error {{Row argument must be an unsigned integer}}
+  a,  // expected-error {{Column argument must be an unsigned integer}}
+  10);
+
+  int x = __builtin_matrix_insert(*a, 3u, 5u, 10.0); // expected-error {{initializing 'int' with an expression of incompatible type 'sx10x10_t' (aka 'float __attribute__((matrix_type(10, 10))) ')}}
+
+  // TODO: Should error here (index out of range).
+  *a = __builtin_matrix_insert(*a, -1u, 5u, 10.0);
+
+  // FIXME: Column argument is fine!
+  *a = __builtin_matrix_insert(*a, f, // expected-error {{Row argument must be an unsigned integer}}
+   5u, 10.0); // expected-error {{Column argument must be an unsigned integer}}
+}
+
+
+void extract(sx10x10_t *a) {
+  struct Foo v1  = __builtin_matrix_extract( // expected-error {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+  *a, 1, 1);
+
+   float v2 = __builtin_matrix_extract(
+  10,  // expected-error {{First argument must be a matrix}}
+  a,   // expected-error {{Row argument must be an unsigned integer}}
+  a);  // expected-error {{Column argument must be an unsigned integer}}
+
+   float v3 = __builtin_matrix_extract(
+  *a, 1); // expected-error {{too few arguments to function call, expected 3, have 2}}
+
+   float v4 = __builtin_matrix_extract(
+  *a, 1, 1, 1); // expected-error {{too many arguments to function call, expected 3, have 4}}
+}
Index: clang/test/CodeGenCXX/builtin-matrix.cpp
===
--- clang/test/CodeGenCXX/builtin-matrix.cpp
+++ clang/test/CodeGenCXX/builtin-matrix.cpp
@@ -70,9 +70,9 @@
   Mat.value = __builtin_matrix_insert(Mat.value, 1u, 0u, e);
 }
 
-void test_template(unsigned *Ptr1, unsigned E1, float *Ptr2, float E2) {
+void test_insert_template(unsigned *Ptr1, unsigned E1, float *Ptr2, float E2) {
 
-  // CHECK-LABEL: define void @_Z13test_templatePjjPff(i32* %Ptr1, i32 %E1, float* %Ptr2, float %E2)
+  // CHECK-LABEL: define void @_Z20test_insert_templatePjjPff(i32* %Ptr1, i32 %E1, float* %Ptr2, float %E2)
   // CHECK-NEXT:  entry:
   // CHECK-NEXT:%Ptr1.addr = alloca i32*, align 8
   // CHECK-NEXT:%E1.addr = alloca i32, align 4
@@ -148,3 +148,78 @@
   Mat2.value = *((decltype(Mat2)::matrix_t *)Ptr2);
   insert(Mat2, E2);
 }
+
+
+typedef float fx3x3_t __attribute__((matrix_type(3, 3)));
+void extract1(dx5x5_t a, fx3x3_t b, ix9x3_t c) {
+  // CHECK-LABEL: @_Z8extract1Dm5_5_dDm3_3_fDm9_3_i(
+  // CHECK-NEXT:  entry:
+  // CHECK-NEXT:%a.addr = alloca [25 x double], align 8
+  // CHECK-NEXT:%b.addr = alloca [9 x float], align 4
+  // CHECK-NEXT:%c.addr = alloca [27 x i32], align 4
+  // CHECK-NEXT:%v1 =