================
@@ -4476,6 +4545,59 @@ void ExtVectorElementExpr::getEncodedElementAccess(
}
}
+void MatrixElementExpr::getEncodedElementAccess(
+ SmallVectorImpl<uint32_t> &Elts) const {
+ StringRef Comp = Accessor->getName();
+ assert(!Comp.empty() && Comp[0] == '_' && "invalid matrix accessor");
+
+ const ConstantMatrixType *MT =
+ getBase()->getType()->getAs<ConstantMatrixType>();
+ assert(MT && "MatrixElementExpr base must be a matrix type");
+
+ unsigned Rows = MT->getNumRows();
+ unsigned Cols = MT->getNumColumns();
+
+ // Zero-indexed: _mRC (4 chars per component: '_', 'm', row, col)
+ // One-indexed: _RC (3 chars per component: '_', row, col)
+ bool IsZeroIndexed = false;
+ unsigned ChunkLen = 0;
+
+ if (Comp.size() >= 2 && Comp[0] == '_' && Comp[1] == 'm') {
+ IsZeroIndexed = true;
+ ChunkLen = 4;
+ } else {
+ IsZeroIndexed = false;
+ ChunkLen = 3;
+ }
+
+ assert(ChunkLen != 0 && "unrecognized matrix swizzle format");
+ assert(Comp.size() % ChunkLen == 0 &&
+ "matrix swizzle accessor has invalid length");
+
+ for (unsigned i = 0, e = Comp.size(); i < e; i += ChunkLen) {
+ unsigned Row = 0, Col = 0;
+
+ if (IsZeroIndexed) {
+ // Pattern: _mRC
+ assert(Comp[i] == '_' && Comp[i + 1] == 'm' &&
+ "invalid zero-indexed matrix swizzle component");
+ Row = static_cast<unsigned>(Comp[i + 2] - '0'); // 0..Rows-1
+ Col = static_cast<unsigned>(Comp[i + 3] - '0'); // 0..Cols-1
+ } else {
+ // Pattern: _RC
+ assert(Comp[i] == '_' && "invalid one-indexed matrix swizzle component");
+ Row = static_cast<unsigned>(Comp[i + 1] - '1'); // 1..Rows -> 0..Rows-1
----------------
farzonl wrote:
No not really. Unless I want to introduce a terinary to represent the digit
subtraction. Which is still having a conditional. or always subtracting by
zero char and then having an inverse to IsZeroIndexed subracting the row and
col to convert one indexed rows to zero index ones. (ie the zero index pattern
would be - 0 and the one index would be -1 ` Row = static_cast<unsigned>(Comp[I
+ IsZeroIndexed + 1] - '0') - static_cast<unsigned>(!IsZeroIndexed);`
https://github.com/llvm/llvm-project/pull/171225
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits