[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2022-09-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha abandoned this revision.
SaurabhJha added a subscriber: Florian.
SaurabhJha added a comment.

> @SaurabhJha did you ever get a chance to create a patch?

Hey @Florian, sorry I dropped the ball here. I don't think I would be able to 
spend time on this so abandoning this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D106005#2904424 , @fhahn wrote:

> In D106005#2896080 , @SaurabhJha 
> wrote:
>
>> In D106005#2895716 , @fhahn wrote:
>>
>>> Thank you very much for working on this! Are you planning on implementing 
>>> the new specification as well? It would probably be good to land the update 
>>> to the spec in close succession to the implementation, to avoid confusing 
>>> users.
>>
>> Yes, that's my plan. Once this is in, I will start working on the 
>> implementation right away.
>
> Ok cool! I think the latest version looks good (modulo making sure the new 
> lines are limited to 80 chars per line). @rjmccall can you think of any 
> scenarios where defining initializers with one expression and broadcasting 
> them might cause issues?
>
> With respect to ordering the patches, I think it would be good to put up a 
> patch implementing the newly added parts, commit it and then land the patch 
> that adds it to the docs. WDYT?

Yeah, sounds good. I will create a patch for implementing initialisation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-07-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

@fhahn addressed your broadcast comment. Would you prefer that I create the 
initialisation implementation patch before we get this in?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 360886.
SaurabhJha added a comment.

Add documentation for matrix broadcast initialization


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

Files:
  clang/docs/MatrixTypes.rst


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,25 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialized with an initializer list:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {x};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+If the initializer list is empty, all elements of the matrix are 
zero-initialized.
+
+If the initializer list has just one expression, all elements of the matrix 
will be initialized using that expression.
+
+Otherwise, the initializer list must consist of M::rows initializer lists, 
each of which must consist of
+M::columns expressions, each of which is used to initialize the corresponding 
element of the matrix. For example,
+m[i][j] is initialized by the jth expression of the ith initializer list in 
the initializer. Element designators are
+not allowed.
+
 TODOs
 -
 
@@ -274,9 +293,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,25 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialized with an initializer list:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {x};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+If the initializer list is empty, all elements of the matrix are zero-initialized.
+
+If the initializer list has just one expression, all elements of the matrix will be initialized using that expression.
+
+Otherwise, the initializer list must consist of M::rows initializer lists, each of which must consist of
+M::columns expressions, each of which is used to initialize the corresponding element of the matrix. For example,
+m[i][j] is initialized by the jth expression of the ith initializer list in the initializer. Element designators are
+not allowed.
+
 TODOs
 -
 
@@ -274,9 +293,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D106005#2895716 , @fhahn wrote:

> Thank you very much for working on this! Are you planning on implementing the 
> new specification as well? It would probably be good to land the update to 
> the spec in close succession to the implementation, to avoid confusing users.

Yes, that's my plan. Once this is in, I will start working on the 
implementation right away.




Comment at: clang/docs/MatrixTypes.rst:279
+The number of constituent arrays must equal the number rows in the matrix type 
M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+

fhahn wrote:
> SaurabhJha wrote:
> > rjmccall wrote:
> > > This is contradicted by your first example.  I think you want to say 
> > > something like
> > > 
> > > > A value of matrix type `M` can be initialized with an initializer list:
> > > >
> > > > (examples)
> > > >
> > > > If the initializer list is empty, all elements of the matrix are 
> > > > zero-initialized.  Otherwise, the initializer list must consist of 
> > > > `M::rows` initializer lists, each of which must consist of `M::columns` 
> > > > expressions, each of which is used to initialize the corresponding 
> > > > element of the matrix (that is, `m[i][j]` is initialized by the `j`th 
> > > > expression of the `i`th initializer list in the initializer).  Element 
> > > > designators are not allowed.
> > > 
> > > That's assuming you want to allow `{}`, but I think that's probably a 
> > > good idea.  At the very least, you already have to define how objects of 
> > > static storage duration are zero-initialized, and having a way to do that 
> > > explicitly always seems wise to me.
> > That sounds great @rjmccall, thanks for your suggestions.
> > 
> > I think I got confused between whether to allow `{}` but as you suggested, 
> > I think we should.
> That looks good, thanks! 
> 
> Another thing to consider is whether we would like to provide a convenient 
> syntax to initialise all elements with an user-specified value, i.e. should 
> we allow something like `m = {99};`, which would broadcast 99 to all elements 
> of the matrix?
That sounds good. Do we have a way to infer the number of rows and columns for 
a matrix object `m` so that we could broadcast correctly? I will amend the docs 
later today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 360716.
SaurabhJha added a comment.

Address second round of comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

Files:
  clang/docs/MatrixTypes.rst


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,20 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialized with an initializer list:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+If the initializer list is empty, all elements of the matrix are 
zero-initialized. Otherwise, the initializer list
+must consist of M::rows initializer lists, each of which must consist of 
M::columns expressions, each of which is used
+to initialize the corresponding element of the matrix. For example, m[i][j] is 
initialized by the jth expression of the
+ith initializer list in the initializer. Element designators are not allowed.
+
 TODOs
 -
 
@@ -274,9 +288,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,20 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialized with an initializer list:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+If the initializer list is empty, all elements of the matrix are zero-initialized. Otherwise, the initializer list
+must consist of M::rows initializer lists, each of which must consist of M::columns expressions, each of which is used
+to initialize the corresponding element of the matrix. For example, m[i][j] is initialized by the jth expression of the
+ith initializer list in the initializer. Element designators are not allowed.
+
 TODOs
 -
 
@@ -274,9 +288,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/docs/MatrixTypes.rst:279
+The number of constituent arrays must equal the number rows in the matrix type 
M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+

rjmccall wrote:
> This is contradicted by your first example.  I think you want to say 
> something like
> 
> > A value of matrix type `M` can be initialized with an initializer list:
> >
> > (examples)
> >
> > If the initializer list is empty, all elements of the matrix are 
> > zero-initialized.  Otherwise, the initializer list must consist of 
> > `M::rows` initializer lists, each of which must consist of `M::columns` 
> > expressions, each of which is used to initialize the corresponding element 
> > of the matrix (that is, `m[i][j]` is initialized by the `j`th expression of 
> > the `i`th initializer list in the initializer).  Element designators are 
> > not allowed.
> 
> That's assuming you want to allow `{}`, but I think that's probably a good 
> idea.  At the very least, you already have to define how objects of static 
> storage duration are zero-initialized, and having a way to do that explicitly 
> always seems wise to me.
That sounds great @rjmccall, thanks for your suggestions.

I think I got confused between whether to allow `{}` but as you suggested, I 
think we should.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-21 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 360524.
SaurabhJha added a comment.

Updated docs to address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

Files:
  clang/docs/MatrixTypes.rst


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,18 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialised using aggregate initialization 
syntax:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+The number of constituent arrays must equal the number rows in the matrix type 
M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +286,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,18 @@
   }
 
 
+Initialization Syntax
+-
+A value of a matrix type M can be initialised using aggregate initialization syntax:
+
+.. code-block:: c++
+
+  constexpr M m1 = {};
+  constexpr M m2 = {{a, b, c}, {d, e, f}};
+
+The number of constituent arrays must equal the number rows in the matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +286,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-20 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/docs/MatrixTypes.rst:271
+-
+An empty value of a matrix type M can be initialised using this syntax:
+

SaurabhJha wrote:
> fhahn wrote:
> > is there a reason we need to allow 'empty' initialisation? What does it 
> > mean? 
> By empty, I meant this `{}` initialisation which was in the test case. I got 
> the term wrong but seems like we do want to support `{}` initialisation, 
> right?
I meant this test case 
https://github.com/llvm/llvm-project/blob/3323a628ec821b8b75d3b60bf1510931f97d3883/clang/test/CodeGenCXX/matrix-type-builtins.cpp#L78


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-20 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/docs/MatrixTypes.rst:271
+-
+An empty value of a matrix type M can be initialised using this syntax:
+

fhahn wrote:
> is there a reason we need to allow 'empty' initialisation? What does it mean? 
By empty, I meant this `{}` initialisation which was in the test case. I got 
the term wrong but seems like we do want to support `{}` initialisation, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-19 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106005

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


[PATCH] D106005: [Docs] Define matrix initialisation in MatrixTypes documentation

2021-07-14 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As part of https://bugs.llvm.org/show_bug.cgi?id=46251, this patch adds 
definition of matrix initialisation. I am not very familiar with this part of 
C++
so please let me know if I am wrong here, which I suspect I am.

I have been trying to follow the reference documentation 
https://en.cppreference.com/w/cpp/language/initialization and the commented out 
test in the
bugzilla ticket 
https://github.com/llvm/llvm-project/blob/3323a628ec821b8b75d3b60bf1510931f97d3883/clang/test/CodeGenCXX/matrix-type-builtins.cpp#L78


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106005

Files:
  clang/docs/MatrixTypes.rst


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,22 @@
   }
 
 
+Initialization Syntax
+-
+An empty value of a matrix type M can be initialised using this syntax:
+
+.. code-block:: c++
+
+  constexpr M m = {};
+
+A non-empty value of a matrix type M can be initialised using the nested 
initialisation syntax:
+
+.. code-block: c++
+  constexpr M m = {{a, b, c}, {d, e, f}}
+
+where the number of constituent arrays must equal the number rows in the 
matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +290,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 


Index: clang/docs/MatrixTypes.rst
===
--- clang/docs/MatrixTypes.rst
+++ clang/docs/MatrixTypes.rst
@@ -266,6 +266,22 @@
   }
 
 
+Initialization Syntax
+-
+An empty value of a matrix type M can be initialised using this syntax:
+
+.. code-block:: c++
+
+  constexpr M m = {};
+
+A non-empty value of a matrix type M can be initialised using the nested initialisation syntax:
+
+.. code-block: c++
+  constexpr M m = {{a, b, c}, {d, e, f}}
+
+where the number of constituent arrays must equal the number rows in the matrix type M and the number of elements
+in each constituent array must equal the number of columns in the matrix type.
+
 TODOs
 -
 
@@ -274,9 +290,6 @@
 convenient. The alternative is using template deduction to extract this
 information. Also add spelling for C.
 
-Future Work: Initialization syntax.
-
-
 Decisions for the Implementation in Clang
 =
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104971: [Matrix] Minor fixes with language extension docs

2021-06-26 Thread Saurabh Jha via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc8f3f46c6983: [Docs] Minor fixes with language extension 
docs (authored by SaurabhJha).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104971

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -536,6 +536,7 @@
 The matrix type extension supports division on a matrix and a scalar but not 
on a matrix and a matrix.
 
 .. code-block:: c++
+
   typedef float m4x4_t __attribute__((matrix_type(4, 4)));
 
   m4x4_t f(m4x4_t a) {
@@ -543,8 +544,8 @@
 return a;
   }
 
-The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
-and between a matrix and a scalar, provided their types are consistent.
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication on matrices
+and on a matrix and a scalar, provided their types are consistent.
 
 .. code-block:: c++
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -536,6 +536,7 @@
 The matrix type extension supports division on a matrix and a scalar but not on a matrix and a matrix.
 
 .. code-block:: c++
+
   typedef float m4x4_t __attribute__((matrix_type(4, 4)));
 
   m4x4_t f(m4x4_t a) {
@@ -543,8 +544,8 @@
 return a;
   }
 
-The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
-and between a matrix and a scalar, provided their types are consistent.
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication on matrices
+and on a matrix and a scalar, provided their types are consistent.
 
 .. code-block:: c++
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104971: [Matrix] Minor fixes with language extension docs

2021-06-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D104971#2842319 , @xgupta wrote:

> btw you should use [Docs] or [NFC] tag for this patch.

Okay, will follow the linked docs and amend the commit message with [Docs].


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104971

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


[PATCH] D104971: [Matrix] Minor fixes with language extension docs

2021-06-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

This is a light patch that probably does not require a review and I created a 
patch anyway.

Would it be appropriate to get this into main using `arc land` if this is 
approved? I saw this https://reviews.llvm.org/D78867 which advises against `arc 
land` but could not find anything related to that in the main docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104971

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


[PATCH] D104971: [Matrix] Minor fixes with language extension docs

2021-06-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There were some issues in the patch https://reviews.llvm.org/D104198. I also 
forgot to address one comment. This patch addresses these


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104971

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -536,6 +536,7 @@
 The matrix type extension supports division on a matrix and a scalar but not 
on a matrix and a matrix.
 
 .. code-block:: c++
+
   typedef float m4x4_t __attribute__((matrix_type(4, 4)));
 
   m4x4_t f(m4x4_t a) {
@@ -543,8 +544,8 @@
 return a;
   }
 
-The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
-and between a matrix and a scalar, provided their types are consistent.
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication on matrices
+and on a matrix and a scalar, provided their types are consistent.
 
 .. code-block:: c++
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -536,6 +536,7 @@
 The matrix type extension supports division on a matrix and a scalar but not on a matrix and a matrix.
 
 .. code-block:: c++
+
   typedef float m4x4_t __attribute__((matrix_type(4, 4)));
 
   m4x4_t f(m4x4_t a) {
@@ -543,8 +544,8 @@
 return a;
   }
 
-The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
-and between a matrix and a scalar, provided their types are consistent.
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication on matrices
+and on a matrix and a scalar, provided their types are consistent.
 
 .. code-block:: c++
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:538
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));

xgupta wrote:
> oh just an blank line is needed :)
Thanks, fixing this now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha closed this revision.
SaurabhJha added a comment.

This is closed by this commit 
https://github.com/llvm/llvm-project/commit/cd256c8bcc9723f0ce7a32957f26600c966fa07c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D104198#2838665 , @fhahn wrote:

> In D104198#2838658 , @SaurabhJha 
> wrote:
>
>> Sorry, I committed this without the `Differential Revision: 
>> https://reviews.llvm.org/D104198` line. Is there a way to change the commit 
>> message after it is in main? I could not push after `git commit --amend`
>
> There's no way to adjust an already pushed commit (force pushes are blocked). 
> You could either revert the change and re-commit with the updated wording or 
> you could manually close the revision here. If the rest of the commit message 
> is OK, I'd recommend just closing the revision manually and provide a link to 
> the commit.

Okay thanks, I will do the latter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Sorry, I committed this without the `Differential Revision: 
https://reviews.llvm.org/D104198` line. Is there a way to change the commit 
message after it is in main? I could not push after `git commit --amend`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Thanks, the build is also passing now so I will land this in a bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 354232.
SaurabhJha added a comment.

Rebase with latest main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,63 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations on a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+return (a + 23) * 12;
+  }
+
+The matrix type extension supports division on a matrix and a scalar but not 
on a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. Implicit type conversion 
between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,63 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations on a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+return (a + 23) * 12;
+  }
+
+The matrix type extension supports division on a matrix and a scalar but not on a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 354231.
SaurabhJha added a comment.

Address round 2 comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,63 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations on a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+return (a + 23) * 12;
+  }
+
+The matrix type extension supports division on a matrix and a scalar but not 
on a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. Implicit type conversion 
between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,63 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations on a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+return (a + 23) * 12;
+  }
+
+The matrix type extension supports division on a matrix and a scalar but not on a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Somehow the builds are failing even though this patch contains no code changes.




Comment at: clang/docs/LanguageExtensions.rst:526
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+

fhahn wrote:
> I'm not a native speaker, but I am not sure if `between` is the best choice 
> here. To me, `on` would sound slightly better, but again, I'm no expert.
I think you are right. Will change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

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


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-23 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 353971.
SaurabhJha added a comment.

Removing mistakenly added files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-23 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 353970.
SaurabhJha added a comment.
Herald added a project: clang-tools-extra.

Did a --amend to rebuild


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
Index: clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
===
--- clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -80,7 +80,7 @@
 
   auto  = Tool.getFiles();
   SourceManager Sources(Diagnostics, FileMgr);
-  Rewriter Rewrite(Sources, DefaultLangOptions);
+  Rewriter Rewrite(Sources, DefaultLangOptions); // TODO: Ally Donaldson
   Tool.applyAllReplacements(Rewrite);
 
   for (const auto  : Files) {


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
Index: clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
===
--- clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -80,7 +80,7 @@
 
   auto  = Tool.getFiles();
   SourceManager Sources(Diagnostics, FileMgr);
-  Rewriter Rewrite(Sources, DefaultLangOptions);
+  Rewriter Rewrite(Sources, 

[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-17 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 352783.
SaurabhJha added a comment.

Address comment: replace scalar variables by values


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+a = a / 3.0;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+a += 23;
+a -= 12;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+return (fx5x5) i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-15 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 352192.
SaurabhJha added a comment.

Document matrix scalar division


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,71 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but 
not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+float s = 3;
+a = a / s;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,71 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+float s = 3;
+a = a / s;
+return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-15 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 352191.
SaurabhJha added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,60 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a 
scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,60 @@
 return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+  int c = 23;
+  int d = 12;
+  a = a + c;
+  return a * d;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+int c = 23;
+int d = 12;
+a += b;
+a -= b;
+a *= b;
+a += c;
+a -= d;
+return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+return f;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-13 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 351728.
SaurabhJha added a comment.

Forgot to add a colon in code-block header. Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,41 @@
 return a + b * c;
   }
 
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication, provided
+their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  void f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  void f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,41 @@
 return a + b * c;
   }
 
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication, provided
+their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  void f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  void f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

2021-06-13 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds examples of compound assignment and type conversions for matrix 
types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,41 @@
 return a + b * c;
   }
 
+The matrix type extension supports compound assignments for addition, 
subtraction, and multiplication, provided
+their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  void f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are 
C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  void f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,41 @@
 return a + b * c;
   }
 
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication, provided
+their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  void f(m4x4_t a, m4x4_t b) {
+a += b;
+a -= b;
+a *= b;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  void f1(ix5x5 i, fx5x5 f) {
+f = (fx5x5)i;
+  }
+
+
+  template 
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+matrix_5_5 d;
+matrix_5_5 i;
+i = (matrix_5_5)d;
+i = static_cast>(d);
+  }
 
 Half-Precision Floating Point
 =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-06-05 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D101696#2798713 , @SjoerdMeijer 
wrote:

> Perhaps for bonus points, update the Clang documentation in 
> https://clang.llvm.org/docs/LanguageExtensions.html#matrix-types with some 
> examples?

Can you please point me to how to submit patches to the documentation? I could 
only find links like https://clang.llvm.org/hacking.html which talk about code 
patches. Many thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D103163: [Matrix] Skip matrix casts checks for class or struct types in C++.

2021-05-27 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha accepted this revision.
SaurabhJha added a comment.

In D103163#2785578 , @fhahn wrote:

> I discussed the problem offline with John and he suggested to handle matrix 
> casts in TryStaticCast. This allows us the handle both static_cast and 
> C-style casts with the same code. As a consequence, the default error 
> messages for casting a matrix type to a non-matrix type and vice versa are 
> used.

Makes sense Florian. I am sorry I missed it in my static cast patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103163

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


[PATCH] D103163: [Matrix] Skip matrix casts checks for class or struct types in C++.

2021-05-26 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Thanks, this looks good to me! The existing tests are failing but seems like 
they are not difficult to fix. Once those are fixed, I will mark this as 
accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103163

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


[PATCH] D102125: [Matrix] Implement static cast for matrix types

2021-05-16 Thread Saurabh Jha via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGecb235d94014: [Matrix] Implement static cast for matrix 
types (authored by SaurabhJha).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102125

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -46,6 +46,37 @@
 }
 
 void f2() {
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = static_cast>(m1);
+  m3 = static_cast>(m2);
+  static_cast>(m3); // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
+
+  static_cast(m3);// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  static_cast>(i); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+
+  static_cast(m2); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  static_cast>(v); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+
+  static_cast(m1);// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  static_cast>(s); // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
+}
+
+void f3() {
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_5_5 m3;
@@ -65,3 +96,24 @@
   m6 = (matrix_5_5)m4;
   m4 = (matrix_5_5)m6;
 }
+
+void f4() {
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
+  float f;
+
+  m2 = static_cast>(m1);
+  static_cast>(m1); // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'double __\
+attribute__((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'float __attribute__((matrix_type(4, 4)))') of different\
+ size is not allowed}}
+  m4 = static_cast>(m3);
+  m5 = static_cast>(m4); // expected-error {{assigning to 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') from incompatible type 'matrix_5_5' (aka 'unsigned int __attribute__\
+((matrix_type(5, 5)))')}}
+  m6 = static_cast>(m4);
+  m4 = static_cast>(m6);
+}
Index: clang/test/CodeGenCXX/matrix-casts.cpp
===
--- clang/test/CodeGenCXX/matrix-casts.cpp
+++ clang/test/CodeGenCXX/matrix-casts.cpp
@@ -6,8 +6,8 @@
 template 
 using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
 
-// CHECK-LABEL: define{{.*}} void @_Z19CastCharMatrixToIntv
-void CastCharMatrixToInt() {
+// CHECK-LABEL: define{{.*}} void @_Z25CastCharMatrixToIntCStylev()
+void CastCharMatrixToIntCStyle() {
   // CHECK: [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
   // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
   // CHECK-NEXT: [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
@@ -18,8 +18,20 @@
   i = (matrix_5_5)c;
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z27CastCharMatrixToUnsignedIntv
-void CastCharMatrixToUnsignedInt() {
+// CHECK-LABEL: define{{.*}} void @_Z29CastCharMatrixToIntStaticCastv()
+void CastCharMatrixToIntStaticCast() {
+  // CHECK: [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT: [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
+  // CHECK-NEXT: store <25 x i32> [[CONV]], <25 x i32>* [[CONV1]], align 4
+
+  matrix_5_5 c;
+  matrix_5_5 i;
+  i = static_cast>(c);
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z33CastCharMatrixToUnsignedIntCStylev
+void CastCharMatrixToUnsignedIntCStyle() {
   // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
   // CHECK-NEXT:  [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
   // CHECK-NEXT:  [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
@@ -31,8 +43,21 @@
   u = (matrix_5_5)c;
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z32CastUnsignedLongIntMatrixToShortv
-void CastUnsignedLongIntMatrixToShort() {
+// CHECK-LABEL: define{{.*}} void 

[PATCH] D102125: [Matrix] Implement static cast for matrix types

2021-05-14 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

I am planning to commit this on Sunday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102125

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


[PATCH] D102125: [Matrix] Implement static cast for matrix types

2021-05-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D102125#2746764 , @fhahn wrote:

> LGTM from the mechanical aspect. Please wait a few days with committing, in 
> case there are any conceptual issues with supporting matrix casts here.

Sure, sounds good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102125

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


[PATCH] D102125: [Matrix] Implement static cast for matrix types

2021-05-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

I have commit access so I can get this into main branch after its approved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102125

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


[PATCH] D102125: [Matrix] Implement static cast for matrix types

2021-05-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch implements static casts for matrix types. This patch finishes all 
the work needed for https://bugs.llvm.org/show_bug.cgi?id=47141


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102125

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -46,6 +46,37 @@
 }
 
 void f2() {
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = static_cast>(m1);
+  m3 = static_cast>(m2);
+  static_cast>(m3); // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
+
+  static_cast(m3);// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  static_cast>(i); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+
+  static_cast(m2); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  static_cast>(v); // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+
+  static_cast(m1);// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  static_cast>(s); // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
+}
+
+void f3() {
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_5_5 m3;
@@ -65,3 +96,24 @@
   m6 = (matrix_5_5)m4;
   m4 = (matrix_5_5)m6;
 }
+
+void f4() {
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
+  float f;
+
+  m2 = static_cast>(m1);
+  static_cast>(m1); // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'double __\
+attribute__((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'float __attribute__((matrix_type(4, 4)))') of different\
+ size is not allowed}}
+  m4 = static_cast>(m3);
+  m5 = static_cast>(m4); // expected-error {{assigning to 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') from incompatible type 'matrix_5_5' (aka 'unsigned int __attribute__\
+((matrix_type(5, 5)))')}}
+  m6 = static_cast>(m4);
+  m4 = static_cast>(m6);
+}
Index: clang/test/CodeGenCXX/matrix-casts.cpp
===
--- clang/test/CodeGenCXX/matrix-casts.cpp
+++ clang/test/CodeGenCXX/matrix-casts.cpp
@@ -6,8 +6,8 @@
 template 
 using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
 
-// CHECK-LABEL: define{{.*}} void @_Z19CastCharMatrixToIntv
-void CastCharMatrixToInt() {
+// CHECK-LABEL: define{{.*}} void @_Z25CastCharMatrixToIntCStylev()
+void CastCharMatrixToIntCStyle() {
   // CHECK: [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
   // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
   // CHECK-NEXT: [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
@@ -18,8 +18,20 @@
   i = (matrix_5_5)c;
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z27CastCharMatrixToUnsignedIntv
-void CastCharMatrixToUnsignedInt() {
+// CHECK-LABEL: define{{.*}} void @_Z29CastCharMatrixToIntStaticCastv()
+void CastCharMatrixToIntStaticCast() {
+  // CHECK: [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT: [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
+  // CHECK-NEXT: store <25 x i32> [[CONV]], <25 x i32>* [[CONV1]], align 4
+
+  matrix_5_5 c;
+  matrix_5_5 i;
+  i = static_cast>(c);
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z33CastCharMatrixToUnsignedIntCStylev
+void CastCharMatrixToUnsignedIntCStyle() {
   // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
   // CHECK-NEXT:  [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
   // CHECK-NEXT:  [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*
@@ -31,8 +43,21 @@
   u = (matrix_5_5)c;
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z32CastUnsignedLongIntMatrixToShortv
-void 

[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D101696#2734312 , @fhahn wrote:

> LGTM, thanks!
>
> I can land this on your behalf tomorrow.
>
> After that I think you could apply for commit access 
> https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access :)

That sounds great, will do!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 342413.
SaurabhJha added a comment.

Rebase with main and add new tests for uitofp, unsigned int to int, and int to 
unsigned int


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -14,7 +14,6 @@
 typedef int vec __attribute__((vector_size(4)));
 
 void f1() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_4_4 m3;
@@ -23,45 +22,46 @@
   vec v;
   test_struct *s;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+  m2 = (matrix_4_4)m1;
+  m2 = m1; // expected-error {{assigning to 'matrix_4_4' from incompatible type 'matrix_4_4'}}
+  m3 = (matrix_4_4)m2;
+  (matrix_5_5)m3; // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
 
-  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'int'}}
-  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
-matrix_type(4, 4)))') is not allowed}}
+  (int)m3;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  (matrix_4_4)i; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
 
-  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
-to 'vec' (vector of 1 'int' value) is not allowed}}
-  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
-(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (vec) m2;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
 
-  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
-((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
-  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
-((matrix_type(5, 5)))') is not allowed}}'
+  (test_struct *)m1;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  (matrix_5_5)s; // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
 }
 
 void f2() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
-  matrix_5_5 m2;
-  matrix_5_5 m3;
-  matrix_4_4 m4;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
   float f;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
-((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
-  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
-is not allowed}}
-  (matrix_4_4)m4;  // expected-error {{C-style cast from 

[PATCH] D101754: [Matrix] Remove bitcast when casting between matrices of the same size

2021-05-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D101754#2733273 , @fhahn wrote:

> LGTM, thanks!
>
> I can commit this change on your behalf in a bit

Cheers Florian!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101754

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D101696#2732983 , @fhahn wrote:

> Thanks for the update! Technically the fix in 
> `clang/lib/CodeGen/CGExprScalar.cpp` is unrelated to C++ support. It would be 
> great if you could put up a separate patch, so we can land this independently.
>
> The whole patch basically LGTM. It would be great if you could add a test 
> casting from unsigned to float/double (looks like no test generates `uitofp`) 
> and a test for casting between signed & unsigned integers of the same size 
> (unless there are already tests for that I missed)

Sure thing. I have created a new patch here https://reviews.llvm.org/D101754. 
Once that's merged, I will rebase this one with the new main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101754: [Matrix] Remove bitcast when casting between matrices of the same size

2021-05-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In matrix type casts, we were doing bitcast when the matrices had the same 
size. This was incorrect and this patch fixes that.
Also added some new CodeGen tests for signed <-> usigned conversions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101754

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/matrix-cast.c


Index: clang/test/CodeGen/matrix-cast.c
===
--- clang/test/CodeGen/matrix-cast.c
+++ clang/test/CodeGen/matrix-cast.c
@@ -52,13 +52,23 @@
 void cast_int_matrix_to_float(ix5x5 i, fx5x5 f) {
   // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_float(<25 x i32> %i, 
<25 x float> %f)
   // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
-  // CHECK-NEXT:  [[CONV:%.*]] = bitcast <25 x i32> [[I]] to <25 x float>
+  // CHECK-NEXT:  [[CONV:%.*]] = sitofp <25 x i32> [[I]] to <25 x float>
   // CHECK-NEXT:  store <25 x float> [[CONV]], <25 x float>* {{.*}}, align 4
   // CHECK-NEXT:  ret void
 
   f = (fx5x5)i;
 }
 
+void cast_unsigned_int_matrix_to_float(unsigned_short_int_5x5 u, fx5x5 f) {
+  // CHECK-LABEL: define{{.*}} void @cast_unsigned_int_matrix_to_float(<25 x 
i16> %u, <25 x float> %f)
+  // CHECK:   [[U:%.*]] = load <25 x i16>, <25 x i16>* {{.*}}, align 2
+  // CHECK-NEXT:  [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>
+  // CHECK-NEXT:  store <25 x float> [[CONV]], <25 x float>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  f = (fx5x5)u;
+}
+
 void cast_double_matrix_to_int(dx5x5 d, ix5x5 i) {
   // CHECK-LABEL: define{{.*}} void @cast_double_matrix_to_int(<25 x double> 
%d, <25 x i32> %i)
   // CHECK:   [[D:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 
8
@@ -108,3 +118,23 @@
 
   s = (unsigned_short_int_5x5)l;
 }
+
+void cast_unsigned_short_int_to_int(unsigned_short_int_5x5 u, ix5x5 i) {
+  // CHECK-LABEL: define{{.*}} void @cast_unsigned_short_int_to_int(<25 x i16> 
%u, <25 x i32> %i)
+  // CHECK:   [[U:%.*]] = load <25 x i16>, <25 x i16>* %0, align 2
+  // CHECK-NEXT:  [[CONV:%.*]] = zext <25 x i16> [[U]] to <25 x i32>
+  // CHECK-NEXT:  store <25 x i32> [[CONV]], <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  i = (ix5x5)u;
+}
+
+void cast_int_to_unsigned_long_int(ix5x5 i, unsigned_long_int_5x5 u) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_to_unsigned_long_int(<25 x i32> 
%i, <25 x i64> %u)
+  // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* %0, align 4
+  // CHECK-NEXT:  [[CONV:%.*]] = sext <25 x i32> [[I]] to <25 x i64>
+  // CHECK-NEXT:  store <25 x i64> [[CONV]], <25 x i64>* {{.*}}, align 8
+  // CHECK-NEXT:  ret void
+
+  u = (unsigned_long_int_5x5)i;
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -1205,10 +1205,6 @@
   QualType SrcElementType;
   QualType DstElementType;
   if (SrcType->isMatrixType() && DstType->isMatrixType()) {
-// Allow bitcast between matrixes of the same size.
-if (SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits())
-  return Builder.CreateBitCast(Src, DstTy, "conv");
-
 SrcElementTy = cast(SrcTy)->getElementType();
 DstElementTy = cast(DstTy)->getElementType();
 SrcElementType = SrcType->castAs()->getElementType();


Index: clang/test/CodeGen/matrix-cast.c
===
--- clang/test/CodeGen/matrix-cast.c
+++ clang/test/CodeGen/matrix-cast.c
@@ -52,13 +52,23 @@
 void cast_int_matrix_to_float(ix5x5 i, fx5x5 f) {
   // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_float(<25 x i32> %i, <25 x float> %f)
   // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
-  // CHECK-NEXT:  [[CONV:%.*]] = bitcast <25 x i32> [[I]] to <25 x float>
+  // CHECK-NEXT:  [[CONV:%.*]] = sitofp <25 x i32> [[I]] to <25 x float>
   // CHECK-NEXT:  store <25 x float> [[CONV]], <25 x float>* {{.*}}, align 4
   // CHECK-NEXT:  ret void
 
   f = (fx5x5)i;
 }
 
+void cast_unsigned_int_matrix_to_float(unsigned_short_int_5x5 u, fx5x5 f) {
+  // CHECK-LABEL: define{{.*}} void @cast_unsigned_int_matrix_to_float(<25 x i16> %u, <25 x float> %f)
+  // CHECK:   [[U:%.*]] = load <25 x i16>, <25 x i16>* {{.*}}, align 2
+  // CHECK-NEXT:  [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>
+  // CHECK-NEXT:  store <25 x float> [[CONV]], <25 x float>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  f = (fx5x5)u;
+}
+
 void cast_double_matrix_to_int(dx5x5 d, ix5x5 i) {
   // CHECK-LABEL: define{{.*}} void @cast_double_matrix_to_int(<25 x double> %d, <25 x i32> %i)
   // CHECK:   [[D:%.*]] = load <25 x double>, <25 x double>* {{.*}}, align 8
@@ -108,3 +118,23 @@
 

[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

All comments addressed now :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 342266.
SaurabhJha added a comment.

Revert change of sext -> zext


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -14,7 +14,6 @@
 typedef int vec __attribute__((vector_size(4)));
 
 void f1() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_4_4 m3;
@@ -23,45 +22,46 @@
   vec v;
   test_struct *s;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+  m2 = (matrix_4_4)m1;
+  m2 = m1; // expected-error {{assigning to 'matrix_4_4' from incompatible type 'matrix_4_4'}}
+  m3 = (matrix_4_4)m2;
+  (matrix_5_5)m3; // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
 
-  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'int'}}
-  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
-matrix_type(4, 4)))') is not allowed}}
+  (int)m3;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  (matrix_4_4)i; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
 
-  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
-to 'vec' (vector of 1 'int' value) is not allowed}}
-  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
-(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (vec) m2;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
 
-  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
-((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
-  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
-((matrix_type(5, 5)))') is not allowed}}'
+  (test_struct *)m1;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  (matrix_5_5)s; // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
 }
 
 void f2() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
-  matrix_5_5 m2;
-  matrix_5_5 m3;
-  matrix_4_4 m4;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
   float f;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
-((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
-  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
-is not allowed}}
-  (matrix_4_4)m4;  // expected-error {{C-style cast from 

[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/test/CodeGenCXX/matrix-casts.cpp:26
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT:  [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*

fhahn wrote:
> SaurabhJha wrote:
> > fhahn wrote:
> > > Shouldn't this use `zext` for the conversion? Possibly that's an issue 
> > > with the existing conversion code for matrixes?
> > Would definitely debug it but would like to quickly clarify this.
> > 
> > [[ 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprScalar.cpp#L1225-L1236
> >  | This ]] is the code that's being executed. For int->int conversion, we 
> > are just checking the whether input is signed and regardless of whether 
> > output type is signed, we do `CreateIntCast`. We probably need to check 
> > `OutputSigned` too, right?
> Nevermind, the scalar version I checked used `zext` due to some AArch64 
> specific optimization! So `sext` should be fine here. But that still leaves 
> the int->float case. https://clang.godbolt.org/z/a5Tjed7sP
Whoops, did not see your updated comment. Reverting that change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 342262.
SaurabhJha added a comment.

Remove unnecessary newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -14,7 +14,6 @@
 typedef int vec __attribute__((vector_size(4)));
 
 void f1() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_4_4 m3;
@@ -23,45 +22,46 @@
   vec v;
   test_struct *s;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+  m2 = (matrix_4_4)m1;
+  m2 = m1; // expected-error {{assigning to 'matrix_4_4' from incompatible type 'matrix_4_4'}}
+  m3 = (matrix_4_4)m2;
+  (matrix_5_5)m3; // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
 
-  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'int'}}
-  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
-matrix_type(4, 4)))') is not allowed}}
+  (int)m3;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  (matrix_4_4)i; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
 
-  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
-to 'vec' (vector of 1 'int' value) is not allowed}}
-  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
-(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (vec) m2;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
 
-  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
-((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
-  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
-((matrix_type(5, 5)))') is not allowed}}'
+  (test_struct *)m1;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  (matrix_5_5)s; // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
 }
 
 void f2() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
-  matrix_5_5 m2;
-  matrix_5_5 m3;
-  matrix_4_4 m4;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
   float f;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
-((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
-  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
-is not allowed}}
-  (matrix_4_4)m4;  // expected-error {{C-style cast from 

[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Thanks for your review @fhahn . I have made some changes in CGExprScalar.cpp to 
address your comments on IR. I have also added a statement to test assignment 
to incorrect type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 342261.
SaurabhJha added a comment.

Updating D101696 : [Matrix] Implement C-style 
explicit type conversions in CXX for matrix types

1. Remove bitcast when types are of the same size.
2. Make int conversion depend on whether both input and output are signed.
3. Add a test case of assigning to an incorrect type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -14,7 +14,6 @@
 typedef int vec __attribute__((vector_size(4)));
 
 void f1() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_4_4 m3;
@@ -23,45 +22,46 @@
   vec v;
   test_struct *s;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+  m2 = (matrix_4_4)m1;
+  m2 = m1; // expected-error {{assigning to 'matrix_4_4' from incompatible type 'matrix_4_4'}}
+  m3 = (matrix_4_4)m2;
+  (matrix_5_5)m3; // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
 
-  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'int'}}
-  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
-matrix_type(4, 4)))') is not allowed}}
+  (int)m3;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  (matrix_4_4)i; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
 
-  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
-to 'vec' (vector of 1 'int' value) is not allowed}}
-  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
-(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (vec) m2;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
 
-  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
-((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
-  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
-((matrix_type(5, 5)))') is not allowed}}'
+  (test_struct *)m1;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  (matrix_5_5)s; // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
 }
 
 void f2() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
-  matrix_5_5 m2;
-  matrix_5_5 m3;
-  matrix_4_4 m4;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
   float f;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
-((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not 

[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/test/CodeGenCXX/matrix-casts.cpp:26
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT:  [[CONV1:%.*]] = bitcast [25 x i32]* {{.*}} to <25 x i32>*

fhahn wrote:
> Shouldn't this use `zext` for the conversion? Possibly that's an issue with 
> the existing conversion code for matrixes?
Would definitely debug it but would like to quickly clarify this.

[[ 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprScalar.cpp#L1225-L1236
 | This ]] is the code that's being executed. For int->int conversion, we are 
just checking the whether input is signed and regardless of whether output type 
is signed, we do `CreateIntCast`. We probably need to check `OutputSigned` too, 
right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101696

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


[PATCH] D101696: [Matrix] Implement C-style explicit type conversions in CXX for matrix types

2021-05-01 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch implements C-style explicit type conversions in CXX for matrix 
types. It is part of fixing https://bugs.llvm.org/show_bug.cgi?id=47141


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101696

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/CodeGenCXX/matrix-casts.cpp
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- clang/test/SemaCXX/matrix-casts.cpp
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -14,7 +14,6 @@
 typedef int vec __attribute__((vector_size(4)));
 
 void f1() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
   matrix_4_4 m2;
   matrix_4_4 m3;
@@ -23,45 +22,45 @@
   vec v;
   test_struct *s;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
-4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+  m2 = (matrix_4_4)m1;
+  m3 = (matrix_4_4)m2;
+  (matrix_5_5)m3; // expected-error {{conversion between matrix types 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') and 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') of different size is not\
+ allowed}}
 
-  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
-4)))') to 'int'}}
-  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
-matrix_type(4, 4)))') is not allowed}}
+  (int)m3;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'short __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
+  (matrix_4_4)i; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'int' is not allowed}}
 
-  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
-to 'vec' (vector of 1 'int' value) is not allowed}}
-  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
-(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (vec) m2;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'int __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'vec' (vector of 1 'int' value) is not allowed}}
 
-  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
-((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
-  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
-((matrix_type(5, 5)))') is not allowed}}'
+  (test_struct *)m1;// expected-error {{conversion between matrix type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') and incompatible type 'test_struct *' is not allowed}}'
+  (matrix_5_5)s; // expected-error {{conversion between matrix type 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') and incompatible type 'test_struct *' is not allowed}}'
 }
 
 void f2() {
-  // TODO: Update this test once the support of C-style casts for C++ is implemented.
   matrix_4_4 m1;
-  matrix_5_5 m2;
-  matrix_5_5 m3;
-  matrix_4_4 m4;
+  matrix_4_4 m2;
+  matrix_5_5 m3;
+  matrix_5_5 m4;
+  matrix_4_4 m5;
+  matrix_5_5 m6;
   float f;
 
-  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
-((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
-  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
-  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
-((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
-is not allowed}}
-  (matrix_4_4)m4;  // expected-error {{C-style cast from 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D99037#2679131 , @fhahn wrote:

> In D99037#2678848 , @SaurabhJha 
> wrote:
>
>> In D99037#2678779 , @fhahn wrote:
>>
>>> 
>>
>> Will create a new patch to address your last comments
>
> Can you directly update this one? I'll commit it after the update.

Sure, done. I did not know I could change the patch after its accepted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 336395.
SaurabhJha added a comment.

Replace `matrices` with `matrixes` in comments and rewrite the comment about 
element types


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D99037#2678779 , @fhahn wrote:

> 

Will create a new patch to address your last comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-09 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

> LGTM, thanks for working on this!

Thanks so much Florian. Can you please also commit this on my behalf as I don't 
have commit access? Cheers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

The windows build failure is solved by itself and its all passing now!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/test/CodeGen/matrix-cast.c:82
+
+void cast_unsigned_short_int_to_unsigned_int(unsigned_short_int_5x5 s, 
unsigned_int_5x5 i) {
+  // CHECK-LABEL: define{{.*}} void 
@cast_unsigned_short_int_to_unsigned_int(<25 x i16> %s, <25 x i32> %i)

fhahn wrote:
> I think this is still missing a test from unsigned to signed?
I added a new `cast_unsigned_long_int_matrix_to_short`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 336154.
SaurabhJha added a comment.

Addressed latest round of comments.
Also rebased with latest main as the windows build failed for some reason


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1219
+  } else {
+SrcElementTy = SrcTy;
+DstElementTy = DstTy;

fhahn wrote:
> We should be able to assert here that both types are not matrix types, I 
> think?
I did `!SrcType->isMatrixType() && !DstType->isMatrixType()` instead of 
`!SrcType->isMatrixType() || !DstType->isMatrixType()` which I hope was the 
correct thing to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-08 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 336022.
SaurabhJha added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hopefully this will work. My IDE is a bit wonky and it will take hours to 
rebuild for me after rebase. So pushed here with the hope that this could be 
validated using web build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1453
+  CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16,
+   CGF.CGM.FloatTy),
+  Res);

Not sure why this was changed. Perhaps clang-clean.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335913.
SaurabhJha added a comment.

Rebased with latest main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 

[PATCH] D100051: [clang] Move int <-> float scalar conversion to a separate function

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D100051#2674849 , @erichkeane 
wrote:

> Alright, validating it now, then I'll push.

Thanks very much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100051

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


[PATCH] D100051: [clang] Move int <-> float scalar conversion to a separate function

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

I don't have commit rights so if it looks good to you, please commit on my 
behalf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100051

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


[PATCH] D100051: [clang] Move int <-> float scalar conversion to a separate function

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335884.
SaurabhJha added a comment.

Rename the function to `EmitScalarCast` and directly returning from `if` 
branches now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100051

Files:
  clang/lib/CodeGen/CGExprScalar.cpp


Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -348,6 +348,9 @@
   EmitImplicitIntegerSignChangeChecks(
   SanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
   };
+  Value *EmitScalarCast(Value *Src, QualType SrcType, QualType DstType,
+llvm::Type *SrcTy, llvm::Type *DstTy,
+ScalarConversionOpts Opts);
   Value *
   EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy,
SourceLocation Loc,
@@ -1191,6 +1194,35 @@
 {Src, Dst});
 }
 
+Value *ScalarExprEmitter::EmitScalarCast(Value *Src, QualType SrcType,
+ QualType DstType, llvm::Type *SrcTy,
+ llvm::Type *DstTy,
+ ScalarConversionOpts Opts) {
+  if (isa(SrcTy)) {
+bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
+if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
+  InputSigned = true;
+}
+
+if (isa(DstTy))
+  return Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
+if (InputSigned)
+  return Builder.CreateSIToFP(Src, DstTy, "conv");
+return Builder.CreateUIToFP(Src, DstTy, "conv");
+  }
+
+  if (isa(DstTy)) {
+assert(SrcTy->isFloatingPointTy() && "Unknown real conversion");
+if (DstType->isSignedIntegerOrEnumerationType())
+  return Builder.CreateFPToSI(Src, DstTy, "conv");
+return Builder.CreateFPToUI(Src, DstTy, "conv");
+  }
+
+  if (DstTy->getTypeID() < SrcTy->getTypeID())
+return Builder.CreateFPTrunc(Src, DstTy, "conv");
+  return Builder.CreateFPExt(Src, DstTy, "conv");
+}
+
 /// Emit a conversion from the specified type to the specified destination 
type,
 /// both of which are LLVM scalar types.
 Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
@@ -1384,31 +1416,7 @@
 DstTy = CGF.FloatTy;
   }
 
-  if (isa(SrcTy)) {
-bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
-if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
-  InputSigned = true;
-}
-if (isa(DstTy))
-  Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
-else if (InputSigned)
-  Res = Builder.CreateSIToFP(Src, DstTy, "conv");
-else
-  Res = Builder.CreateUIToFP(Src, DstTy, "conv");
-  } else if (isa(DstTy)) {
-assert(SrcTy->isFloatingPointTy() && "Unknown real conversion");
-if (DstType->isSignedIntegerOrEnumerationType())
-  Res = Builder.CreateFPToSI(Src, DstTy, "conv");
-else
-  Res = Builder.CreateFPToUI(Src, DstTy, "conv");
-  } else {
-assert(SrcTy->isFloatingPointTy() && DstTy->isFloatingPointTy() &&
-   "Unknown real conversion");
-if (DstTy->getTypeID() < SrcTy->getTypeID())
-  Res = Builder.CreateFPTrunc(Src, DstTy, "conv");
-else
-  Res = Builder.CreateFPExt(Src, DstTy, "conv");
-  }
+  Res = EmitScalarCast(Src, SrcType, DstType, SrcTy, DstTy, Opts);
 
   if (DstTy != ResTy) {
 if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {


Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -348,6 +348,9 @@
   EmitImplicitIntegerSignChangeChecks(
   SanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
   };
+  Value *EmitScalarCast(Value *Src, QualType SrcType, QualType DstType,
+llvm::Type *SrcTy, llvm::Type *DstTy,
+ScalarConversionOpts Opts);
   Value *
   EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy,
SourceLocation Loc,
@@ -1191,6 +1194,35 @@
 {Src, Dst});
 }
 
+Value *ScalarExprEmitter::EmitScalarCast(Value *Src, QualType SrcType,
+ QualType DstType, llvm::Type *SrcTy,
+ llvm::Type *DstTy,
+ ScalarConversionOpts Opts) {
+  if (isa(SrcTy)) {
+bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
+if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
+  InputSigned = true;
+}
+
+if (isa(DstTy))
+  return Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
+if (InputSigned)
+  return Builder.CreateSIToFP(Src, DstTy, "conv");
+return 

[PATCH] D100051: [clang] Move int <-> float scalar conversion to a separate function

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D100051#2674674 , @erichkeane 
wrote:

> Hrmph... Phab ate my other comment, which was that the name 
> `EmitCastBetweenScalarTypes` feels clunky.  Does `EmitScalarCast` or 
> `EmitScalarScalarCast` sound better and capture the meaning correctly?

Yeah, good idea. I'll rename it to `EmitScalarCast`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100051

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

> I think the issue might be that adding this additional cast-kind caused the 
> value to exceed the maximum supported by the `CastExprBitfields`; the 
> bitfield can only store 64 values, but after adding `MatrixCast`, 
> `CK_IntToOCLSampler` will have value `64`, so assigning to the bitfield 
> results in `0` being assigned. I *think* you have to bump the bitfield size 
> to 7 or perhaps 8 (which may result in slightly better codegen). 
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/Stmt.h#L521

This worked. Setting it to 7 made the tests pass.

I have created a separate patch for codegen refactoring here 
https://reviews.llvm.org/D100051. Once that's merged, I can rebase this 
patch/branch against that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D100051: [clang] Move int <-> float scalar conversion to a separate function

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As prelude to this patch https://reviews.llvm.org/D99037, we want to move the 
int-float conversion
into a separate function that can be reused by matrix cast


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100051

Files:
  clang/lib/CodeGen/CGExprScalar.cpp


Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -348,6 +348,10 @@
   EmitImplicitIntegerSignChangeChecks(
   SanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
   };
+  Value *EmitCastBetweenScalarTypes(Value *Src, QualType SrcType,
+QualType DstType, llvm::Type *SrcTy,
+llvm::Type *DstTy,
+ScalarConversionOpts Opts);
   Value *
   EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy,
SourceLocation Loc,
@@ -1191,6 +1195,38 @@
 {Src, Dst});
 }
 
+Value *ScalarExprEmitter::EmitCastBetweenScalarTypes(
+Value *Src, QualType SrcType, QualType DstType, llvm::Type *SrcTy,
+llvm::Type *DstTy, ScalarConversionOpts Opts) {
+  Value *Res = nullptr;
+
+  if (isa(SrcTy)) {
+bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
+if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
+  InputSigned = true;
+}
+if (isa(DstTy))
+  Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
+else if (InputSigned)
+  Res = Builder.CreateSIToFP(Src, DstTy, "conv");
+else
+  Res = Builder.CreateUIToFP(Src, DstTy, "conv");
+  } else if (isa(DstTy)) {
+assert(SrcTy->isFloatingPointTy() && "Unknown real conversion");
+if (DstType->isSignedIntegerOrEnumerationType())
+  Res = Builder.CreateFPToSI(Src, DstTy, "conv");
+else
+  Res = Builder.CreateFPToUI(Src, DstTy, "conv");
+  } else {
+if (DstTy->getTypeID() < SrcTy->getTypeID())
+  Res = Builder.CreateFPTrunc(Src, DstTy, "conv");
+else
+  Res = Builder.CreateFPExt(Src, DstTy, "conv");
+  }
+
+  return Res;
+}
+
 /// Emit a conversion from the specified type to the specified destination 
type,
 /// both of which are LLVM scalar types.
 Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
@@ -1384,31 +1420,7 @@
 DstTy = CGF.FloatTy;
   }
 
-  if (isa(SrcTy)) {
-bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
-if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
-  InputSigned = true;
-}
-if (isa(DstTy))
-  Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv");
-else if (InputSigned)
-  Res = Builder.CreateSIToFP(Src, DstTy, "conv");
-else
-  Res = Builder.CreateUIToFP(Src, DstTy, "conv");
-  } else if (isa(DstTy)) {
-assert(SrcTy->isFloatingPointTy() && "Unknown real conversion");
-if (DstType->isSignedIntegerOrEnumerationType())
-  Res = Builder.CreateFPToSI(Src, DstTy, "conv");
-else
-  Res = Builder.CreateFPToUI(Src, DstTy, "conv");
-  } else {
-assert(SrcTy->isFloatingPointTy() && DstTy->isFloatingPointTy() &&
-   "Unknown real conversion");
-if (DstTy->getTypeID() < SrcTy->getTypeID())
-  Res = Builder.CreateFPTrunc(Src, DstTy, "conv");
-else
-  Res = Builder.CreateFPExt(Src, DstTy, "conv");
-  }
+  Res = EmitCastBetweenScalarTypes(Src, SrcType, DstType, SrcTy, DstTy, Opts);
 
   if (DstTy != ResTy) {
 if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {


Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -348,6 +348,10 @@
   EmitImplicitIntegerSignChangeChecks(
   SanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
   };
+  Value *EmitCastBetweenScalarTypes(Value *Src, QualType SrcType,
+QualType DstType, llvm::Type *SrcTy,
+llvm::Type *DstTy,
+ScalarConversionOpts Opts);
   Value *
   EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy,
SourceLocation Loc,
@@ -1191,6 +1195,38 @@
 {Src, Dst});
 }
 
+Value *ScalarExprEmitter::EmitCastBetweenScalarTypes(
+Value *Src, QualType SrcType, QualType DstType, llvm::Type *SrcTy,
+llvm::Type *DstTy, ScalarConversionOpts Opts) {
+  Value *Res = nullptr;
+
+  if (isa(SrcTy)) {
+bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
+if (SrcType->isBooleanType() && Opts.TreatBooleanAsSigned) {
+  InputSigned = true;
+}
+if (isa(DstTy))
+  Res = 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Okay interesting I should have posted before. Seems like when I move 
`MatrixCast` to the bottom of OperationKinds.def, and do nothing else, the 
matrix-cast CodeGen fails with this error. It is somehow not able to assign 
correct cast type.

  + /tmp/build/bin/clang -cc1 -internal-isystem 
/tmp/build/lib/clang/13.0.0/include -nostdsysteminc -fenable-matrix -triple 
x86_64-apple-darwin /tmp/clang/test/CodeGen/matrix-cast.c -emit-llvm 
-disable-llvm-passes -o -
  + /tmp/build/bin/FileCheck /tmp/clang/test/CodeGen/matrix-cast.c
  dependent cast kind in IR gen!
  UNREACHABLE executed at /tmp/clang/lib/CodeGen/CGExprScalar.cpp:1985!
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.Program arguments: /tmp/build/bin/clang -cc1 -internal-isystem 
/tmp/build/lib/clang/13.0.0/include -nostdsysteminc -fenable-matrix -triple 
x86_64-apple-darwin /tmp/clang/test/CodeGen/matrix-cast.c -emit-llvm 
-disable-llvm-passes -o -
  1./tmp/clang/test/CodeGen/matrix-cast.c:22:1: current parser token 'void'
  2./tmp/clang/test/CodeGen/matrix-cast.c:12:6: LLVM IR generation of 
declaration 'cast_char_matrix_to_int'
  3./tmp/clang/test/CodeGen/matrix-cast.c:12:6: Generating code for 
declaration 'cast_char_matrix_to_int'
   #0 0x0974250a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:565:11
   #1 0x097426db PrintStackTraceSignalHandler(void*) 
/tmp/llvm/lib/Support/Unix/Signals.inc:632:1
   #2 0x09740cab llvm::sys::RunSignalHandlers() 
/tmp/llvm/lib/Support/Signals.cpp:70:5
   #3 0x09742e51 SignalHandler(int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:407:1
   #4 0x7f503b2923c0 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
   #5 0x7f503ad4318b raise 
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #6 0x7f503ad22859 abort 
/build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
   #7 0x09661fe4 /tmp/llvm/lib/Support/ErrorHandling.cpp:213:3
   #8 0x09fd93fb (anonymous 
namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:1987:5
   #9 0x09fd934e (anonymous 
namespace)::ScalarExprEmitter::VisitExplicitCastExpr(clang::ExplicitCastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:568:5
  #10 0x09fd17b3 clang::StmtVisitorBase::VisitCStyleCastExpr(clang::CStyleCastExpr*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:891:1
  #11 0x09fcb9ff clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:891:1
  #12 0x09fc0d0b (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:415:3
  #13 0x09fce242 (anonymous 
namespace)::ScalarExprEmitter::VisitBinAssign(clang::BinaryOperator const*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4218:9
  #14 0x09fca7fd clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/clang/include/clang/AST/StmtVisitor.h:72:26
  #15 0x09fc0d0b (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:415:3
  #16 0x09fc0c66 
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4807:3
  #17 0x09e7edec 
clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot, bool) /tmp/clang/lib/CodeGen/CGExpr.cpp:218:12
  #18 0x09e7ed1d 
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) 
/tmp/clang/lib/CodeGen/CGExpr.cpp:203:19
  #19 0x09fed236 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt 
const*, llvm::ArrayRef) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:118:5
  #20 0x09ff664b 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:453:3
  #21 0x09e573c1 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) 
/tmp/clang/lib/CodeGen/CodeGenFunction.cpp:1194:5
  #22 0x09e57e91 
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, 
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) 
/tmp/clang/lib/CodeGen/CodeGenFunction.cpp:1358:3
  #23 0x09d0b7de 
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) /tmp/clang/lib/CodeGen/CodeGenModule.cpp:4780:3
  #24 0x09d0215c 
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) /tmp/clang/lib/CodeGen/CodeGenModule.cpp:3166:12
  #25 0x09d071e4 
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) 
/tmp/clang/lib/CodeGen/CodeGenModule.cpp:2919:5
  #26 0x09d0f040 
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-07 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey Florian and John,

Thanks for your reviews so far. Just checked the build. Addressed all previous 
comments and the build is looking good too except for one thing. For open cl 
tests, it is failing with this curious `error: initializer element is not a 
compile-time constant` which I am still not sure how to debug. I tried to debug 
`Clang.SemaOpenCL::sampler_t_overload.cl` by moving the definition of 
`MatrixCast` in `OperationKinds.def` to below the definition of 
`IntToOCLSampler`. That made it work for `sampler_overload` but then the new 
matrix cast tests started failing.

Will give it another shot today. If you have any thoughts on this, let me know.

Saurabh


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335680.
SaurabhJha added a comment.

Fix the bug with int <-> float conversion by explicitly passing llvm types to 
EmitCastBetweenScalarTypes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3;// expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec) m2;// expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1;// expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1;   // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2;// expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4;  // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335677.
SaurabhJha added a comment.

I reverted the int <-> float conversion to previous code to make the tests 
pass. That way, we atleast have something working and we can go from there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1; // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3; // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1; // expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1; // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2; // expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4; // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335643.
SaurabhJha added a comment.

Changes in latest revision:

- Updated definition of areMatrixTypesOfTheSameDimension to reflect the comment
- Refactored casting between types into EmitCastBetweenScalarTypes
- Removed mentions of "non matrix"
- Replaced matrices with matrixes
- Update error messages to "..is not allowed"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only -verify %s
+
+template 
+
+using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+template 
+
+using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
+
+typedef struct test_struct {
+} test_struct;
+
+typedef int vec __attribute__((vector_size(4)));
+
+void f1() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_4_4 m2;
+  matrix_4_4 m3;
+  matrix_5_5 m4;
+  int i;
+  vec v;
+  test_struct *s;
+
+  (matrix_4_4)m1; // expected-error {{C-style cast from 'matrix_4_4' (aka 'char __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_4_4)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, \
+4)))') to 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'matrix_5_5' (aka 'int __attribute__((matrix_type(5, 5)))') is not allowed}}
+
+  (int)m3; // expected-error {{C-style cast from 'matrix_4_4' (aka 'short __attribute__((matrix_type(4, \
+4)))') to 'int'}}
+  (matrix_4_4)i; // expected-error {{C-style cast from 'int' to 'matrix_4_4' (aka 'int __attribute__((\
+matrix_type(4, 4)))') is not allowed}}
+
+  (vec)m2; // expected-error {{C-style cast from 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') \
+to 'vec' (vector of 1 'int' value) is not allowed}}
+  (matrix_4_4)v; // expected-error {{C-style cast from 'vec' (vector of 1 'int' value) to 'matrix_4_4' \
+(aka 'char __attribute__((matrix_type(4, 4)))') is not allowed}}
+
+  (test_struct *)m1; // expected-error {{cannot cast from type 'matrix_4_4' (aka 'char __attribute__\
+((matrix_type(4, 4)))') to pointer type 'test_struct *}}'
+  (matrix_5_5)s; // expected-error {{C-style cast from 'test_struct *' to 'matrix_5_5' (aka 'float __attribute__\
+((matrix_type(5, 5)))') is not allowed}}'
+}
+
+void f2() {
+  // TODO: Update this test once the support of C-style casts for C++ is implemented.
+  matrix_4_4 m1;
+  matrix_5_5 m2;
+  matrix_5_5 m3;
+  matrix_4_4 m4;
+  float f;
+
+  (matrix_4_4)m1; // expected-error {{C-style cast from 'matrix_4_4' (aka 'float __attribute__\
+((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'double __attribute__((matrix_type(4, 4)))') is not allowed}}
+  (matrix_5_5)m2; // expected-error {{C-style cast from 'matrix_5_5' (aka 'double __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'float __attribute__((matrix_type(5, 5)))') is not allowed}}
+  (matrix_5_5)m3; // expected-error {{C-style cast from 'matrix_5_5' (aka 'int __attribute__\
+((matrix_type(5, 5)))') to 'matrix_5_5' (aka 'unsigned int __attribute__((matrix_type(5, 5)))') \
+is not allowed}}
+  (matrix_4_4)m4; // expected-error {{C-style cast from 'matrix_4_4' (aka 'unsigned int \
+__attribute__((matrix_type(4, 4)))') to 'matrix_4_4' (aka 'int __attribute__((matrix_type(4, 4)))') is not \
+allowed}}
+}
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/include/clang/AST/OperationKinds.def:185
+/// CK_MatrixCast - A cast between matrix types of the same dimensions.
+CAST_OPERATION(MatrixCast)
+

This line is causing me issues that I don't know how to solve. If we leave it 
in the current place on line 185. The new tests Sema and CodeGen tests are 
passing but Clang.SemaOpenCL::sampler_t.cl and 
Clang.SemaOpenCL::sampler_t_overload.cl (along with other sampler tests) are 
failing.

And if I move it to the bottom, right after `CAST_OPERATION(IntToOCLSampler)`, 
the sampler tests pass but the new matrix conversion tests are failing. Am I 
missing something here? My understanding was implementing new cast kind is just 
the matter of defining a `CAST_OPERATION` in this file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1324
+
+if (SrcElementTy->isFloatTy() || SrcElementTy->isDoubleTy()) {
+  QualType DstElementType = 
DstType->castAs()->getElementType();

fhahn wrote:
> SaurabhJha wrote:
> > fhahn wrote:
> > > I think we should support all floating point type here 
> > > (`isFloatingPointTy`). Basically we want the same rules as for integer 
> > > types (around line 1418). Perhaps it would be possible to generalize this 
> > > code in a separate function that takes the LLVM types & the element 
> > > type/scalar types?
> > I think we should move this code to `MatrixBuilder` but then generalising 
> > floating point after that would be problematic since the code is splitted 
> > across this function and in MatrixBuilder, right?
> That's a good point. Sharing the logic with the scalar case in Clang directly 
> seems much more valuable than having it in the MatrixBuilder IMO.
Whoops, I just moved the code to MatrixBuilder. Will revert it back and 
generalise it :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-06 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1324
+
+if (SrcElementTy->isFloatTy() || SrcElementTy->isDoubleTy()) {
+  QualType DstElementType = 
DstType->castAs()->getElementType();

fhahn wrote:
> I think we should support all floating point type here (`isFloatingPointTy`). 
> Basically we want the same rules as for integer types (around line 1418). 
> Perhaps it would be possible to generalize this code in a separate function 
> that takes the LLVM types & the element type/scalar types?
I think we should move this code to `MatrixBuilder` but then generalising 
floating point after that would be problematic since the code is splitted 
across this function and in MatrixBuilder, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-05 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335216.
SaurabhJha added a comment.

Move back CK_MatrixCast definition to to just above CK_VectorSplat. The Matrix 
CodeGen is passing again but SemaOpenCL/sampler tests are failing again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  i = (int)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  m4 = (ix5x5)i;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  v = (vec)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  m4 = (ix5x5)v;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  s = (test_struct *)m3; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+  m3 = (sx4x4)s; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+  float f;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+  f = (float)m4;   // expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+  m4 = (signed_int_12x12)f;// expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-04 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335182.
SaurabhJha added a comment.

Move the definition of MatrixCast to the bottom in OperationKinds.def


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  i = (int)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  m4 = (ix5x5)i;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  v = (vec)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  m4 = (ix5x5)v;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  s = (test_struct *)m3; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+  m3 = (sx4x4)s; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+  float f;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+  f = (float)m4;   // expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+  m4 = (signed_int_12x12)f;// expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ 

[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-04 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D99037#2668295 , @SaurabhJha wrote:

> One other problem is somehow this test is failing 
> https://github.com/llvm/llvm-project/blob/main/clang/test/SemaOpenCL/sampler_t_overload.cl#L6
>  with this error.
>
>   /tmp/clang/test/SemaOpenCL/sampler_t_overload.cl:6:30: error: initializer 
> element is not a compile-time constant
>   constant sampler_t glb_smp = 5;
>^
>   1 error generated.
>
> Not sure what's going on but will continue to debug. Let me know if there's 
> something simple that I am missing here.

I think I got it. If I remove the definition of `CAST_OPERATION(MatrixCast)` 
from `OperationKinds.def`, it works. So probably a matter of defining it the 
correct way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-04 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

One other problem is somehow this test is failing 
https://github.com/llvm/llvm-project/blob/main/clang/test/SemaOpenCL/sampler_t_overload.cl#L6
 with this error.

  /tmp/clang/test/SemaOpenCL/sampler_t_overload.cl:6:30: error: initializer 
element is not a compile-time constant
  constant sampler_t glb_smp = 5;
   ^
  1 error generated.

Not sure what's going on but will continue to debug. Let me know if there's 
something simple that I am missing here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement C-style explicit type conversions for matrix types

2021-04-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335084.
SaurabhJha added a comment.

Update one inline comment in SemaCast.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  i = (int)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  m4 = (ix5x5)i;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  v = (vec)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  m4 = (ix5x5)v;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  s = (test_struct *)m3; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+  m3 = (sx4x4)s; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+  float f;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+  f = (float)m4;   // expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+  m4 = (signed_int_12x12)f;// expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,100 @@

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-03 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335083.
SaurabhJha added a comment.

Addressed most of the comments. I couldn't understand "..would also be good to 
have C++ tests that test casting with matrix types where some of the dimensions 
are template arguments...". When I tried this

"""
cx4x4 m1;

(void)(ix4x4)m1
"""

it gave me the error
"""
C-style cast from 'cx4x4' (aka 'char __attribute__((matrix_type(4, 4)))') to 
'ix4x4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed
"""
should I address it as part of this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  i = (int)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  m4 = (ix5x5)i;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  v = (vec)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  m4 = (ix5x5)v;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  s = (test_struct *)m3; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+  m3 = (sx4x4)s; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+  float f;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+  f = (float)m4;   // expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix 

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/test/CodeGen/matrix-cast.c:15
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = zext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT:  store <25 x i32> [[CONV]], <25 x i32>* {{.*}}, align 4

fhahn wrote:
> This doesn't seem right. We are casting between 2 signed types, so the sign 
> should get preserved, right? Shouldn't this be `sext`? See 
> https://godbolt.org/z/zWznYdnKW for the scalar case.
> 
> I think you also need tests for casts with different bitwidths with unsigned, 
> unsigned -> signed & signed -> unsigned.
This is happening because we are always passing inSigned argument to 
`Builder.CreateIntCast` as false here 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprScalar.cpp#L1348.
 IfI change it to `true`, it generates `sext` instructions.

I am figuring out how can I determine sign of src and dest type. Because 
`SrcTy` and `DestTy` are vectors here, they are unsigned and `SrcElementTy` and 
`DestElementTy` have no method like `isSignedIntegerOrEnumerationType`. Once 
that's solved, this should be fixed.



Comment at: clang/test/CodeGen/matrix-cast.c:39
+
+  f = (fx5x5)i;
+}

fhahn wrote:
> SaurabhJha wrote:
> > I tried adding a float -> int conversion too but it failed because of this 
> > assertion 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprScalar.cpp#L1339-L1344
> >  Hopefully that's intended.
> Clang should never run into an assertion. If that should not be allowed, then 
> Clang should emit an error during Sema. I'm not sure why there is such a 
> restriction for vector types, but I am not sure that this shouldn't be 
> allowed for matrixes. Perhaps @rjmccall has more thoughts on this, but 
> conversion between scalar ints to floats is allowed AFAIKT.
I can probably try removing that assert and see if some other unit or lit tests 
are failing. We can then make a decision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 334951.
SaurabhJha added a comment.

Update commit message to more accurately reflect the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef char cx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef short sx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef double dx5x5 __attribute__((matrix_type(5, 5)));
+typedef signed int signed_int_5x5 __attribute__((matrix_type(5, 5)));
+typedef unsigned int unsigned_int_5x5 __attribute__((matrix_type(5, 5)));
+
+void cast_char_matrix_to_int(cx5x5 c, ix5x5 i) {
+  // CHECK-LABEL: define{{.*}} void @cast_char_matrix_to_int(<25 x i8> %c, <25 x i32> %i)
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = zext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT:  store <25 x i32> [[CONV]], <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  i = (ix5x5)c;
+}
+
+void cast_int_matrix_to_short(ix5x5 i, sx5x5 s) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_short(<25 x i32> %i, <25 x i16> %s)
+  // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>
+  // CHECK-NEXT:  store <25 x i16> [[CONV]], <25 x i16>* {{.*}}, align 2
+  // CHECK-NEXT:  ret void
+
+  s = (sx5x5)i;
+}
+
+void cast_int_matrix_to_float(ix5x5 i, fx5x5 f) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_float(<25 x i32> %i, <25 x float> %f)
+  // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Added some inline comments on where I have some doubts.




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:547
+  case CK_MatrixCast: {
+// TODO: Handle MatrixCast here.
+  }

I thought doing changes here is is outside the scope of casting so I just left 
a TODO here. Please let me know if we want to do something else here.



Comment at: clang/test/CodeGen/matrix-cast.c:39
+
+  f = (fx5x5)i;
+}

I tried adding a float -> int conversion too but it failed because of this 
assertion 
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprScalar.cpp#L1339-L1344
 Hopefully that's intended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 334945.
SaurabhJha added a comment.

Updating D99037 : [Matrix] Implement explicit 
type conversions for matrix types
Removed unused variables and includes and fix codegen lit tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef char cx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef short sx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef double dx5x5 __attribute__((matrix_type(5, 5)));
+typedef signed int signed_int_5x5 __attribute__((matrix_type(5, 5)));
+typedef unsigned int unsigned_int_5x5 __attribute__((matrix_type(5, 5)));
+
+void cast_char_matrix_to_int(cx5x5 c, ix5x5 i) {
+  // CHECK-LABEL: define{{.*}} void @cast_char_matrix_to_int(<25 x i8> %c, <25 x i32> %i)
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = zext <25 x i8> [[C]] to <25 x i32>
+  // CHECK-NEXT:  store <25 x i32> [[CONV]], <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  i = (ix5x5)c;
+}
+
+void cast_int_matrix_to_short(ix5x5 i, sx5x5 s) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_short(<25 x i32> %i, <25 x i16> %s)
+  // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>
+  // CHECK-NEXT:  store <25 x i16> [[CONV]], <25 x i16>* {{.*}}, align 2
+  // CHECK-NEXT:  ret void
+
+  s = (sx5x5)i;
+}
+
+void cast_int_matrix_to_float(ix5x5 i, fx5x5 f) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_float(<25 x 

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

I pushed some unwanted changes that I used for debugging..fixing/removing them 
now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-02 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 334942.
SaurabhJha added a comment.

Updating D99037 : [Matrix] Implement explicit 
type conversions for matrix types

Latest update includes code gen for c style casts along with some lit tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef char cx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef short sx5x5 __attribute__((matrix_type(5, 5)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef double dx5x5 __attribute__((matrix_type(5, 5)));
+typedef signed int signed_int_5x5 __attribute__((matrix_type(5, 5)));
+typedef unsigned int unsigned_int_5x5 __attribute__((matrix_type(5, 5)));
+
+void cast_char_matrix_to_int(cx5x5 c, ix5x5 i) {
+  // CHECK-LABEL: define{{.*}} void @cast_char_matrix_to_int(<25 x i8> %c, <25 x i32> %i)
+  // CHECK:   [[C:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[C1:%.*]] = load <25 x i8>, <25 x i8>* {{.*}}, align 1
+  // CHECK-NEXT:  [[CONV:%.*]] = zext <25 x i8> [[C1]] to <25 x i32>
+  // CHECK-NEXT:  store <25 x i32> [[CONV]], <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  ret void
+
+  i = (ix5x5)c;
+}
+
+void cast_int_matrix_to_short(ix5x5 i, sx5x5 s) {
+  // CHECK-LABEL: define{{.*}} void @cast_int_matrix_to_short(<25 x i32> %i, <25 x i16> %s)
+  // CHECK:   [[I:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  [[I1:%.*]] = load <25 x i32>, <25 x i32>* {{.*}}, align 4
+  // CHECK-NEXT:  [[CONV:%.*]] = trunc <25 x i32> [[I1]] to <25 x i16>
+  // CHECK-NEXT:  store <25 x i16> [[CONV]], <25 x i16>* {{.*}}, align 2
+  // 

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-01 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 334815.
SaurabhJha added a comment.
Herald added a subscriber: martong.

Hi Florian and John,

Thanks for the comments so far. I figure it would be easier for further 
discussion if I have something concrete. Here's what I have right now:

- A new CK_MatrixCast.
- Sema code for C-style cast along with its tests.
- My guess on places CK_MatrixCast will go in CodeGen. I have added a TODO in 
CGExprScalar.cpp indicating where I think we should implement the code gen for 
this conversion. There's a failing CodeGen test too.
- I am not sure yet if we need to anything with 
StaticAnalyzer/Core/ExprEngineC.cpp. I got a warning that CK_MatrixCast needs 
handling there.

My next step is to make it work for C style cast. Once that works, I can use 
that learning to implement static_cast.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+
+void cast_char_matrix_to_int_same_size(cx4x4 c, ix4x4 i) {
+   c = (cx4x4)i;
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -543,6 +543,9 @@
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;
   }
+  case CK_MatrixCast: {
+// TODO: Handle MatrixCast here.
+  }
 }
   }
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7312,6 +7312,19 @@
  

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-04-01 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey, elementary question about arcanist. I followed the steps here 
https://llvm.org/docs/Contributing.html#how-to-submit-a-patch and did

  arc diff --edit --verbatim

on my current branch. Probably one mistake I did was to do a `git reset HEAD~1` 
and create a new commit. Now its trying to create a new revision. Is that okay 
to create a new revision and abandoning this one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99765: [Matrix] Implement explicit type conversions for matrix types

2021-04-01 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Sorry, this revision was created by mistake. I just wanted to update 
https://reviews.llvm.org/D99037


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99765

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


[PATCH] D99765: [Matrix] Implement explicit type conversions for matrix types

2021-04-01 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
Herald added subscribers: martong, tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[Matrix] Implement explicit type conversions for MatrixType.
Bugzilla ticket is here: https://bugs.llvm.org/show_bug.cgi?id=47141


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99765

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c
===
--- /dev/null
+++ clang/test/CodeGen/matrix-cast.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+
+void cast_char_matrix_to_int_same_size(cx4x4 c, ix4x4 i) {
+   c = (cx4x4)i;
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -543,6 +543,9 @@
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;
   }
+  case CK_MatrixCast: {
+// TODO: Handle MatrixCast here.
+  }
 }
   }
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7312,6 +7312,19 @@
  ValidScalableConversion(destTy, srcTy);
 }
 
+/// Are the two types matrix types and do they have the same dimensions i.e.
+/// and do they both have the same dimensions i.e. do they have the same number
+/// of rows and the same number of columns?
+bool Sema::areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy) {
+  assert(destTy->isMatrixType() && srcTy->isMatrixType());
+
+  const ConstantMatrixType *matSrcType = srcTy->getAs();
+  const ConstantMatrixType *matDestType = destTy->getAs();
+
+  return (matSrcType->getNumRows() == matDestType->getNumRows() 

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-30 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey, I should mention that I am new to clang/llvm. My below thoughts could be 
wrong.

> IIRC, making C-style casts work correctly in C++ will actually be easier if 
> you make one of the specialized casts do it; I'd say go ahead and do it in 
> `static_cast`.
>
> Casts in C use basically a completely different code path.

Okay, then I think I will focus on static casts and C style casts for later. 
They use different functions, `CheckStaticCast` and `CheckCStyleCast` 
respectively and implementing static casts in matrix must involve change in 
`CheckStaticCast` and the function it calls.

> Right, vector casts are their own unfortunate thing which we don't want to 
> semantically emulate.
>
> What code do you want to get out of this?  Are there e.g. vectorized 
> float->double conversions we can use, or is the operation basically doomed to 
> break the matrix apart and put it back together again?

I think because matrices are vectors underneath, we should try vectorised 
conversions.

Thoughts?

Saurabh


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-30 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey @fhahn @rjmccall ,

Thank you so much for your reviews. Apart from the rest of your comments, here 
are the two principle things I am going to do next:

1. Replace the `reinterpret_cast`with `static_cast`. Do you think I should 
focus this revision to C-style casts and do `static_casts` in another patch?
2. Create a new `CK_MatrixCast` and implement its handling.

Is there any existing code I can look at that can help me implement the handler 
code for `CK_MatrixCast`? I could look at vectors because I was doing 
`CK_Bitcast` but I don't think I can rely on that now. If there's no such 
existing code at the moment, that's not an issue. I think I should be able 
figure it out after I spend some more time on it.

Cheers,
Saurabh


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-30 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:7315
+/// is not a scalar type.
+bool Sema::areCompatibleMatrixTypes(QualType srcTy, QualType destTy) {
+  assert(destTy->isMatrixType() && srcTy->isMatrixType());

rjmccall wrote:
> "Compatible" has a specific meaning in the C standard, so if you aren't 
> intending to invoke that concept of compatibility, you should find a new word.
> 
> It looks like this kind of cast is supposed to be doing an elementwise 
> conversion.  I guess all the types you can have matrices of are 
> interconvertible, so there are no restrictions on the element types.  But you 
> definitely need this to produce a new `CastKind` for elementwise conversion 
> instead of using `CK_BitCast`, which does a bitwise reinterpretation, which 
> is not what you want.
> 
> Matrix element types already have to be scalar types, so those checks aren't 
> doing anything.
I see, so we need a new `CK_MatrixCast`, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-24 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

Hey @fhahn ,

I realise, as you pointed out before, that we need to do some changes in 
CodeGen too. I think its going to be more involved so before starting on that, 
it would be great if you can confirm whether I am on the right path. I will 
describe what I did, what happened, and what I inferred from that.

I ran this simple cast.

  typedef char cx4x4 __attribute__((matrix_type(4, 4)));
  typedef int ix4x4 __attribute__((matrix_type(4, 4)));
  cx4x4 c = (cx4x4) i;

This crashed the compiler with this stack trace.

  clang: /tmp/llvm/lib/IR/Instructions.cpp:2934: static llvm::CastInst 
*llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, 
const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && 
"Invalid cast!"' failed.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.Program arguments: /tmp/build/bin/clang -cc1 -internal-isystem 
/tmp/build/lib/clang/13.0.0/include -nostdsysteminc -fenable-matrix -triple 
x86_64-apple-darwin /tmp/clang/test/CodeGen/matrix-cast.c -emit-llvm 
-disable-llvm-passes -o -
  1. parser at end of file
  2./tmp/clang/test/CodeGen/matrix-cast.c:15:6: LLVM IR generation of 
declaration 'cast_char_matrix_to_int_same_size'
  3./tmp/clang/test/CodeGen/matrix-cast.c:15:6: Generating code for 
declaration 'cast_char_matrix_to_int_same_size'
   #0 0x0972648a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:565:11
   #1 0x0972665b PrintStackTraceSignalHandler(void*) 
/tmp/llvm/lib/Support/Unix/Signals.inc:632:1
   #2 0x09724c4b llvm::sys::RunSignalHandlers() 
/tmp/llvm/lib/Support/Signals.cpp:70:5
   #3 0x09726dd1 SignalHandler(int) 
/tmp/llvm/lib/Support/Unix/Signals.inc:407:1
   #4 0x7ff3d17353c0 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
   #5 0x7ff3d11e618b raise 
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #6 0x7ff3d11c5859 abort 
/build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
   #7 0x7ff3d11c5729 get_sysdep_segment_value 
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
   #8 0x7ff3d11c5729 _nl_load_domain 
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
   #9 0x7ff3d11d6f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
  #10 0x08a5c1bf llvm::CastInst::Create(llvm::Instruction::CastOps, 
llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) 
/tmp/llvm/lib/IR/Instructions.cpp:2936:11
  #11 0x06205834 
llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, 
llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2106:52
  #12 0x061ef472 llvm::IRBuilderBase::CreateBitCast(llvm::Value*, 
llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2065:5
  #13 0x09fb1140 (anonymous 
namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:2069:5
  #14 0x09fb002e (anonymous 
namespace)::ScalarExprEmitter::VisitExplicitCastExpr(clang::ExplicitCastExpr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:563:5
  #15 0x09fa8493 clang::StmtVisitorBase::VisitCStyleCastExpr(clang::CStyleCastExpr*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
  #16 0x09fa2747 clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
  #17 0x09f976fb (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
  #18 0x09fa4f82 (anonymous 
namespace)::ScalarExprEmitter::VisitBinAssign(clang::BinaryOperator const*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4168:9
  #19 0x09fa157d clang::StmtVisitorBase::Visit(clang::Stmt*) 
/tmp/clang/include/clang/AST/StmtVisitor.h:72:26
  #20 0x09f976fb (anonymous 
namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
  #21 0x09f97656 
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
/tmp/clang/lib/CodeGen/CGExprScalar.cpp:4757:3
  #22 0x09e5638c 
clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
clang::CodeGen::AggValueSlot, bool) /tmp/clang/lib/CodeGen/CGExpr.cpp:218:12
  #23 0x09e562bd 
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) 
/tmp/clang/lib/CodeGen/CGExpr.cpp:203:19
  #24 0x09fc3616 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt 
const*, llvm::ArrayRef) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:118:5
  #25 0x09fcc7ab 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
/tmp/clang/lib/CodeGen/CGStmt.cpp:447:3
  #26 0x09e2ebd1 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt 

[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

> I think you probably need to add new files for the tests, e.g. 
> `matrix-type-casts.cpp` & `matrix-type-casts.c` and then just add tests for 
> various valid cast combinations. Is that enough to get you started? You can 
> look at some of the existing matrix codegen tests for inspiration for the 
> run-line & CHECK lines.

Oh yes, missed the obvious thing I could have done, Cheers!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-22 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha added a comment.

In D99037#2640388 , @fhahn wrote:

> Thanks for the patch! I think this also needs changes in code-gen & code-gen 
> tests.

Hey @fhahn I searched but could not find the relevant code-gen and code-gen 
tests I need to fix. Can you please point me to where vectors casts are handled 
in code gen? I could probably use that for matrices.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


  1   2   >