@@ -292,9 +292,9 @@ bool LoopRestructure::removeIfFromRegion(DominanceInfo &domInfo, Region ®ion,
292
292
if (Succs[j] == pseudoExit && Succs[1 - j] == Preds[1 - i]) {
293
293
OpBuilder builder (Preds[i]->getTerminator ());
294
294
auto condBr = cast<cf::CondBranchOp>(Preds[i]->getTerminator ());
295
- auto ifOp = builder.create <scf::IfOp>(
296
- builder. getUnknownLoc (), condTys, condBr.getCondition (),
297
- /* hasElse*/ true );
295
+ auto ifOp = builder.create <scf::IfOp>(condBr. getLoc (), condTys,
296
+ condBr.getCondition (),
297
+ /* hasElse*/ true );
298
298
Succs[j] = new Block ();
299
299
if (j == 0 ) {
300
300
ifOp.getElseRegion ().getBlocks ().splice (
@@ -311,7 +311,7 @@ bool LoopRestructure::removeIfFromRegion(DominanceInfo &domInfo, Region ®ion,
311
311
assert (condTys.size () == condBr.getTrueOperands ().size ());
312
312
OpBuilder tbuilder (&ifOp.getThenRegion ().front (),
313
313
ifOp.getThenRegion ().front ().begin ());
314
- tbuilder.create <scf::YieldOp>(tbuilder. getUnknownLoc (), emptyTys,
314
+ tbuilder.create <scf::YieldOp>(condBr. getLoc (), emptyTys,
315
315
condBr.getTrueOperands ());
316
316
} else {
317
317
if (!ifOp.getThenRegion ().getBlocks ().empty ()) {
@@ -331,17 +331,16 @@ bool LoopRestructure::removeIfFromRegion(DominanceInfo &domInfo, Region ®ion,
331
331
OpBuilder tbuilder (&ifOp.getElseRegion ().front (),
332
332
ifOp.getElseRegion ().front ().begin ());
333
333
assert (condTys.size () == condBr.getFalseOperands ().size ());
334
- tbuilder.create <scf::YieldOp>(tbuilder. getUnknownLoc (), emptyTys,
334
+ tbuilder.create <scf::YieldOp>(condBr. getLoc (), emptyTys,
335
335
condBr.getFalseOperands ());
336
336
}
337
337
auto *oldTerm = Succs[1 - j]->getTerminator ();
338
338
OpBuilder tbuilder (Succs[1 - j], Succs[1 - j]->end ());
339
- tbuilder.create <scf::YieldOp>(tbuilder. getUnknownLoc (), emptyTys,
339
+ tbuilder.create <scf::YieldOp>(condBr. getLoc (), emptyTys,
340
340
oldTerm->getOperands ());
341
341
oldTerm->erase ();
342
342
343
- builder.create <scf::YieldOp>(builder.getUnknownLoc (),
344
- ifOp->getResults ());
343
+ builder.create <scf::YieldOp>(condBr.getLoc (), ifOp->getResults ());
345
344
condBr->erase ();
346
345
347
346
pseudoExit->erase ();
@@ -385,9 +384,10 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
385
384
386
385
// Copy the arguments across
387
386
SmallVector<Type, 4 > headerArgumentTypes (header->getArgumentTypes ());
388
- SmallVector<Location> locs (headerArgumentTypes.size (),
389
- builder.getUnknownLoc ());
390
- wrapper->addArguments (headerArgumentTypes, locs);
387
+ SmallVector<Location, 4 > headerArgumentLocs;
388
+ for (auto a : header->getArguments ())
389
+ headerArgumentLocs.push_back (a.getLoc ());
390
+ wrapper->addArguments (headerArgumentTypes, headerArgumentLocs);
391
391
392
392
SmallVector<Value> valsCallingLoop;
393
393
for (auto a : wrapper->getArguments ())
@@ -405,20 +405,28 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
405
405
})) {
406
406
preservedVals.emplace_back (V, headerArgumentTypes.size ());
407
407
headerArgumentTypes.push_back (V.getType ());
408
- valsCallingLoop.push_back (builder.create <mlir::LLVM::UndefOp>(
409
- builder.getUnknownLoc (), V.getType ()));
408
+ headerArgumentLocs.push_back (V.getLoc ());
409
+ valsCallingLoop.push_back (
410
+ builder.create <mlir::LLVM::UndefOp>(V.getLoc (), V.getType ()));
410
411
header->addArgument (V.getType (), V.getLoc ());
411
412
}
412
413
}
413
414
}
414
415
}
415
416
416
417
SmallVector<Type, 4 > combinedTypes = headerArgumentTypes;
418
+ SmallVector<Location, 4 > combinedLocs = headerArgumentLocs;
419
+
417
420
SmallVector<Type, 4 > returns (target->getArgumentTypes ());
421
+ SmallVector<Location, 4 > returnLocs;
422
+ for (auto a : target->getArguments ())
423
+ returnLocs.push_back (a.getLoc ());
418
424
combinedTypes.append (returns);
425
+ combinedLocs.append (returnLocs);
426
+ assert (combinedTypes.size () == combinedLocs.size ());
419
427
420
428
auto loop = builder.create <mlir::scf::WhileOp>(
421
- builder. getUnknownLoc (), combinedTypes, valsCallingLoop);
429
+ header-> front (). getLoc (), combinedTypes, valsCallingLoop);
422
430
{
423
431
SmallVector<Value, 4 > RetVals;
424
432
for (size_t i = 0 ; i < returns.size (); ++i) {
@@ -449,15 +457,18 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
449
457
SmallVector<Type, 4 > tys = {builder.getI1Type ()};
450
458
for (auto t : combinedTypes)
451
459
tys.push_back (t);
452
- auto exec =
453
- builder.create <scf::ExecuteRegionOp>(builder.getUnknownLoc (), tys);
460
+ SmallVector<Location, 4 > locs = {region.getLoc ()};
461
+ for (auto t : combinedLocs)
462
+ locs.push_back (t);
463
+ assert (tys.size () == locs.size ());
464
+ auto exec = builder.create <scf::ExecuteRegionOp>(region.getLoc (), tys);
454
465
455
466
{
456
467
SmallVector<Value> yields;
457
468
for (auto a : exec.getResults ())
458
469
yields.push_back (a);
459
470
yields.erase (yields.begin ());
460
- builder.create <scf::ConditionOp>(builder. getUnknownLoc (),
471
+ builder.create <scf::ConditionOp>(header-> getTerminator ()-> getLoc (),
461
472
exec.getResult (0 ), yields);
462
473
}
463
474
@@ -477,10 +488,10 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
477
488
Block *pseudoExit = new Block ();
478
489
{
479
490
insertRegion.push_back (pseudoExit);
480
- SmallVector<Location> locs (tys.size (), builder.getUnknownLoc ());
481
491
pseudoExit->addArguments (tys, locs);
482
492
OpBuilder builder (pseudoExit, pseudoExit->begin ());
483
493
tys.clear ();
494
+ locs.clear ();
484
495
builder.create <scf::YieldOp>(builder.getUnknownLoc (), tys,
485
496
pseudoExit->getArguments ());
486
497
}
@@ -493,8 +504,8 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
493
504
if (successor == target) {
494
505
495
506
OpBuilder builder (terminator);
496
- auto vfalse = builder. create <arith::ConstantIntOp>(
497
- builder.getUnknownLoc (), false , 1 );
507
+ auto vfalse =
508
+ builder.create <arith::ConstantIntOp>(region. getLoc (), false , 1 );
498
509
499
510
SmallVector<Value> args = {vfalse};
500
511
for (auto arg : header->getArguments ())
@@ -547,17 +558,17 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
547
558
if (successor == header) {
548
559
549
560
OpBuilder builder (terminator);
550
- auto vtrue = builder. create <arith::ConstantIntOp>(
551
- builder.getUnknownLoc (), true , 1 );
561
+ auto vtrue =
562
+ builder.create <arith::ConstantIntOp>(region. getLoc (), true , 1 );
552
563
553
564
if (auto op = dyn_cast<cf::BranchOp>(terminator)) {
554
565
SmallVector<Value> args (op.getOperands ());
555
566
args.insert (args.begin (), vtrue);
556
567
for (auto p : preservedVals)
557
568
args.push_back (p.first );
558
- for (auto ty : returns) {
569
+ for (auto tup : llvm::zip ( returns, returnLocs) ) {
559
570
args.push_back (builder.create <mlir::LLVM::UndefOp>(
560
- builder. getUnknownLoc ( ), ty ));
571
+ std::get< 1 >(tup ), std::get< 0 >(tup) ));
561
572
}
562
573
terminator =
563
574
builder.create <cf::BranchOp>(op.getLoc (), pseudoExit, args);
@@ -571,18 +582,18 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
571
582
trueargs.insert (trueargs.begin (), vtrue);
572
583
for (auto pair : preservedVals)
573
584
trueargs.push_back (pair.first );
574
- for (auto ty : returns) {
585
+ for (auto tup : llvm::zip ( returns, returnLocs) ) {
575
586
trueargs.push_back (builder.create <mlir::LLVM::UndefOp>(
576
- builder. getUnknownLoc ( ), ty ));
587
+ std::get< 1 >(tup ), std::get< 0 >(tup) ));
577
588
}
578
589
}
579
590
if (op.getFalseDest () == header) {
580
591
falseargs.insert (falseargs.begin (), vtrue);
581
592
for (auto pair : preservedVals)
582
593
falseargs.push_back (pair.first );
583
- for (auto ty : returns) {
594
+ for (auto tup : llvm::zip ( returns, returnLocs) ) {
584
595
falseargs.push_back (builder.create <mlir::LLVM::UndefOp>(
585
- builder. getUnknownLoc ( ), ty ));
596
+ std::get< 1 >(tup ), std::get< 0 >(tup) ));
586
597
}
587
598
}
588
599
// Recreate the terminator and store it so that its other
@@ -600,8 +611,7 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
600
611
}
601
612
602
613
Block *after = new Block ();
603
- SmallVector<Location> locs2 (combinedTypes.size (), region.getLoc ());
604
- after->addArguments (combinedTypes, locs2);
614
+ after->addArguments (combinedTypes, combinedLocs);
605
615
loop.getAfter ().push_back (after);
606
616
OpBuilder builder2 (after, after->begin ());
607
617
SmallVector<Value, 4 > yieldargs;
@@ -637,7 +647,8 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) {
637
647
}
638
648
header->eraseArguments ([](BlockArgument) { return true ; });
639
649
640
- builder2.create <scf::YieldOp>(builder.getUnknownLoc (), yieldargs);
650
+ builder2.create <scf::YieldOp>(header->getTerminator ()->getLoc (),
651
+ yieldargs);
641
652
domInfo.invalidate (&insertRegion);
642
653
643
654
assert (header->getParent () == &insertRegion);
0 commit comments