@@ -25,6 +25,14 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
25
25
26
26
void runOnOp (Operation *op);
27
27
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; }
28
36
};
29
37
30
38
} // namespace
@@ -36,6 +44,7 @@ void LoweringPreparePass::runOnOp(mlir::Operation *op) {
36
44
}
37
45
38
46
static void lowerArrayDtorCtorIntoLoop (cir::CIRBaseBuilderTy &builder,
47
+ clang::ASTContext *astCtx,
39
48
mlir::Operation *op, mlir::Type eltTy,
40
49
mlir::Value arrayAddr,
41
50
uint64_t arrayLen) {
@@ -44,7 +53,11 @@ static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
44
53
45
54
// TODO: instead of fixed integer size, create alias for PtrDiffTy and unify
46
55
// 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 );
48
61
49
62
auto begin = builder.create <cir::CastOp>(
50
63
loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr);
@@ -98,7 +111,8 @@ void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) {
98
111
mlir::Type eltTy = op->getRegion (0 ).getArgument (0 ).getType ();
99
112
auto arrayLen =
100
113
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);
102
116
}
103
117
104
118
void LoweringPreparePass::runOnOperation () {
@@ -119,3 +133,10 @@ void LoweringPreparePass::runOnOperation() {
119
133
std::unique_ptr<Pass> mlir::createLoweringPreparePass () {
120
134
return std::make_unique<LoweringPreparePass>();
121
135
}
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
+ }
0 commit comments