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