Skip to content

Commit e25cd88

Browse files
committed
Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
This change is needed for the next update to ToT LLVM. It can be put into place now without breaking anything so I am committing it now. The churn upstream on ilist_node is neccessary to remove undefined behavior. Rather than updating the different ilist_node patches for the hacky change required to not use iterators, just use iterators and keep everything as ilist_nodes. Upstream they want to eventually do this, so it makes sense for us to just do it now. Please do not introduce new invocations of ilist_node::get{Next,Prev}Node() into the tree.
1 parent 2874743 commit e25cd88

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,13 +1392,13 @@ void IRGenSILFunction::emitSILFunction() {
13921392
// Map the entry bb.
13931393
LoweredBBs[&*CurSILFn->begin()] = LoweredBB(&*CurFn->begin(), {});
13941394
// Create LLVM basic blocks for the other bbs.
1395-
for (SILBasicBlock *bb = CurSILFn->begin()->getNextNode();
1396-
bb != CurSILFn->end(); bb = bb->getNextNode()) {
1395+
for (auto bi = std::next(CurSILFn->begin()), be = CurSILFn->end(); bi != be;
1396+
++bi) {
13971397
// FIXME: Use the SIL basic block's name.
13981398
llvm::BasicBlock *llBB = llvm::BasicBlock::Create(IGM.getLLVMContext());
1399-
auto phis = emitPHINodesForBBArgs(*this, bb, llBB);
1399+
auto phis = emitPHINodesForBBArgs(*this, &*bi, llBB);
14001400
CurFn->getBasicBlockList().push_back(llBB);
1401-
LoweredBBs[bb] = LoweredBB(llBB, std::move(phis));
1401+
LoweredBBs[&*bi] = LoweredBB(llBB, std::move(phis));
14021402
}
14031403

14041404
auto entry = LoweredBBs.begin();
@@ -3386,18 +3386,21 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
33863386
// if the alloc_stack is dominated by copy_addrs into it on all paths.
33873387
// For now, check only that the copy_addr is the first use within the same
33883388
// block.
3389-
const SILInstruction *inst = allocInst;
3390-
while ((inst = inst->getNextNode()) && !isa<TermInst>(inst)) {
3391-
// Does this instruction use the allocation?
3392-
for (auto &operand : inst->getAllOperands())
3393-
if (operand.get() == addressValue)
3394-
goto is_use;
3395-
3396-
continue;
3397-
3398-
is_use:
3389+
for (auto ii = std::next(allocInst->getIterator()),
3390+
ie = std::prev(allocInst->getParent()->end());
3391+
ii != ie; ++ii) {
3392+
auto *inst = &*ii;
3393+
3394+
// Does this instruction use the allocation? If not, continue.
3395+
auto Ops = inst->getAllOperands();
3396+
if (std::none_of(Ops.begin(), Ops.end(),
3397+
[&addressValue](const Operand &Op) {
3398+
return Op.get() == addressValue;
3399+
}))
3400+
continue;
3401+
33993402
// Is this a copy?
3400-
auto copy = dyn_cast<swift::CopyAddrInst>(inst);
3403+
auto *copy = dyn_cast<swift::CopyAddrInst>(inst);
34013404
if (!copy)
34023405
return false;
34033406

lib/SIL/Dominance.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ bool DominanceInfo::properlyDominates(SILInstruction *a, SILInstruction *b) {
4040

4141
// Otherwise, they're in the same block, and we just need to check
4242
// whether B comes after A. This is a non-strict computation.
43-
SILInstruction *f = &*aBlock->begin();
44-
while (b != f) {
45-
b = b->getPrevNode();
46-
if (a == b) return true;
43+
auto aIter = a->getIterator();
44+
auto bIter = b->getIterator();
45+
auto fIter = aBlock->begin();
46+
while (bIter != fIter) {
47+
--bIter;
48+
if (aIter == bIter)
49+
return true;
4750
}
4851

4952
return false;

lib/SILGen/SILGenStmt.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ SILBasicBlock *SILGenFunction::createBasicBlock(FunctionSection section) {
5353
// The end of the ordinary section is just the end of the function
5454
// unless postmatter blocks exist.
5555
SILBasicBlock *afterBB =
56-
(StartOfPostmatter ? StartOfPostmatter->getPrevNode() : nullptr);
56+
(StartOfPostmatter ? &*std::prev(StartOfPostmatter->getIterator())
57+
: nullptr);
5758
return new (F.getModule()) SILBasicBlock(&F, afterBB);
5859
}
5960

@@ -73,7 +74,7 @@ void SILGenFunction::eraseBasicBlock(SILBasicBlock *block) {
7374
assert(block->pred_empty() && "erasing block with predecessors");
7475
assert(block->empty() && "erasing block with content");
7576
if (block == StartOfPostmatter) {
76-
StartOfPostmatter = block->getNextNode();
77+
StartOfPostmatter = &*std::next(block->getIterator());
7778
}
7879
block->eraseFromParent();
7980
}

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,12 @@ examineAllocBoxInst(AllocBoxInst *ABI, ReachabilityInfo &RI,
802802
// Helper lambda function to determine if instruction b is strictly after
803803
// instruction a, assuming both are in the same basic block.
804804
auto isAfter = [](SILInstruction *a, SILInstruction *b) {
805-
SILInstruction *f = &*b->getParent()->begin();
806-
while (b != f) {
807-
b = b->getPrevNode();
808-
if (a == b)
805+
auto fIter = b->getParent()->begin();
806+
auto bIter = b->getIterator();
807+
auto aIter = a->getIterator();
808+
while (bIter != fIter) {
809+
--bIter;
810+
if (aIter == bIter)
809811
return true;
810812
}
811813
return false;

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
18811881
}
18821882

18831883
// Before the memory allocation, store zero in the control variable.
1884-
B.setInsertionPoint(TheMemory.MemoryInst->getNextNode());
1884+
B.setInsertionPoint(&*std::next(TheMemory.MemoryInst->getIterator()));
18851885
SILValue ControlVariableAddr = ControlVariableBox;
18861886
auto Zero = B.createIntegerLiteral(Loc, IVType, 0);
18871887
B.createStore(Loc, Zero, ControlVariableAddr);

lib/SILOptimizer/Transforms/DeadStoreElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ bool DSEContext::run() {
11421142
// Create the stores that are alive due to partial dead stores.
11431143
for (auto &I : getBlockState(&BB)->LiveStores) {
11441144
Changed = true;
1145-
SILInstruction *IT = cast<SILInstruction>(I.first)->getNextNode();
1145+
auto *IT = &*std::next(cast<SILInstruction>(I.first)->getIterator());
11461146
SILBuilderWithScope Builder(IT);
11471147
Builder.createStore(I.first.getLoc().getValue(), I.second, I.first);
11481148
}

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,7 @@ bool simplifySwitchEnumToSelectEnum(SILBasicBlock *BB, unsigned ArgNum,
30323032
// Do not replace the bbarg
30333033
SmallVector<SILValue, 4> Args;
30343034
Args.push_back(SelectInst);
3035-
B.setInsertionPoint(SelectInst->getNextNode());
3035+
B.setInsertionPoint(&*std::next(SelectInst->getIterator()));
30363036
B.createBranch(SEI->getLoc(), BB, Args);
30373037
// Remove switch_enum instruction
30383038
SEI->getParent()->getTerminator()->eraseFromParent();

0 commit comments

Comments
 (0)