@@ -2288,17 +2288,19 @@ mlir::Value CIRGenFunction::buildOpOnBoolExpr(const Expr *cond,
2288
2288
2289
2289
mlir::Value CIRGenFunction::buildAlloca (StringRef name, mlir::Type ty,
2290
2290
mlir::Location loc, CharUnits alignment,
2291
- bool insertIntoFnEntryBlock) {
2291
+ bool insertIntoFnEntryBlock,
2292
+ mlir::Value arraySize) {
2292
2293
mlir::Block *entryBlock = insertIntoFnEntryBlock
2293
2294
? getCurFunctionEntryBlock ()
2294
2295
: currLexScope->getEntryBlock ();
2295
2296
return buildAlloca (name, ty, loc, alignment,
2296
- builder.getBestAllocaInsertPoint (entryBlock));
2297
+ builder.getBestAllocaInsertPoint (entryBlock), arraySize );
2297
2298
}
2298
2299
2299
2300
mlir::Value CIRGenFunction::buildAlloca (StringRef name, mlir::Type ty,
2300
2301
mlir::Location loc, CharUnits alignment,
2301
- mlir::OpBuilder::InsertPoint ip) {
2302
+ mlir::OpBuilder::InsertPoint ip,
2303
+ mlir::Value arraySize) {
2302
2304
auto localVarPtrTy = mlir::cir::PointerType::get (builder.getContext (), ty);
2303
2305
auto alignIntAttr = CGM.getSize (alignment);
2304
2306
@@ -2308,7 +2310,7 @@ mlir::Value CIRGenFunction::buildAlloca(StringRef name, mlir::Type ty,
2308
2310
builder.restoreInsertionPoint (ip);
2309
2311
addr = builder.create <mlir::cir::AllocaOp>(loc, /* addr type*/ localVarPtrTy,
2310
2312
/* var type*/ ty, name,
2311
- alignIntAttr);
2313
+ alignIntAttr, arraySize );
2312
2314
if (currVarDecl) {
2313
2315
auto alloca = cast<mlir::cir::AllocaOp>(addr.getDefiningOp ());
2314
2316
alloca .setAstAttr (ASTVarDeclAttr::get (builder.getContext (), currVarDecl));
@@ -2319,9 +2321,10 @@ mlir::Value CIRGenFunction::buildAlloca(StringRef name, mlir::Type ty,
2319
2321
2320
2322
mlir::Value CIRGenFunction::buildAlloca (StringRef name, QualType ty,
2321
2323
mlir::Location loc, CharUnits alignment,
2322
- bool insertIntoFnEntryBlock) {
2324
+ bool insertIntoFnEntryBlock,
2325
+ mlir::Value arraySize) {
2323
2326
return buildAlloca (name, getCIRType (ty), loc, alignment,
2324
- insertIntoFnEntryBlock);
2327
+ insertIntoFnEntryBlock, arraySize );
2325
2328
}
2326
2329
2327
2330
mlir::Value CIRGenFunction::buildLoadOfScalar (LValue lvalue,
@@ -2469,12 +2472,11 @@ Address CIRGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
2469
2472
2470
2473
// / This creates a alloca and inserts it into the entry block of the
2471
2474
// / current region.
2472
- Address CIRGenFunction::CreateTempAllocaWithoutCast (mlir::Type Ty,
2473
- CharUnits Align,
2474
- mlir::Location Loc,
2475
- const Twine &Name,
2476
- mlir::Value ArraySize) {
2477
- auto Alloca = CreateTempAlloca (Ty, Loc, Name, ArraySize);
2475
+ Address CIRGenFunction::CreateTempAllocaWithoutCast (
2476
+ mlir::Type Ty, CharUnits Align, mlir::Location Loc, const Twine &Name,
2477
+ mlir::Value ArraySize, mlir::OpBuilder::InsertPoint ip) {
2478
+ auto Alloca = ip.isSet () ? CreateTempAlloca (Ty, Loc, Name, ip, ArraySize)
2479
+ : CreateTempAlloca (Ty, Loc, Name, ArraySize);
2478
2480
Alloca.setAlignmentAttr (CGM.getSize (Align));
2479
2481
return Address (Alloca, Ty, Align);
2480
2482
}
@@ -2484,8 +2486,10 @@ Address CIRGenFunction::CreateTempAllocaWithoutCast(mlir::Type Ty,
2484
2486
Address CIRGenFunction::CreateTempAlloca (mlir::Type Ty, CharUnits Align,
2485
2487
mlir::Location Loc, const Twine &Name,
2486
2488
mlir::Value ArraySize,
2487
- Address *AllocaAddr) {
2488
- auto Alloca = CreateTempAllocaWithoutCast (Ty, Align, Loc, Name, ArraySize);
2489
+ Address *AllocaAddr,
2490
+ mlir::OpBuilder::InsertPoint ip) {
2491
+ auto Alloca =
2492
+ CreateTempAllocaWithoutCast (Ty, Align, Loc, Name, ArraySize, ip);
2489
2493
if (AllocaAddr)
2490
2494
*AllocaAddr = Alloca;
2491
2495
mlir::Value V = Alloca.getPointer ();
@@ -2504,10 +2508,19 @@ mlir::cir::AllocaOp
2504
2508
CIRGenFunction::CreateTempAlloca (mlir::Type Ty, mlir::Location Loc,
2505
2509
const Twine &Name, mlir::Value ArraySize,
2506
2510
bool insertIntoFnEntryBlock) {
2507
- if (ArraySize)
2508
- assert (0 && " NYI" );
2511
+ return cast<mlir::cir::AllocaOp>(buildAlloca (Name.str (), Ty, Loc, CharUnits (),
2512
+ insertIntoFnEntryBlock,
2513
+ ArraySize)
2514
+ .getDefiningOp ());
2515
+ }
2516
+
2517
+ // / This creates an alloca and inserts it into the provided insertion point
2518
+ mlir::cir::AllocaOp CIRGenFunction::CreateTempAlloca (
2519
+ mlir::Type Ty, mlir::Location Loc, const Twine &Name,
2520
+ mlir::OpBuilder::InsertPoint ip, mlir::Value ArraySize) {
2521
+ assert (ip.isSet () && " Insertion point is not set" );
2509
2522
return cast<mlir::cir::AllocaOp>(
2510
- buildAlloca (Name.str (), Ty, Loc, CharUnits (), insertIntoFnEntryBlock )
2523
+ buildAlloca (Name.str (), Ty, Loc, CharUnits (), ip, ArraySize )
2511
2524
.getDefiningOp ());
2512
2525
}
2513
2526
0 commit comments