Skip to content

Commit 631f411

Browse files
kartcqIanWood1
authored andcommitted
[RemoveDI][Polly] Use iterators instead of instruction pointers to SetInsertPoint (llvm#135336)
As part of the effort to transition to using Debug Records instead of Debug intrinsics, some API/argument changes are necessary to achieve the desired behavior from Debug Records. This particular fix involves passing iterators instead of instruction pointers to the SetInsertPoint function. While this is crucial in certain areas, it may be more than needed in others, but it does not cause any harm.
1 parent 93dd507 commit 631f411

File tree

8 files changed

+48
-39
lines changed

8 files changed

+48
-39
lines changed

polly/lib/CodeGen/BlockGenerators.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ BasicBlock *BlockGenerator::copyBB(ScopStmt &Stmt, BasicBlock *BB,
420420
ValueMapT &BBMap, LoopToScevMapT &LTS,
421421
isl_id_to_ast_expr *NewAccesses) {
422422
BasicBlock *CopyBB = splitBB(BB);
423-
Builder.SetInsertPoint(&CopyBB->front());
423+
Builder.SetInsertPoint(CopyBB, CopyBB->begin());
424424
generateScalarLoads(Stmt, LTS, BBMap, NewAccesses);
425425
generateBeginStmtTrace(Stmt, LTS, BBMap);
426426

@@ -795,7 +795,7 @@ void BlockGenerator::createScalarInitialization(Scop &S) {
795795
BasicBlock *ExitBB = S.getExit();
796796
BasicBlock *PreEntryBB = S.getEnteringBlock();
797797

798-
Builder.SetInsertPoint(&*StartBlock->begin());
798+
Builder.SetInsertPoint(StartBlock, StartBlock->begin());
799799

800800
for (auto &Array : S.arrays()) {
801801
if (Array->getNumberOfDimensions() != 0)
@@ -850,7 +850,7 @@ void BlockGenerator::createScalarFinalization(Scop &S) {
850850
if (OptExitBB == ExitBB)
851851
OptExitBB = *(++pred_begin(MergeBB));
852852

853-
Builder.SetInsertPoint(OptExitBB->getTerminator());
853+
Builder.SetInsertPoint(OptExitBB, OptExitBB->getTerminator()->getIterator());
854854
for (const auto &EscapeMapping : EscapeMap) {
855855
// Extract the escaping instruction and the escaping users as well as the
856856
// alloca the instruction was demoted to.
@@ -921,7 +921,7 @@ void BlockGenerator::createExitPHINodeMerges(Scop &S) {
921921
if (OptExitBB == ExitBB)
922922
OptExitBB = *(++pred_begin(MergeBB));
923923

924-
Builder.SetInsertPoint(OptExitBB->getTerminator());
924+
Builder.SetInsertPoint(OptExitBB, OptExitBB->getTerminator()->getIterator());
925925

926926
for (auto &SAI : S.arrays()) {
927927
auto *Val = SAI->getBasePtr();
@@ -1072,7 +1072,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
10721072
BasicBlock *EntryBBCopy = SplitBlock(
10731073
Builder.GetInsertBlock(), &*Builder.GetInsertPoint(), GenDT, GenLI);
10741074
EntryBBCopy->setName("polly.stmt." + EntryBB->getName() + ".entry");
1075-
Builder.SetInsertPoint(&EntryBBCopy->front());
1075+
Builder.SetInsertPoint(EntryBBCopy, EntryBBCopy->begin());
10761076

10771077
ValueMapT &EntryBBMap = RegionMaps[EntryBBCopy];
10781078
generateScalarLoads(Stmt, LTS, EntryBBMap, IdToAstExp);
@@ -1112,7 +1112,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
11121112
ValueMapT &RegionMap = Inserted.first->second;
11131113

11141114
// Copy the block with the BlockGenerator.
1115-
Builder.SetInsertPoint(&BBCopy->front());
1115+
Builder.SetInsertPoint(BBCopy, BBCopy->begin());
11161116
copyBB(Stmt, BB, BBCopy, RegionMap, LTS, IdToAstExp);
11171117

11181118
// In order to remap PHI nodes we store also basic block mappings.
@@ -1166,7 +1166,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
11661166
ValueMapT &RegionMap = RegionMaps[BBCopyStart];
11671167
RegionMap.insert_range(StartBlockMap);
11681168

1169-
Builder.SetInsertPoint(BICopy);
1169+
Builder.SetInsertPoint(BBCopyEnd, BICopy->getIterator());
11701170
copyInstScalar(Stmt, TI, RegionMap, LTS);
11711171
BICopy->eraseFromParent();
11721172
}
@@ -1204,7 +1204,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
12041204
}
12051205

12061206
// Continue generating code in the exit block.
1207-
Builder.SetInsertPoint(&*ExitBBCopy->getFirstInsertionPt());
1207+
Builder.SetInsertPoint(ExitBBCopy, ExitBBCopy->getFirstInsertionPt());
12081208

12091209
// Write values visible to other statements.
12101210
generateScalarStores(Stmt, LTS, ValueMap, IdToAstExp);
@@ -1241,7 +1241,8 @@ PHINode *RegionGenerator::buildExitPHI(MemoryAccess *MA, LoopToScevMapT &LTS,
12411241
BasicBlock *OrigIncomingBlock = Pair.first;
12421242
BasicBlock *NewIncomingBlockStart = StartBlockMap.lookup(OrigIncomingBlock);
12431243
BasicBlock *NewIncomingBlockEnd = EndBlockMap.lookup(OrigIncomingBlock);
1244-
Builder.SetInsertPoint(NewIncomingBlockEnd->getTerminator());
1244+
Builder.SetInsertPoint(NewIncomingBlockEnd,
1245+
NewIncomingBlockEnd->getTerminator()->getIterator());
12451246
assert(RegionMaps.count(NewIncomingBlockStart));
12461247
assert(RegionMaps.count(NewIncomingBlockEnd));
12471248
ValueMapT *LocalBBMap = &RegionMaps[NewIncomingBlockStart];
@@ -1358,10 +1359,11 @@ void RegionGenerator::addOperandToPHI(ScopStmt &Stmt, PHINode *PHI,
13581359
// change it, otherwise do not.
13591360
auto IP = Builder.GetInsertPoint();
13601361
if (IP->getParent() != BBCopyEnd)
1361-
Builder.SetInsertPoint(BBCopyEnd->getTerminator());
1362+
Builder.SetInsertPoint(BBCopyEnd,
1363+
BBCopyEnd->getTerminator()->getIterator());
13621364
OpCopy = getNewValue(Stmt, Op, BBCopyMap, LTS, getLoopForStmt(Stmt));
13631365
if (IP->getParent() != BBCopyEnd)
1364-
Builder.SetInsertPoint(&*IP);
1366+
Builder.SetInsertPoint(IP);
13651367
} else {
13661368
// All edges from outside the non-affine region become a single edge
13671369
// in the new copy of the non-affine region. Make sure to only add the

polly/lib/CodeGen/CodeGeneration.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ namespace polly {
7777
/// Marks the basic block @p Block unreachable by equipping it with an
7878
/// UnreachableInst.
7979
void markBlockUnreachable(BasicBlock &Block, PollyIRBuilder &Builder) {
80-
auto *OrigTerminator = Block.getTerminator();
81-
Builder.SetInsertPoint(OrigTerminator);
80+
auto OrigTerminator = Block.getTerminator()->getIterator();
81+
Builder.SetInsertPoint(&Block, OrigTerminator);
8282
Builder.CreateUnreachable();
8383
OrigTerminator->eraseFromParent();
8484
}
@@ -211,7 +211,8 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
211211
assert(EnteringBB);
212212
PollyIRBuilder Builder(EnteringBB->getContext(), ConstantFolder(),
213213
IRInserter(Annotator));
214-
Builder.SetInsertPoint(EnteringBB->getTerminator());
214+
Builder.SetInsertPoint(EnteringBB,
215+
EnteringBB->getTerminator()->getIterator());
215216

216217
// Only build the run-time condition and parameters _after_ having
217218
// introduced the conditional branch. This is important as the conditional
@@ -257,7 +258,8 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
257258
// might reference the hoisted loads. Finally, build the runtime check
258259
// that might reference both hoisted loads as well as parameters.
259260
// If the hoisting fails we have to bail and execute the original code.
260-
Builder.SetInsertPoint(SplitBlock->getTerminator());
261+
Builder.SetInsertPoint(SplitBlock,
262+
SplitBlock->getTerminator()->getIterator());
261263
if (!NodeBuilder.preloadInvariantLoads()) {
262264
// Patch the introduced branch condition to ensure that we always execute
263265
// the original SCoP.
@@ -289,7 +291,8 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
289291
// Ideally we would just split the block during allocation of the new
290292
// arrays, but this would break the assumption that there are no blocks
291293
// between polly.start and polly.exiting (at this point).
292-
Builder.SetInsertPoint(StartBlock->getTerminator());
294+
Builder.SetInsertPoint(StartBlock,
295+
StartBlock->getTerminator()->getIterator());
293296

294297
NodeBuilder.create(AstRoot.release());
295298
NodeBuilder.finalize();

polly/lib/CodeGen/IslExprBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ IslExprBuilder::createOpBooleanConditional(__isl_take isl_ast_expr *Expr) {
625625
Builder.SetInsertPoint(CondBB);
626626
Builder.CreateBr(NextBB);
627627

628-
Builder.SetInsertPoint(InsertBB->getTerminator());
628+
Builder.SetInsertPoint(InsertBB, InsertBB->getTerminator()->getIterator());
629629

630630
LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
631631
if (!LHS->getType()->isIntegerTy(1))
@@ -637,13 +637,13 @@ IslExprBuilder::createOpBooleanConditional(__isl_take isl_ast_expr *Expr) {
637637
else
638638
BR->setCondition(LHS);
639639

640-
Builder.SetInsertPoint(CondBB->getTerminator());
640+
Builder.SetInsertPoint(CondBB, CondBB->getTerminator()->getIterator());
641641
RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
642642
if (!RHS->getType()->isIntegerTy(1))
643643
RHS = Builder.CreateIsNotNull(RHS);
644644
auto RightBB = Builder.GetInsertBlock();
645645

646-
Builder.SetInsertPoint(NextBB->getTerminator());
646+
Builder.SetInsertPoint(NextBB, NextBB->getTerminator()->getIterator());
647647
auto PHI = Builder.CreatePHI(Builder.getInt1Ty(), 2);
648648
PHI->addIncoming(OpType == isl_ast_op_and_then ? Builder.getFalse()
649649
: Builder.getTrue(),

polly/lib/CodeGen/IslNodeBuilder.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void IslNodeBuilder::createForSequential(isl::ast_node_for For,
488488

489489
IDToValue.erase(IDToValue.find(IteratorID.get()));
490490

491-
Builder.SetInsertPoint(&ExitBlock->front());
491+
Builder.SetInsertPoint(ExitBlock, ExitBlock->begin());
492492

493493
SequentialLoops++;
494494
}
@@ -508,7 +508,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
508508
BasicBlock *ParBB = SplitBlock(Builder.GetInsertBlock(),
509509
&*Builder.GetInsertPoint(), &DT, &LI);
510510
ParBB->setName("polly.parallel.for");
511-
Builder.SetInsertPoint(&ParBB->front());
511+
Builder.SetInsertPoint(ParBB, ParBB->begin());
512512

513513
Body = isl_ast_node_for_get_body(For);
514514
Init = isl_ast_node_for_get_init(For);
@@ -612,7 +612,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
612612
BlockGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
613613
RegionGen.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
614614
ExprBuilder.switchGeneratedFunc(SubFn, GenDT, GenLI, GenSE);
615-
Builder.SetInsertPoint(&*LoopBody);
615+
Builder.SetInsertPoint(LoopBody);
616616

617617
// Update the ValueMap to use instructions in the subfunction. Note that
618618
// "GlobalMap" used in BlockGenerator/IslExprBuilder is a reference to this
@@ -682,7 +682,7 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
682682
ExprBuilder.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
683683
RegionGen.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
684684
BlockGen.switchGeneratedFunc(CallerFn, CallerDT, CallerLI, CallerSE);
685-
Builder.SetInsertPoint(&*AfterLoop);
685+
Builder.SetInsertPoint(AfterLoop);
686686

687687
for (const Loop *L : Loops)
688688
OutsideLoopIterations.erase(L);
@@ -737,16 +737,16 @@ void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) {
737737
Builder.CreateBr(MergeBB);
738738
Builder.SetInsertPoint(ElseBB);
739739
Builder.CreateBr(MergeBB);
740-
Builder.SetInsertPoint(&ThenBB->front());
740+
Builder.SetInsertPoint(ThenBB, ThenBB->begin());
741741

742742
create(isl_ast_node_if_get_then(If));
743743

744-
Builder.SetInsertPoint(&ElseBB->front());
744+
Builder.SetInsertPoint(ElseBB, ElseBB->begin());
745745

746746
if (isl_ast_node_if_has_else(If))
747747
create(isl_ast_node_if_get_else(If));
748748

749-
Builder.SetInsertPoint(&MergeBB->front());
749+
Builder.SetInsertPoint(MergeBB, MergeBB->begin());
750750

751751
isl_ast_node_free(If);
752752

@@ -1126,16 +1126,16 @@ Value *IslNodeBuilder::preloadInvariantLoad(const MemoryAccess &MA,
11261126
L->addBasicBlockToLoop(ExecBB, *GenLI);
11271127

11281128
auto *CondBBTerminator = CondBB->getTerminator();
1129-
Builder.SetInsertPoint(CondBBTerminator);
1129+
Builder.SetInsertPoint(CondBB, CondBBTerminator->getIterator());
11301130
Builder.CreateCondBr(Cond, ExecBB, MergeBB);
11311131
CondBBTerminator->eraseFromParent();
11321132

11331133
Builder.SetInsertPoint(ExecBB);
11341134
Builder.CreateBr(MergeBB);
11351135

1136-
Builder.SetInsertPoint(ExecBB->getTerminator());
1136+
Builder.SetInsertPoint(ExecBB, ExecBB->getTerminator()->getIterator());
11371137
Value *PreAccInst = preloadUnconditionally(AccessRange, Build, AccInst);
1138-
Builder.SetInsertPoint(MergeBB->getTerminator());
1138+
Builder.SetInsertPoint(MergeBB, MergeBB->getTerminator()->getIterator());
11391139
auto *MergePHI = Builder.CreatePHI(
11401140
AccInstTy, 2, "polly.preload." + AccInst->getName() + ".merge");
11411141
PreloadVal = MergePHI;
@@ -1315,7 +1315,9 @@ void IslNodeBuilder::allocateNewArrays(BBPair StartExitBlocks) {
13151315
unsigned Size = SAI->getElemSizeInBytes();
13161316

13171317
// Insert the malloc call at polly.start
1318-
Builder.SetInsertPoint(std::get<0>(StartExitBlocks)->getTerminator());
1318+
BasicBlock *StartBlock = std::get<0>(StartExitBlocks);
1319+
Builder.SetInsertPoint(StartBlock,
1320+
StartBlock->getTerminator()->getIterator());
13191321
auto *CreatedArray = Builder.CreateMalloc(
13201322
IntPtrTy, SAI->getElementType(),
13211323
ConstantInt::get(Type::getInt64Ty(Ctx), Size),
@@ -1325,7 +1327,9 @@ void IslNodeBuilder::allocateNewArrays(BBPair StartExitBlocks) {
13251327
SAI->setBasePtr(CreatedArray);
13261328

13271329
// Insert the free call at polly.exiting
1328-
Builder.SetInsertPoint(std::get<1>(StartExitBlocks)->getTerminator());
1330+
BasicBlock *ExitingBlock = std::get<1>(StartExitBlocks);
1331+
Builder.SetInsertPoint(ExitingBlock,
1332+
ExitingBlock->getTerminator()->getIterator());
13291333
Builder.CreateFree(CreatedArray);
13301334
} else {
13311335
auto InstIt = Builder.GetInsertBlock()
@@ -1351,7 +1355,7 @@ bool IslNodeBuilder::preloadInvariantLoads() {
13511355
BasicBlock *PreLoadBB = SplitBlock(Builder.GetInsertBlock(),
13521356
&*Builder.GetInsertPoint(), GenDT, GenLI);
13531357
PreLoadBB->setName("polly.preload.begin");
1354-
Builder.SetInsertPoint(&PreLoadBB->front());
1358+
Builder.SetInsertPoint(PreLoadBB, PreLoadBB->begin());
13551359

13561360
for (auto &IAClass : InvariantEquivClasses)
13571361
if (!preloadInvariantEquivClass(IAClass))

polly/lib/CodeGen/LoopGenerators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Value *ParallelLoopGenerator::createParallelLoop(
200200
Function *SubFn;
201201
std::tie(IV, SubFn) = createSubFn(Stride, Struct, UsedValues, Map);
202202
*LoopBody = Builder.GetInsertPoint();
203-
Builder.SetInsertPoint(&*BeforeLoop);
203+
Builder.SetInsertPoint(BeforeLoop);
204204

205205
// Add one as the upper bound provided by OpenMP is a < comparison
206206
// whereas the codegenForSequential function creates a <= comparison.

polly/lib/CodeGen/LoopGeneratorsGOMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ ParallelLoopGeneratorGOMP::createSubFn(Value *Stride, AllocaInst *StructData,
148148
"polly.par.UBAdjusted");
149149

150150
Builder.CreateBr(CheckNextBB);
151-
Builder.SetInsertPoint(&*--Builder.GetInsertPoint());
151+
Builder.SetInsertPoint(--Builder.GetInsertPoint());
152152
BasicBlock *AfterBB;
153153
Value *IV =
154154
createLoop(LB, UB, Stride, Builder, *SubFnLI, *SubFnDT, AfterBB,
@@ -161,7 +161,7 @@ ParallelLoopGeneratorGOMP::createSubFn(Value *Stride, AllocaInst *StructData,
161161
createCallCleanupThread();
162162
Builder.CreateRetVoid();
163163

164-
Builder.SetInsertPoint(&*LoopBody);
164+
Builder.SetInsertPoint(LoopBody);
165165

166166
// FIXME: Call SubFnDT->verify() and SubFnLI->verify() to check that the
167167
// DominatorTree/LoopInfo has been created correctly. Alternatively, recreate

polly/lib/CodeGen/LoopGeneratorsKMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ ParallelLoopGeneratorKMP::createSubFn(Value *SequentialLoopStride,
282282
}
283283

284284
Builder.CreateBr(CheckNextBB);
285-
Builder.SetInsertPoint(&*--Builder.GetInsertPoint());
285+
Builder.SetInsertPoint(--Builder.GetInsertPoint());
286286
BasicBlock *AfterBB;
287287
Value *IV = createLoop(LB, UB, SequentialLoopStride, Builder, *SubFnLI,
288288
*SubFnDT, AfterBB, ICmpInst::ICMP_SLE, nullptr, true,
@@ -298,7 +298,7 @@ ParallelLoopGeneratorKMP::createSubFn(Value *SequentialLoopStride,
298298
createCallStaticFini(ID);
299299
}
300300
Builder.CreateRetVoid();
301-
Builder.SetInsertPoint(&*LoopBody);
301+
Builder.SetInsertPoint(LoopBody);
302302

303303
// FIXME: Call SubFnDT->verify() and SubFnLI->verify() to check that the
304304
// DominatorTree/LoopInfo has been created correctly. Alternatively, recreate

polly/lib/CodeGen/PerfMonitor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void PerfMonitor::insertRegionStart(Instruction *InsertBefore) {
267267
if (!Supported)
268268
return;
269269

270-
Builder.SetInsertPoint(InsertBefore);
270+
Builder.SetInsertPoint(InsertBefore->getIterator());
271271
Function *RDTSCPFn = getRDTSCP();
272272
Value *CurrentCycles =
273273
Builder.CreateExtractValue(Builder.CreateCall(RDTSCPFn), {0});
@@ -278,7 +278,7 @@ void PerfMonitor::insertRegionEnd(Instruction *InsertBefore) {
278278
if (!Supported)
279279
return;
280280

281-
Builder.SetInsertPoint(InsertBefore);
281+
Builder.SetInsertPoint(InsertBefore->getIterator());
282282
Function *RDTSCPFn = getRDTSCP();
283283
Type *Int64Ty = Builder.getInt64Ty();
284284
LoadInst *CyclesStart =

0 commit comments

Comments
 (0)