================
@@ -3118,14 +3118,15 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
SmallVector<int> Mask;
unsigned NumCols = MatTy->getNumColumns();
unsigned NumRows = MatTy->getNumRows();
- unsigned ColOffset = NumCols;
- if (auto *SrcMatTy = E->getType()->getAs<ConstantMatrixType>())
- ColOffset = SrcMatTy->getNumColumns();
- for (unsigned R = 0; R < NumRows; R++) {
- for (unsigned C = 0; C < NumCols; C++) {
- unsigned I = R * ColOffset + C;
- Mask.push_back(I);
- }
+ auto *SrcMatTy = E->getType()->getAs<ConstantMatrixType>();
+ assert(SrcMatTy && "Source type must be a matrix type.");
+ assert(NumRows <= SrcMatTy->getNumRows());
+ assert(NumCols <= SrcMatTy->getNumColumns());
+ bool IsRowMajor = CGF.getLangOpts().getDefaultMatrixMemoryLayout() ==
+ LangOptions::MatrixMemoryLayout::MatrixRowMajor;
+ for (unsigned I = 0, E = MatTy->getNumElementsFlattened(); I < E; I++) {
+ auto [Row, Col] = MatTy->getRowAndColumn(I, IsRowMajor);
+ Mask.push_back(SrcMatTy->getFlattenedIndex(Row, Col, IsRowMajor));
----------------
Icohedron wrote:
If we support `row_major` and `column_major` keywords in the future, then the
`IsRowMajor` check would be two separate boolean checks: one for MatTy and one
for SrcMatTy
because the matrices' memory layouts could differ.
https://github.com/llvm/llvm-project/pull/184280
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits