@@ -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,
@@ -2465,12 +2468,11 @@ Address CIRGenFunction::CreateMemTemp(QualType Ty, CharUnits Align,
2465
2468
2466
2469
// / This creates a alloca and inserts it into the entry block of the
2467
2470
// / current region.
2468
- Address CIRGenFunction::CreateTempAllocaWithoutCast (mlir::Type Ty,
2469
- CharUnits Align,
2470
- mlir::Location Loc,
2471
- const Twine &Name,
2472
- mlir::Value ArraySize) {
2473
- auto Alloca = CreateTempAlloca (Ty, Loc, Name, ArraySize);
2471
+ Address CIRGenFunction::CreateTempAllocaWithoutCast (
2472
+ mlir::Type Ty, CharUnits Align, mlir::Location Loc, const Twine &Name,
2473
+ mlir::Value ArraySize, mlir::OpBuilder::InsertPoint ip) {
2474
+ auto Alloca = ip.isSet () ? CreateTempAlloca (Ty, Loc, Name, ip, ArraySize)
2475
+ : CreateTempAlloca (Ty, Loc, Name, ArraySize);
2474
2476
Alloca.setAlignmentAttr (CGM.getSize (Align));
2475
2477
return Address (Alloca, Ty, Align);
2476
2478
}
@@ -2480,8 +2482,10 @@ Address CIRGenFunction::CreateTempAllocaWithoutCast(mlir::Type Ty,
2480
2482
Address CIRGenFunction::CreateTempAlloca (mlir::Type Ty, CharUnits Align,
2481
2483
mlir::Location Loc, const Twine &Name,
2482
2484
mlir::Value ArraySize,
2483
- Address *AllocaAddr) {
2484
- auto Alloca = CreateTempAllocaWithoutCast (Ty, Align, Loc, Name, ArraySize);
2485
+ Address *AllocaAddr,
2486
+ mlir::OpBuilder::InsertPoint ip) {
2487
+ auto Alloca =
2488
+ CreateTempAllocaWithoutCast (Ty, Align, Loc, Name, ArraySize, ip);
2485
2489
if (AllocaAddr)
2486
2490
*AllocaAddr = Alloca;
2487
2491
mlir::Value V = Alloca.getPointer ();
@@ -2500,10 +2504,19 @@ mlir::cir::AllocaOp
2500
2504
CIRGenFunction::CreateTempAlloca (mlir::Type Ty, mlir::Location Loc,
2501
2505
const Twine &Name, mlir::Value ArraySize,
2502
2506
bool insertIntoFnEntryBlock) {
2503
- if (ArraySize)
2504
- assert (0 && " NYI" );
2507
+ return cast<mlir::cir::AllocaOp>(buildAlloca (Name.str (), Ty, Loc, CharUnits (),
2508
+ insertIntoFnEntryBlock,
2509
+ ArraySize)
2510
+ .getDefiningOp ());
2511
+ }
2512
+
2513
+ // / This creates an alloca and inserts it into the provided insertion point
2514
+ mlir::cir::AllocaOp CIRGenFunction::CreateTempAlloca (
2515
+ mlir::Type Ty, mlir::Location Loc, const Twine &Name,
2516
+ mlir::OpBuilder::InsertPoint ip, mlir::Value ArraySize) {
2517
+ assert (ip.isSet () && " Insertion point is not set" );
2505
2518
return cast<mlir::cir::AllocaOp>(
2506
- buildAlloca (Name.str (), Ty, Loc, CharUnits (), insertIntoFnEntryBlock )
2519
+ buildAlloca (Name.str (), Ty, Loc, CharUnits (), ip, ArraySize )
2507
2520
.getDefiningOp ());
2508
2521
}
2509
2522
0 commit comments