Skip to content

Commit e05725e

Browse files
committed
!fixup move to CGF::EmitMatrixIndexExpr
1 parent 4efcce8 commit e05725e

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,22 +4392,23 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
43924392
return LV;
43934393
}
43944394

4395+
llvm::Value *CodeGenFunction::EmitMatrixIndexExpr(const Expr *E) {
4396+
llvm::Value *Idx = EmitScalarExpr(E);
4397+
if (Idx->getType() == IntPtrTy)
4398+
return Idx;
4399+
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
4400+
return Builder.CreateIntCast(Idx, IntPtrTy, IsSigned);
4401+
}
4402+
43954403
LValue CodeGenFunction::EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E) {
43964404
assert(
43974405
!E->isIncomplete() &&
43984406
"incomplete matrix subscript expressions should be rejected during Sema");
43994407
LValue Base = EmitLValue(E->getBase());
44004408

4401-
// Extend or truncate the index type to 32 or 64-bits.
4402-
auto EmitIndex = [this](const Expr *E) {
4403-
llvm::Value *Idx = EmitScalarExpr(E);
4404-
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
4405-
if (Idx->getType() != IntPtrTy)
4406-
Idx = Builder.CreateIntCast(Idx, IntPtrTy, IsSigned);
4407-
return Idx;
4408-
};
4409-
llvm::Value *RowIdx = EmitIndex(E->getRowIdx());
4410-
llvm::Value *ColIdx = EmitIndex(E->getColumnIdx());
4409+
// Extend or truncate the index type to 32 or 64-bits if needed.
4410+
llvm::Value *RowIdx = EmitMatrixIndexExpr(E->getRowIdx());
4411+
llvm::Value *ColIdx = EmitMatrixIndexExpr(E->getColumnIdx());
44114412

44124413
llvm::Value *NumRows = Builder.getIntN(
44134414
RowIdx->getType()->getScalarSizeInBits(),

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,15 +1995,8 @@ Value *ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
19951995

19961996
// Handle the vector case. The base must be a vector, the index must be an
19971997
// integer value.
1998-
auto VisitIndex = [this](Expr *E) {
1999-
llvm::Value *Idx = Visit(E);
2000-
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
2001-
if (Idx->getType() != CGF.IntPtrTy)
2002-
Idx = Builder.CreateIntCast(Idx, CGF.IntPtrTy, IsSigned);
2003-
return Idx;
2004-
};
2005-
Value *RowIdx = VisitIndex(E->getRowIdx());
2006-
Value *ColumnIdx = VisitIndex(E->getColumnIdx());
1998+
Value *RowIdx = CGF.EmitMatrixIndexExpr(E->getRowIdx());
1999+
Value *ColumnIdx = CGF.EmitMatrixIndexExpr(E->getColumnIdx());
20072000

20082001
const auto *MatrixTy = E->getBase()->getType()->castAs<ConstantMatrixType>();
20092002
unsigned NumRows = MatrixTy->getNumRows();

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,7 @@ class CodeGenFunction : public CodeGenTypeCache {
42804280
LValue EmitUnaryOpLValue(const UnaryOperator *E);
42814281
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
42824282
bool Accessed = false);
4283+
llvm::Value *EmitMatrixIndexExpr(const Expr *E);
42834284
LValue EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E);
42844285
LValue EmitArraySectionExpr(const ArraySectionExpr *E,
42854286
bool IsLowerBound = true);

0 commit comments

Comments
 (0)