Skip to content

Conversation

@hekota
Copy link
Member

@hekota hekota commented Feb 2, 2026

Adds new type attribute __LinAlg_Matrix_Attributes that can be attached to __builtin_LinAlg_Matrix built-in matrix handle type to specify the matrix component type, dimensions, use and scope. Includes enabling C11++ -style attributes on types in DXC.

Adds two new AST types that are used to capture the information from the attribute:

  • AttributedLinAlgMatrixType type is used when the attribute specifies concrete matrix parameters
  • DependentAttributedLinAlgMatrixType is for cases where the type attributes arguments are dependent on template instantiation

The AttributedLinAlgMatrixType is linked to LinAlgMatrix type alias used in gen_intrin_main.txt for built-in function APIs.

This change also adds the outline of the LinAlg Matrix template class to dx/linalg.h, including the enumeration types used as arguments to the new attribute and as template parameters of Matrix.

Note that the ComponentType enum in dx/linalg.h is defined using values matching the existing internal ComponentType enum that was added in SM 6.9 for cooperative vectors. This is different from the current LinAlg spec. The issue to update the spec is microsoft/hlsl-specs#779.

Fixes #8122

@hekota hekota marked this pull request as ready for review February 2, 2026 18:14
@hekota hekota requested a review from llvm-beanz February 2, 2026 18:15
@hekota hekota changed the title Add LinAng Matrix attributes and two new attributed matrix types [SM6.10] Add LinAng Matrix attributes and two new attributed matrix types Feb 2, 2026
@hekota hekota linked an issue Feb 2, 2026 that may be closed by this pull request
__builtin_LinAlg_Matrix [[__LinAlg_Matrix_Attributes(ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup)]] mat8;

// expected-error@+1 {{cannot initialize a variable of type '__builtin_LinAlg_Matrix' with an lvalue of type '__builtin_LinAlg_Matrix [[__LinAlg_Matrix_Attributes(ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup)]]'}}
__builtin_LinAlg_Matrix naked_mat = mat8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be illegal to declare this type without attributes? Is that the reason for TMP?

Copy link
Member Author

@hekota hekota Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it illegal by intercepting every place where a type can be used and adding a special check and error if it is the __builtin_LinAlgMatrix without attributes. Or we can do nothing because the naked typed cannot be used for anything anyway. The __builtin prefix means users should not be using these directly.


// Check that the value is a valid range.
int64_t Value = APVal.getLimitedValue();
if (Value < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we enforce any maximum?

Copy link
Collaborator

@V-FEXrt V-FEXrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I did a very rush job on the review. Wanted to mark my general approval before being out the next couple days

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff eea0b2b70ffcb65484aad2a25ac7948cab230b71 7f61a48c08e28644f4f777d89cd6071e65117708 -- include/dxc/DXIL/DxilConstants.h include/dxc/dxcapi.internal.h tools/clang/include/clang/AST/ASTContext.h tools/clang/include/clang/AST/DataRecursiveASTVisitor.h tools/clang/include/clang/AST/RecursiveASTVisitor.h tools/clang/include/clang/AST/Type.h tools/clang/include/clang/AST/TypeLoc.h tools/clang/include/clang/Sema/SemaHLSL.h tools/clang/include/clang/Serialization/ASTBitCodes.h tools/clang/lib/AST/ASTContext.cpp tools/clang/lib/AST/ASTDumper.cpp tools/clang/lib/AST/ASTImporter.cpp tools/clang/lib/AST/ItaniumMangle.cpp tools/clang/lib/AST/MicrosoftMangle.cpp tools/clang/lib/AST/Type.cpp tools/clang/lib/AST/TypePrinter.cpp tools/clang/lib/Headers/hlsl/dx/linalg.h tools/clang/lib/Parse/ParseDecl.cpp tools/clang/lib/Parse/ParseDeclCXX.cpp tools/clang/lib/Sema/SemaHLSL.cpp tools/clang/lib/Sema/SemaTemplate.cpp tools/clang/lib/Sema/SemaType.cpp tools/clang/lib/Sema/TreeTransform.h tools/clang/lib/Serialization/ASTReader.cpp tools/clang/lib/Serialization/ASTWriter.cpp tools/clang/tools/libclang/CIndex.cpp
View the diff from clang-format here.
diff --git a/tools/clang/include/clang/AST/Type.h b/tools/clang/include/clang/AST/Type.h
index a449b6b2..352045be 100644
--- a/tools/clang/include/clang/AST/Type.h
+++ b/tools/clang/include/clang/AST/Type.h
@@ -1708,7 +1708,7 @@ public:
       const; // HLSL attributed __builtin_LinAlgMatrix with dependent
              // parameters
   // HLSL Change End
-  
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
  • Check this box to apply formatting changes to this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Implement attributed matrix handle in the AST

3 participants