clang 23.0.0git
MatrixUtils.h
Go to the documentation of this file.
1//===- MatrixUtils.h - Matrix AST utilities -------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines AST-level helper utilities for matrix types.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_MATRIXUTILS_H
15#define LLVM_CLANG_AST_MATRIXUTILS_H
16
17#include "clang/AST/Type.h"
20
21namespace clang {
22/// Returns true if matrices of \p T should be laid out in row-major order.
23///
24/// In HLSL mode, an `HLSLRowMajor` / `HLSLColumnMajor` AttributedType anywhere
25/// in the sugar chain of \p T (imprinted by Sema when a source decl carries
26/// `[[hlsl::row_major]]` / `[[hlsl::column_major]]`) takes precedence over the
27/// `-fmatrix-memory-layout=` default carried in \p LangOpts. Otherwise the
28/// LangOptions default is used.
29inline bool isMatrixRowMajor(const LangOptions &LangOpts, QualType T) {
30 if (LangOpts.HLSL && !T.isNull()) {
31 QualType Cur = T;
32 while (const auto *AT = Cur->getAs<AttributedType>()) {
33 switch (AT->getAttrKind()) {
34 case attr::HLSLRowMajor:
35 return true;
36 case attr::HLSLColumnMajor:
37 return false;
38 default:
39 break;
40 }
41 Cur = AT->getModifiedType();
42 }
43 }
44 return LangOpts.getDefaultMatrixMemoryLayout() ==
46}
47} // namespace clang
48
49#endif // LLVM_CLANG_AST_MATRIXUTILS_H
Defines the clang::attr::Kind enum.
Defines the clang::LangOptions interface.
C Language Family Type Representation.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Definition TypeBase.h:937
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9275
The JSON file list parser is used to communicate input to InstallAPI.
bool isMatrixRowMajor(const LangOptions &LangOpts, QualType T)
Returns true if matrices of T should be laid out in row-major order.
Definition MatrixUtils.h:29