Skip to content

Commit 5f704f9

Browse files
authored
[RemoveDI][Polly] Migrate to adapt to the new DebugRecord format in more areas (#135935)
Some of the changes in the patch include: 1. Using iterators instead of instruction pointers when applicable. 2. Modifying Polly functions to accept iterators instead of inst pointers. 3. Updating API usages such as use begin instead of front.
1 parent 2319a1e commit 5f704f9

File tree

6 files changed

+33
-34
lines changed

6 files changed

+33
-34
lines changed

polly/include/polly/Support/ScopHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ llvm::Value *expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
402402
llvm::Function *GenFn, llvm::ScalarEvolution &GenSE,
403403
const llvm::DataLayout &DL, const char *Name,
404404
const llvm::SCEV *E, llvm::Type *Ty,
405-
llvm::Instruction *IP, ValueMapT *VMap,
405+
llvm::BasicBlock::iterator IP, ValueMapT *VMap,
406406
LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB);
407407

408408
/// Return the condition for the terminator @p TI.

polly/lib/CodeGen/BlockGenerators.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, Value *Old,
8787
"Only instructions can be insert points for SCEVExpander");
8888
Value *Expanded = expandCodeFor(
8989
S, SE, Builder.GetInsertBlock()->getParent(), *GenSE, DL, "polly", Scev,
90-
Old->getType(), &*IP, &VTV, &LTS, StartBlock->getSinglePredecessor());
90+
Old->getType(), IP, &VTV, &LTS, StartBlock->getSinglePredecessor());
9191

9292
BBMap[Old] = Expanded;
9393
return Expanded;
@@ -411,7 +411,7 @@ void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
411411

412412
BasicBlock *BlockGenerator::splitBB(BasicBlock *BB) {
413413
BasicBlock *CopyBB = SplitBlock(Builder.GetInsertBlock(),
414-
&*Builder.GetInsertPoint(), GenDT, GenLI);
414+
Builder.GetInsertPoint(), GenDT, GenLI);
415415
CopyBB->setName("polly.stmt." + BB->getName());
416416
return CopyBB;
417417
}
@@ -622,7 +622,7 @@ void BlockGenerator::generateConditionalExecution(
622622

623623
// Generate the conditional block.
624624
DomTreeUpdater DTU(GenDT, DomTreeUpdater::UpdateStrategy::Eager);
625-
SplitBlockAndInsertIfThen(Cond, &*Builder.GetInsertPoint(), false, nullptr,
625+
SplitBlockAndInsertIfThen(Cond, Builder.GetInsertPoint(), false, nullptr,
626626
&DTU, GenLI);
627627
BranchInst *Branch = cast<BranchInst>(HeadBlock->getTerminator());
628628
BasicBlock *ThenBlock = Branch->getSuccessor(0);
@@ -1069,8 +1069,8 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
10691069
// Create a dedicated entry for the region where we can reload all demoted
10701070
// inputs.
10711071
BasicBlock *EntryBB = R->getEntry();
1072-
BasicBlock *EntryBBCopy = SplitBlock(
1073-
Builder.GetInsertBlock(), &*Builder.GetInsertPoint(), GenDT, GenLI);
1072+
BasicBlock *EntryBBCopy = SplitBlock(Builder.GetInsertBlock(),
1073+
Builder.GetInsertPoint(), GenDT, GenLI);
10741074
EntryBBCopy->setName("polly.stmt." + EntryBB->getName() + ".entry");
10751075
Builder.SetInsertPoint(EntryBBCopy, EntryBBCopy->begin());
10761076

@@ -1136,7 +1136,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
11361136

11371137
// Now create a new dedicated region exit block and add it to the region map.
11381138
BasicBlock *ExitBBCopy = SplitBlock(Builder.GetInsertBlock(),
1139-
&*Builder.GetInsertPoint(), GenDT, GenLI);
1139+
Builder.GetInsertPoint(), GenDT, GenLI);
11401140
ExitBBCopy->setName("polly.stmt." + R->getExit()->getName() + ".exit");
11411141
StartBlockMap[R->getExit()] = ExitBBCopy;
11421142
EndBlockMap[R->getExit()] = ExitBBCopy;

polly/lib/CodeGen/IslExprBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ IslExprBuilder::createAccessAddress(__isl_take isl_ast_expr *Expr) {
324324
// needed. But GlobalMap may contain SCoP-invariant vars.
325325
Value *DimSize = expandCodeFor(
326326
S, SE, Builder.GetInsertBlock()->getParent(), *GenSE, DL, "polly",
327-
DimSCEV, DimSCEV->getType(), &*Builder.GetInsertPoint(), &GlobalMap,
327+
DimSCEV, DimSCEV->getType(), Builder.GetInsertPoint(), &GlobalMap,
328328
/*LoopMap*/ nullptr, StartBlock->getSinglePredecessor());
329329

330330
Type *Ty = getWidestType(DimSize->getType(), IndexOp->getType());
@@ -613,7 +613,7 @@ IslExprBuilder::createOpBooleanConditional(__isl_take isl_ast_expr *Expr) {
613613

614614
auto InsertBB = Builder.GetInsertBlock();
615615
auto InsertPoint = Builder.GetInsertPoint();
616-
auto NextBB = SplitBlock(InsertBB, &*InsertPoint, GenDT, GenLI);
616+
auto NextBB = SplitBlock(InsertBB, InsertPoint, GenDT, GenLI);
617617
BasicBlock *CondBB = BasicBlock::Create(Context, "polly.cond", F);
618618
GenLI->changeLoopFor(CondBB, GenLI->getLoopFor(InsertBB));
619619
GenDT->addNewBlock(CondBB, InsertBB);

polly/lib/CodeGen/IslNodeBuilder.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) {
505505
// The preamble of parallel code interacts different than normal code with
506506
// e.g., scalar initialization. Therefore, we ensure the parallel code is
507507
// separated from the last basic block.
508-
BasicBlock *ParBB = SplitBlock(Builder.GetInsertBlock(),
509-
&*Builder.GetInsertPoint(), &DT, &LI);
508+
BasicBlock *ParBB =
509+
SplitBlock(Builder.GetInsertBlock(), Builder.GetInsertPoint(), &DT, &LI);
510510
ParBB->setName("polly.parallel.for");
511511
Builder.SetInsertPoint(ParBB, ParBB->begin());
512512

@@ -711,9 +711,9 @@ void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) {
711711
LLVMContext &Context = F->getContext();
712712

713713
BasicBlock *CondBB = SplitBlock(Builder.GetInsertBlock(),
714-
&*Builder.GetInsertPoint(), GenDT, GenLI);
714+
Builder.GetInsertPoint(), GenDT, GenLI);
715715
CondBB->setName("polly.cond");
716-
BasicBlock *MergeBB = SplitBlock(CondBB, &CondBB->front(), GenDT, GenLI);
716+
BasicBlock *MergeBB = SplitBlock(CondBB, CondBB->begin(), GenDT, GenLI);
717717
MergeBB->setName("polly.merge");
718718
BasicBlock *ThenBB = BasicBlock::Create(Context, "polly.then", F);
719719
BasicBlock *ElseBB = BasicBlock::Create(Context, "polly.else", F);
@@ -1111,10 +1111,10 @@ Value *IslNodeBuilder::preloadInvariantLoad(const MemoryAccess &MA,
11111111
Cond = Builder.CreateIsNotNull(Cond);
11121112

11131113
BasicBlock *CondBB = SplitBlock(Builder.GetInsertBlock(),
1114-
&*Builder.GetInsertPoint(), GenDT, GenLI);
1114+
Builder.GetInsertPoint(), GenDT, GenLI);
11151115
CondBB->setName("polly.preload.cond");
11161116

1117-
BasicBlock *MergeBB = SplitBlock(CondBB, &CondBB->front(), GenDT, GenLI);
1117+
BasicBlock *MergeBB = SplitBlock(CondBB, CondBB->begin(), GenDT, GenLI);
11181118
MergeBB->setName("polly.preload.merge");
11191119

11201120
Function *F = Builder.GetInsertBlock()->getParent();
@@ -1353,7 +1353,7 @@ bool IslNodeBuilder::preloadInvariantLoads() {
13531353
return true;
13541354

13551355
BasicBlock *PreLoadBB = SplitBlock(Builder.GetInsertBlock(),
1356-
&*Builder.GetInsertPoint(), GenDT, GenLI);
1356+
Builder.GetInsertPoint(), GenDT, GenLI);
13571357
PreLoadBB->setName("polly.preload.begin");
13581358
Builder.SetInsertPoint(PreLoadBB, PreLoadBB->begin());
13591359

@@ -1401,7 +1401,7 @@ Value *IslNodeBuilder::generateSCEV(const SCEV *Expr) {
14011401
/// insert location remains valid.
14021402
assert(Builder.GetInsertBlock()->end() != Builder.GetInsertPoint() &&
14031403
"Insert location points after last valid instruction");
1404-
Instruction *InsertLocation = &*Builder.GetInsertPoint();
1404+
BasicBlock::iterator InsertLocation = Builder.GetInsertPoint();
14051405

14061406
return expandCodeFor(S, SE, Builder.GetInsertBlock()->getParent(), *GenSE, DL,
14071407
"polly", Expr, Expr->getType(), InsertLocation,

polly/lib/CodeGen/LoopGenerators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride,
128128
Annotator->pushLoop(NewLoop, Parallel);
129129

130130
// ExitBB
131-
ExitBB = SplitBlock(BeforeBB, &*Builder.GetInsertPoint(), &DT, &LI);
131+
ExitBB = SplitBlock(BeforeBB, Builder.GetInsertPoint(), &DT, &LI);
132132
ExitBB->setName("polly.loop_exit");
133133

134134
// BeforeBB

polly/lib/Support/ScopHelper.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ void polly::simplifyRegion(Region *R, DominatorTree *DT, LoopInfo *LI,
165165
// Split the block into two successive blocks.
166166
//
167167
// Like llvm::SplitBlock, but also preserves RegionInfo
168-
static BasicBlock *splitBlock(BasicBlock *Old, Instruction *SplitPt,
168+
static BasicBlock *splitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
169169
DominatorTree *DT, llvm::LoopInfo *LI,
170170
RegionInfo *RI) {
171-
assert(Old && SplitPt);
171+
assert(Old);
172172

173173
// Before:
174174
//
@@ -203,7 +203,7 @@ void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, DominatorTree *DT,
203203
++I;
204204

205205
// splitBlock updates DT, LI and RI.
206-
splitBlock(EntryBlock, &*I, DT, LI, RI);
206+
splitBlock(EntryBlock, I, DT, LI, RI);
207207
}
208208

209209
void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) {
@@ -261,8 +261,8 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
261261
VMap(VMap), LoopMap(LoopMap), RTCBB(RTCBB), GenSE(GenSE), GenFn(GenFn) {
262262
}
263263

264-
Value *expandCodeFor(const SCEV *E, Type *Ty, Instruction *IP) {
265-
assert(isInGenRegion(IP) &&
264+
Value *expandCodeFor(const SCEV *E, Type *Ty, BasicBlock::iterator IP) {
265+
assert(isInGenRegion(&*IP) &&
266266
"ScopExpander assumes to be applied to generated code region");
267267
const SCEV *GenE = visit(E);
268268
return Expander.expandCodeFor(GenE, Ty, IP);
@@ -305,7 +305,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
305305
bool isInGenRegion(Instruction *Inst) { return !isInOrigRegion(Inst); }
306306

307307
const SCEV *visitGenericInst(const SCEVUnknown *E, Instruction *Inst,
308-
Instruction *IP) {
308+
BasicBlock::iterator IP) {
309309
if (!Inst || isInGenRegion(Inst))
310310
return E;
311311

@@ -321,7 +321,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
321321
}
322322

323323
InstClone->setName(Name + Inst->getName());
324-
InstClone->insertBefore(IP->getIterator());
324+
InstClone->insertBefore(IP);
325325
return GenSE.getSCEV(InstClone);
326326
}
327327

@@ -341,19 +341,19 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
341341
}
342342

343343
Instruction *Inst = dyn_cast<Instruction>(E->getValue());
344-
Instruction *IP;
344+
BasicBlock::iterator IP;
345345
if (Inst && isInGenRegion(Inst))
346-
IP = Inst;
346+
IP = Inst->getIterator();
347347
else if (R.getEntry()->getParent() != GenFn) {
348348
// RTCBB is in the original function, but we are generating for a
349349
// subfunction so we cannot emit to RTCBB. Usually, we land here only
350350
// because E->getValue() is not an instruction but a global or constant
351351
// which do not need to emit anything.
352-
IP = GenFn->getEntryBlock().getTerminator();
352+
IP = GenFn->getEntryBlock().getTerminator()->getIterator();
353353
} else if (Inst && RTCBB->getParent() == Inst->getFunction())
354-
IP = RTCBB->getTerminator();
354+
IP = RTCBB->getTerminator()->getIterator();
355355
else
356-
IP = RTCBB->getParent()->getEntryBlock().getTerminator();
356+
IP = RTCBB->getParent()->getEntryBlock().getTerminator()->getIterator();
357357

358358
if (!Inst || (Inst->getOpcode() != Instruction::SRem &&
359359
Inst->getOpcode() != Instruction::SDiv))
@@ -368,9 +368,8 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
368368
Value *LHS = expandCodeFor(LHSScev, E->getType(), IP);
369369
Value *RHS = expandCodeFor(RHSScev, E->getType(), IP);
370370

371-
Inst =
372-
BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(), LHS,
373-
RHS, Inst->getName() + Name, IP->getIterator());
371+
Inst = BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(),
372+
LHS, RHS, Inst->getName() + Name, IP);
374373
return GenSE.getSCEV(Inst);
375374
}
376375

@@ -465,7 +464,7 @@ struct ScopExpander final : SCEVVisitor<ScopExpander, const SCEV *> {
465464
Value *polly::expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
466465
llvm::Function *GenFn, ScalarEvolution &GenSE,
467466
const DataLayout &DL, const char *Name,
468-
const SCEV *E, Type *Ty, Instruction *IP,
467+
const SCEV *E, Type *Ty, BasicBlock::iterator IP,
469468
ValueMapT *VMap, LoopToScevMapT *LoopMap,
470469
BasicBlock *RTCBB) {
471470
ScopExpander Expander(S.getRegion(), SE, GenFn, GenSE, DL, Name, VMap,

0 commit comments

Comments
 (0)