[PATCH] D72281: [Matrix] Add matrix type to Clang.

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 5 12:26:18 PDT 2020


fhahn updated this revision to Diff 262188.
fhahn marked 9 inline comments as done.
fhahn added a comment.

Thanks for the extensive comments! They should be addressed: refactor dependent type construction, template argument deduction, adjust mangling.

In D72281#2019417 <https://reviews.llvm.org/D72281#2019417>, @rjmccall wrote:

> The test cases for function template partial specialization would look something like this:
>
>   template <class T, size_t R, size_t C>
>   using matrix = T __attribute__((matrix_type(R, C)));
>  
>   template <int N> struct selector {};
>  
>   template <class T, size_t R, size_t C>
>   selector<0> use_matrix(matrix<T, R, C> m) {}
>  
>   template <class T, size_t R>
>   selector<1> use_matrix(matrix<T, R, 10> m) {}
>  
>   template <class T>
>   selector<2> use_matrix(matrix<T, 10, 10> m) {}
>  
>   void test() {
>     selector<2> x = use_matrix(matrix<int, 10, 10>());
>     selector<1> y = use_matrix(matrix<int, 12, 10>());
>     selector<0> z = use_matrix(matrix<int, 12, 12>());
>   }
>


That's a great example that highlighted a few other issues (e.g. BuildMatrixType not supporting dependent element types).

The latest version of the patch manages to compile each `use_matrix` definition individually (if there is only a single template definition of `use_matrix`), but there still is a disambiguation failure in the snippet below, if all 3 `use_matrix` definitions are available.

  matrix<int, 10, 10> m1;
  selector<2> x = use_matrix(m1);

The type of `m1` matches the matrix argument in all 3 definitions of `use_matrix` and for some reason the return type is not used to disambiguate the definitions:

  llvm-project/clang/test/CodeGenCXX/matrix-type.cpp:310:19: error: call to 'use_matrix' is ambiguous
    selector<2> x = use_matrix(m1);
                    ^~~~~~~~~~
  llvm-project/clang/test/CodeGenCXX/matrix-type.cpp:300:13: note: candidate function [with T = int, R = 10, C = 10]
  selector<0> use_matrix(matrix<T, R, C> &m) {}
              ^
  llvm-project/clang/test/CodeGenCXX/matrix-type.cpp:303:13: note: candidate function [with T = int, R = 10]
  selector<1> use_matrix(matrix<T, R, 10> &m) {}
              ^
  llvm-project/clang/test/CodeGenCXX/matrix-type.cpp:306:13: note: candidate function [with T = int]
  selector<2> use_matrix(matrix<T, 10, 10> &m) {}

I am not sure where things are going wrong unfortunately. The matrix argument deduction should mirror the code for types like DependentSizedArrayType. Do you have any idea what could be missing?

> But you should include some weirder kinds of template, expressions that aren't deducible, and so on.

Will do, once the issue above is sorted out :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72281

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/debug-info-matrix-types.c
  clang/test/CodeGen/matrix-type.c
  clang/test/CodeGenCXX/matrix-type.cpp
  clang/test/Parser/matrix-type-disabled.c
  clang/test/SemaCXX/matrix-type.cpp
  clang/tools/libclang/CIndex.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72281.262188.patch
Type: text/x-patch
Size: 100649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200505/8bd2bb79/attachment-0001.bin>


More information about the cfe-commits mailing list