[PATCH] D72283: [Matrix] Add __builtin_matrix_insert 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/D72283/new/

https://reviews.llvm.org/D72283



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


[PATCH] D72283: [Matrix] Add __builtin_matrix_insert to Clang (WIP).

2020-01-06 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/D72283/new/

https://reviews.llvm.org/D72283



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


[PATCH] D72283: [Matrix] Add __builtin_matrix_insert to Clang (WIP).

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

This patch adds a __builtin_matrix_insert builtin as described in
"Matrix Support in Clang" on cfe-dev [1]. The patch is not intended for
review yet, just to provide an idea how the implementation could look
like.

[1] http://lists.llvm.org/pipermail/cfe-dev/2019-December/064141.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72283

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  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/SemaCXX/builtin-matrix.cpp

Index: clang/test/SemaCXX/builtin-matrix.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-matrix.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -fenable-matrix -pedantic -std=c++11 -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 {{cannot initialize a variable of type 'int' with an rvalue of 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}}
+}
Index: clang/test/CodeGenCXX/builtin-matrix.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/builtin-matrix.cpp
@@ -0,0 +1,150 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s
+
+typedef double dx5x5_t __attribute__((matrix_type(5, 5)));
+using fx2x3_t = float __attribute__((matrix_type(2, 3)));
+
+void insert_fp(dx5x5_t *a, double d, fx2x3_t *b, float e) {
+  *a = __builtin_matrix_insert(*a, 0u, 1u, d);
+  *b = __builtin_matrix_insert(*b, 1u, 0u, e);
+
+  // CHECK-LABEL: @_Z9insert_fpPDm5_5_ddPDm2_3_ff(
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT:%a.addr = alloca [25 x double]*, align 8
+  // CHECK-NEXT:%d.addr = alloca double, align 8
+  // CHECK-NEXT:%b.addr = alloca [6 x float]*, align 8
+  // CHECK-NEXT:%e.addr = alloca float, align 4
+  // CHECK-NEXT:store [25 x double]* %a, [25 x double]** %a.addr, align 8
+  // CHECK-NEXT:store double %d, double* %d.addr, align 8
+  // CHECK-NEXT:store [6 x float]* %b, [6 x float]** %b.addr, align 8
+  // CHECK-NEXT:store float %e, float* %e.addr, align 4
+  // CHECK-NEXT:%0 = load [25 x double]*, [25 x double]** %a.addr, align 8
+  // CHECK-NEXT:%1 = bitcast [25 x double]* %0 to <25 x double>*
+  // CHECK-NEXT:%2 = load <25 x double>, <25 x double>* %1, align 8
+  // CHECK-NEXT:%3 = load double, double* %d.addr, align 8
+  // CHECK-NEXT:%4 = insertelement <25 x double> %2, double %3, i32 5
+  // CHECK-NEXT:%5 = load [25 x double]*, [25 x double]** %a.addr, align 8
+  // CHECK-NEXT:%6 = bitcast [25 x double]* %5 to <25 x double>*
+  // CHECK-NEXT:store <25 x double> %4, <25 x double>* %6, align 8
+  // CHECK-NEXT:%7 = load [6 x float]*, [6 x float]** %b.addr, align 8
+  // CHECK-NEXT:%8 = bitcast [6 x float]* %7 to <6 x float>*
+  // CHECK-NEXT:%9 = load <6 x float>, <6 x float>* %8, align 4
+  // CHECK-NEXT:%10 = load float, float* %e.addr, align 4
+  // CHECK-NEXT:%11 = insertelement <6 x float> %9, float %10, i32 1
+  // CHECK-NEXT:%12 = load [6 x float]*, [6 x float]** %b.addr, align 8
+  // CHECK-NEXT:%13 = bitcast [6 x float]* %12 to <6 x float>*
+  // CHECK-NEXT:store <6 x float> %11, <6 x float>* %13, align 4
+  // CHECK-NEXT:   ret void
+}
+
+typedef int ix9x3_t __attribute__((matrix_type(9, 3)));
+
+void insert_int(ix9x3_t *a, int i) {
+  *a = __builtin_matrix_insert(*a, 4u, 1u, i);
+
+  // CHECK-LABEL: @_Z10insert_intPDm9_3_ii(
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT:%a.addr = alloca [27 x i32]*, align 8
+  // CHECK-NEXT:%i.addr = alloca i32, align 4
+  // CHECK-NEXT:store [27 x i32]* %a, [27 x i32]** %a.addr, align 8
+  // CHECK-NEXT:store i32 %i, i32* %i.addr, align 4
+  // CHECK-NEXT:%0 = load [27 x i32]*, [27 x i32]** %a.addr, align 8
+  // CHECK-NEXT:%1 = bitcast [27 x i32]* %0 to