Skip to content

Commit 7a33bb6

Browse files
committed
Fix compilation errors after applying suggestions
1 parent 6b5693e commit 7a33bb6

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
7575
return getConstant(loc, cir::IntAttr::get(ty, value));
7676
}
7777

78+
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
79+
unsigned numBits) {
80+
auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/false);
81+
return getConstAPInt(loc, type, llvm::APInt(numBits, val));
82+
}
83+
7884
// Creates constant null value for integral type ty.
7985
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc) {
8086
return getConstant(loc, getZeroInitAttr(ty));

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std::unique_ptr<Pass> createCIRFlattenCFGPass();
2525
std::unique_ptr<Pass> createCIRSimplifyPass();
2626
std::unique_ptr<Pass> createHoistAllocasPass();
2727
std::unique_ptr<Pass> createLoweringPreparePass();
28+
std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
2829

2930
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
3031

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
2525

2626
void runOnOp(Operation *op);
2727
void lowerArrayCtor(cir::ArrayCtor op);
28+
29+
///
30+
/// AST related
31+
/// -----------
32+
33+
clang::ASTContext *astCtx;
34+
35+
void setASTContext(clang::ASTContext *c) { astCtx = c; }
2836
};
2937

3038
} // namespace
@@ -36,6 +44,7 @@ void LoweringPreparePass::runOnOp(mlir::Operation *op) {
3644
}
3745

3846
static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
47+
clang::ASTContext *astCtx,
3948
mlir::Operation *op, mlir::Type eltTy,
4049
mlir::Value arrayAddr,
4150
uint64_t arrayLen) {
@@ -44,7 +53,11 @@ static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
4453

4554
// TODO: instead of fixed integer size, create alias for PtrDiffTy and unify
4655
// with CIRGen stuff.
47-
cir::ConstantOp numArrayElementsConst = builder.getUnsignedInt(loc, 64, arrayLen);
56+
const unsigned sizeTypeSize =
57+
astCtx->getTypeSize(astCtx->getSignedSizeType());
58+
auto ptrDiffTy =
59+
cir::IntType::get(builder.getContext(), sizeTypeSize, /*isSigned=*/false);
60+
mlir::Value numArrayElementsConst = builder.getUnsignedInt(loc, arrayLen, 64);
4861

4962
auto begin = builder.create<cir::CastOp>(
5063
loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr);
@@ -98,7 +111,8 @@ void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) {
98111
mlir::Type eltTy = op->getRegion(0).getArgument(0).getType();
99112
auto arrayLen =
100113
mlir::cast<cir::ArrayType>(op.getAddr().getType().getPointee()).getSize();
101-
lowerArrayDtorCtorIntoLoop(builder, op, eltTy, op.getAddr(), arrayLen);
114+
lowerArrayDtorCtorIntoLoop(builder, astCtx, op, eltTy, op.getAddr(),
115+
arrayLen);
102116
}
103117

104118
void LoweringPreparePass::runOnOperation() {
@@ -119,3 +133,10 @@ void LoweringPreparePass::runOnOperation() {
119133
std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
120134
return std::make_unique<LoweringPreparePass>();
121135
}
136+
137+
std::unique_ptr<Pass>
138+
mlir::createLoweringPreparePass(clang::ASTContext *astCtx) {
139+
auto pass = std::make_unique<LoweringPreparePass>();
140+
pass->setASTContext(astCtx);
141+
return std::move(pass);
142+
}

clang/lib/CIR/Lowering/CIRPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
3131
if (enableCIRSimplify)
3232
pm.addPass(mlir::createCIRSimplifyPass());
3333

34-
pm.addPass(mlir::createLoweringPreparePass());
34+
pm.addPass(mlir::createLoweringPreparePass(&astContext));
3535

3636
pm.enableVerifier(enableVerifier);
3737
(void)mlir::applyPassManagerCLOptions(pm);

0 commit comments

Comments
 (0)