Skip to content

Commit 6b5693e

Browse files
mmhaandykaylorxlauko
authored
Apply suggestions from code review
Co-authored-by: Andy Kaylor <[email protected]> Co-authored-by: Henrich Lauko <[email protected]>
1 parent 2a78522 commit 6b5693e

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
360360
cgm.errorNYI(e->getSourceRange(), "dynamic-length array expression");
361361
}
362362

363-
auto arrayTy = mlir::dyn_cast<cir::ArrayType>(arrayBase.getElementType());
364-
assert(arrayTy && "expected array type");
363+
auto arrayTy = mlir::cast<cir::ArrayType>(arrayBase.getElementType());
365364
mlir::Type elementType = arrayTy.getElementType();
366365
cir::PointerType ptrToElmType = builder.getPointerTo(elementType);
367366

@@ -400,7 +399,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
400399
}
401400

402401
// Emit the constructor call that will execute for every array element.
403-
auto arrayOp = builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
402+
mlir::Value arrayOp = builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
404403
builder.create<cir::ArrayCtor>(
405404
*currSrcLoc, arrayOp, [&](mlir::OpBuilder &b, mlir::Location loc) {
406405
auto arg = b.getInsertionBlock()->addArgument(ptrToElmType, loc);

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ CIRGenFunction::emitArrayLength(const clang::ArrayType *origArrayType,
845845
}
846846

847847
baseType = eltType;
848-
auto numElements = builder.getConstInt(*currSrcLoc, SizeTy, countFromCLAs);
848+
cir::ConstantOp numElements = builder.getConstInt(*currSrcLoc, SizeTy, countFromCLAs);
849849

850850
return numElements;
851851
}

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,27 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
2424
void runOnOperation() override;
2525

2626
void runOnOp(Operation *op);
27-
void lowerArrayCtor(ArrayCtor op);
27+
void lowerArrayCtor(cir::ArrayCtor op);
2828
};
2929

3030
} // namespace
3131

32-
void LoweringPreparePass::runOnOp(Operation *op) {
32+
void LoweringPreparePass::runOnOp(mlir::Operation *op) {
3333
if (auto arrayCtor = dyn_cast<ArrayCtor>(op)) {
3434
lowerArrayCtor(arrayCtor);
3535
}
3636
}
3737

38-
static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder,
38+
static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
3939
mlir::Operation *op, mlir::Type eltTy,
4040
mlir::Value arrayAddr,
4141
uint64_t arrayLen) {
4242
// Generate loop to call into ctor/dtor for every element.
43-
Location loc = op->getLoc();
43+
mlir::Location loc = op->getLoc();
4444

4545
// TODO: instead of fixed integer size, create alias for PtrDiffTy and unify
4646
// with CIRGen stuff.
47-
auto ptrDiffTy =
48-
cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false);
49-
auto numArrayElementsConst = builder.create<cir::ConstantOp>(
50-
loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen));
47+
cir::ConstantOp numArrayElementsConst = builder.getUnsignedInt(loc, 64, arrayLen);
5148

5249
auto begin = builder.create<cir::CastOp>(
5350
loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr);
@@ -73,8 +70,8 @@ static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder,
7370
[&](mlir::OpBuilder &b, mlir::Location loc) {
7471
auto currentElement = b.create<cir::LoadOp>(loc, eltTy, tmpAddr);
7572

76-
CallOp ctorCall;
77-
op->walk([&](CallOp c) { ctorCall = c; });
73+
cir::CallOp ctorCall;
74+
op->walk([&](cir::CallOp c) { ctorCall = c; });
7875
assert(ctorCall && "expected ctor call");
7976

8077
auto one = builder.create<cir::ConstantOp>(
@@ -94,23 +91,23 @@ static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder,
9491
op->erase();
9592
}
9693

97-
void LoweringPreparePass::lowerArrayCtor(ArrayCtor op) {
98-
CIRBaseBuilderTy builder(getContext());
94+
void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) {
95+
cir::CIRBaseBuilderTy builder(getContext());
9996
builder.setInsertionPointAfter(op.getOperation());
10097

101-
Type eltTy = op->getRegion(0).getArgument(0).getType();
98+
mlir::Type eltTy = op->getRegion(0).getArgument(0).getType();
10299
auto arrayLen =
103100
mlir::cast<cir::ArrayType>(op.getAddr().getType().getPointee()).getSize();
104101
lowerArrayDtorCtorIntoLoop(builder, op, eltTy, op.getAddr(), arrayLen);
105102
}
106103

107104
void LoweringPreparePass::runOnOperation() {
108-
Operation *op = getOperation();
105+
mlir::Operation *op = getOperation();
109106

110-
llvm::SmallVector<Operation *> opsToTransform;
107+
llvm::SmallVector<mlir::Operation *> opsToTransform;
111108

112-
op->walk([&](Operation *op) {
113-
if (isa<ArrayCtor>(op)) {
109+
op->walk([&](mlir::Operation *op) {
110+
if (mlir::isa<cir::ArrayCtor>(op)) {
114111
opsToTransform.push_back(op);
115112
}
116113
});

0 commit comments

Comments
 (0)