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