Skip to content

Commit b0b8e45

Browse files
committed
Applied suggestions
1 parent 28c3ff9 commit b0b8e45

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

polygeist/tools/cgeist/Lib/CGExpr.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,18 +2642,18 @@ static Optional<Value> castSubIndexOpIndex(OpBuilder &Builder, Location Loc,
26422642
ValueCategory Pointer,
26432643
ValueRange IdxList, bool IsSigned) {
26442644
if (Pointer.val.getType().isa<MemRefType>()) {
2645-
assert(IdxList.size() == 1 && "SubIndexOP accepts just an index");
2645+
assert(IdxList.size() == 1 && "SubIndexOp accepts just an index");
26462646
return ValueCategory(IdxList.front(), false)
26472647
.IntCast(Builder, Loc, Builder.getIndexType(), IsSigned)
26482648
.val;
26492649
}
26502650
return llvm::None;
26512651
}
26522652

2653-
ValueCategory MLIRScanner::EmitCheckedInBoundsGEP(mlir::Type ElemTy,
2654-
ValueCategory Pointer,
2655-
ValueRange IdxList,
2656-
bool IsSigned, bool) {
2653+
ValueCategory MLIRScanner::EmitCheckedInBoundsPtrOffsetOp(mlir::Type ElemTy,
2654+
ValueCategory Pointer,
2655+
ValueRange IdxList,
2656+
bool IsSigned, bool) {
26572657
assert(mlirclang::isPointerOrMemRefTy(Pointer.val.getType()) &&
26582658
"Expecting pointer or MemRef");
26592659
assert(std::all_of(IdxList.begin(), IdxList.end(),
@@ -2681,20 +2681,17 @@ ValueCategory MLIRScanner::EmitPointerArithmetic(const BinOpInfo &Info) {
26812681
const auto IsSubtraction =
26822682
Opcode == clang::BO_Sub || Opcode == clang::BO_SubAssign;
26832683

2684-
// In a subtraction, the LHS is always the pointer.
2685-
if (!IsSubtraction &&
2686-
!mlirclang::isPointerOrMemRefTy(Pointer.val.getType())) {
2684+
assert((!IsSubtraction ||
2685+
mlirclang::isPointerOrMemRefTy(Pointer.val.getType())) &&
2686+
"The LHS is always a pointer in a subtraction");
2687+
2688+
if (!mlirclang::isPointerOrMemRefTy(Pointer.val.getType())) {
26872689
std::swap(Pointer, Index);
26882690
std::swap(PointerOperand, IndexOperand);
26892691
}
26902692

26912693
assert(Index.val.getType().isa<IntegerType>() && "Expecting integer type");
26922694

2693-
const auto IsSigned =
2694-
IndexOperand->getType()->isSignedIntegerOrEnumerationType();
2695-
2696-
const unsigned Width = Index.val.getType().getIntOrFloatBitWidth();
2697-
26982695
auto PtrTy = Pointer.val.getType();
26992696

27002697
assert(mlirclang::isPointerOrMemRefTy(PtrTy) && "Expecting pointer type");
@@ -2727,6 +2724,9 @@ ValueCategory MLIRScanner::EmitPointerArithmetic(const BinOpInfo &Info) {
27272724
auto &DL = CGM.getDataLayout();
27282725
const unsigned IndexTypeSize = DL.getIndexTypeSizeInBits(
27292726
CGM.getTypes().ConvertType(PointerOperand->getType()));
2727+
const auto IsSigned =
2728+
IndexOperand->getType()->isSignedIntegerOrEnumerationType();
2729+
const unsigned Width = Index.val.getType().getIntOrFloatBitWidth();
27302730
if (Width != IndexTypeSize) {
27312731
// Zero-extend or sign-extend the pointer value according to
27322732
// whether the index is signed or not.
@@ -2765,8 +2765,8 @@ ValueCategory MLIRScanner::EmitPointerArithmetic(const BinOpInfo &Info) {
27652765
return Pointer.GEPOrSubIndex(builder, loc, ElemTy, Index.val);
27662766
}
27672767

2768-
return EmitCheckedInBoundsGEP(ElemTy, Pointer, Index.val, IsSigned,
2769-
IsSubtraction);
2768+
return EmitCheckedInBoundsPtrOffsetOp(ElemTy, Pointer, Index.val, IsSigned,
2769+
IsSubtraction);
27702770
}
27712771

27722772
ValueCategory MLIRScanner::EmitBinAdd(const BinOpInfo &Info) {

polygeist/tools/cgeist/Lib/TypeUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ bool isRecursiveStruct(llvm::Type *T, llvm::Type *Meta,
4848
mlir::IntegerAttr wrapIntegerMemorySpace(unsigned MemorySpace,
4949
mlir::MLIRContext *Ctx);
5050

51+
/// Given a MemRefType or LLVMPointerType, change the element type, keeping the
52+
/// rest of the parameters.
5153
mlir::Type getPtrTyWithNewType(mlir::Type Orig, mlir::Type NewElementType);
5254

5355
mlir::Type getSYCLType(const clang::RecordType *RT,

polygeist/tools/cgeist/Lib/clang-mlir.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,11 @@ class MLIRScanner : public clang::StmtVisitor<MLIRScanner, ValueCategory> {
507507
EmitCompoundAssign(clang::CompoundAssignOperator *E,
508508
ValueCategory (MLIRScanner::*F)(const BinOpInfo &));
509509

510-
ValueCategory EmitCheckedInBoundsGEP(mlir::Type ElemTy, ValueCategory Pointer,
511-
mlir::ValueRange IdxList, bool IsSigned,
512-
bool IsSubtraction);
510+
ValueCategory EmitCheckedInBoundsPtrOffsetOp(mlir::Type ElemTy,
511+
ValueCategory Pointer,
512+
mlir::ValueRange IdxList,
513+
bool IsSigned,
514+
bool IsSubtraction);
513515
ValueCategory EmitPointerArithmetic(const BinOpInfo &Info);
514516

515517
BinOpInfo EmitBinOps(clang::BinaryOperator *E,

0 commit comments

Comments
 (0)