Skip to content

Commit 7f47041

Browse files
committed
Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
There was churn upstream on ilist_node 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.
1 parent 40a89cb commit 7f47041

File tree

7 files changed

+37
-28
lines changed

7 files changed

+37
-28
lines changed

lib/IRGen/IRGenSIL.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -1306,13 +1306,13 @@ void IRGenSILFunction::emitSILFunction() {
13061306
// Map the entry bb.
13071307
LoweredBBs[&*CurSILFn->begin()] = LoweredBB(&*CurFn->begin(), {});
13081308
// Create LLVM basic blocks for the other bbs.
1309-
for (SILBasicBlock *bb = CurSILFn->begin()->getNextNode();
1310-
bb != CurSILFn->end(); bb = bb->getNextNode()) {
1309+
for (auto bi = std::next(CurSILFn->begin()), be = CurSILFn->end(); bi != be;
1310+
++bi) {
13111311
// FIXME: Use the SIL basic block's name.
13121312
llvm::BasicBlock *llBB = llvm::BasicBlock::Create(IGM.getLLVMContext());
1313-
auto phis = emitPHINodesForBBArgs(*this, bb, llBB);
1313+
auto phis = emitPHINodesForBBArgs(*this, &*bi, llBB);
13141314
CurFn->getBasicBlockList().push_back(llBB);
1315-
LoweredBBs[bb] = LoweredBB(llBB, std::move(phis));
1315+
LoweredBBs[&*bi] = LoweredBB(llBB, std::move(phis));
13161316
}
13171317

13181318
auto entry = LoweredBBs.begin();
@@ -3311,18 +3311,21 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
33113311
// if the alloc_stack is dominated by copy_addrs into it on all paths.
33123312
// For now, check only that the copy_addr is the first use within the same
33133313
// block.
3314-
const SILInstruction *inst = allocInst;
3315-
while ((inst = inst->getNextNode()) && !isa<TermInst>(inst)) {
3316-
// Does this instruction use the allocation?
3317-
for (auto &operand : inst->getAllOperands())
3318-
if (operand.get() == addressValue)
3319-
goto is_use;
3320-
3321-
continue;
3322-
3323-
is_use:
3314+
for (auto ii = std::next(allocInst->getIterator()),
3315+
ie = std::prev(allocInst->getParent()->end());
3316+
ii != ie; ++ii) {
3317+
auto *inst = &*ii;
3318+
3319+
// Does this instruction use the allocation? If not, continue.
3320+
auto Ops = inst->getAllOperands();
3321+
if (std::none_of(Ops.begin(), Ops.end(),
3322+
[&addressValue](const Operand &Op) {
3323+
return Op.get() == addressValue;
3324+
}))
3325+
continue;
3326+
33243327
// Is this a copy?
3325-
auto copy = dyn_cast<swift::CopyAddrInst>(inst);
3328+
auto *copy = dyn_cast<swift::CopyAddrInst>(inst);
33263329
if (!copy)
33273330
return false;
33283331

lib/SIL/Dominance.cpp

+7-4
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

+3-2
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/SILPasses/EarlySIL/DefiniteInitialization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
18251825
}
18261826

18271827
// Before the memory allocation, store zero in the control variable.
1828-
B.setInsertionPoint(TheMemory.MemoryInst->getNextNode());
1828+
B.setInsertionPoint(&*std::next(TheMemory.MemoryInst->getIterator()));
18291829
SILValue ControlVariableAddr = SILValue(ControlVariableBox, 1);
18301830
auto Zero = B.createIntegerLiteral(Loc, IVType, 0);
18311831
B.createStore(Loc, Zero, ControlVariableAddr);

lib/SILPasses/IPO/CapturePromotion.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,12 @@ examineAllocBoxInst(AllocBoxInst *ABI, ReachabilityInfo &RI,
778778
// Helper lambda function to determine if instruction b is strictly after
779779
// instruction a, assuming both are in the same basic block.
780780
auto isAfter = [](SILInstruction *a, SILInstruction *b) {
781-
SILInstruction *f = &*b->getParent()->begin();
782-
while (b != f) {
783-
b = b->getPrevNode();
784-
if (a == b)
781+
auto fIter = b->getParent()->begin();
782+
auto bIter = b->getIterator();
783+
auto aIter = a->getIterator();
784+
while (bIter != fIter) {
785+
--bIter;
786+
if (aIter == bIter)
785787
return true;
786788
}
787789
return false;

lib/SILPasses/Scalar/DeadStoreElimination.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ void DSEContext::run() {
881881
for (SILBasicBlock &BB : *F) {
882882
// Create the stores that are alive.
883883
for (auto &I : getBBLocState(&BB)->LiveStores) {
884-
SILInstruction *IT = cast<SILInstruction>(I.first)->getNextNode();
884+
auto *IT = &*std::next(cast<SILInstruction>(I.first)->getIterator());
885885
SILBuilderWithScope Builder(IT);
886886
Builder.createStore(I.first.getLoc().getValue(), I.second, I.first);
887887
}

lib/SILPasses/Scalar/SimplifyCFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3013,7 +3013,7 @@ bool simplifySwitchEnumToSelectEnum(SILBasicBlock *BB, unsigned ArgNum,
30133013
// Do not replace the bbarg
30143014
SmallVector<SILValue, 4> Args;
30153015
Args.push_back(SelectInst);
3016-
B.setInsertionPoint(SelectInst->getNextNode());
3016+
B.setInsertionPoint(&*std::next(SelectInst->getIterator()));
30173017
B.createBranch(SEI->getLoc(), BB, Args);
30183018
// Remove switch_enum instruction
30193019
SEI->getParent()->getTerminator()->eraseFromParent();

0 commit comments

Comments
 (0)