Skip to content

Commit 1c844ed

Browse files
committed
SIL: remove dangerous SILBasicBlock APIs
`isSuccessorBlock` and `isPredecessorBlock` are dangerous because they can easily lead to quadratic behavior. Fortunately they are not used anywhere (except in one place for verification, which I rewrote).
1 parent cc10417 commit 1c844ed

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,6 @@ public SwiftObjectHeader {
427427
return getTerminator()->getSingleSuccessorBlock();
428428
}
429429

430-
/// Returns true if \p BB is a successor of this block.
431-
bool isSuccessorBlock(SILBasicBlock *Block) const {
432-
return getTerminator()->isSuccessorBlock(Block);
433-
}
434-
435430
using SuccessorBlockListTy = TermInst::SuccessorBlockListTy;
436431
using ConstSuccessorBlockListTy = TermInst::ConstSuccessorBlockListTy;
437432

@@ -459,12 +454,6 @@ public SwiftObjectHeader {
459454
return {pred_begin(), pred_end()};
460455
}
461456

462-
bool isPredecessorBlock(SILBasicBlock *BB) const {
463-
return any_of(
464-
getPredecessorBlocks(),
465-
[&BB](const SILBasicBlock *PredBB) -> bool { return BB == PredBB; });
466-
}
467-
468457
SILBasicBlock *getSinglePredecessorBlock() {
469458
if (pred_empty() || std::next(pred_begin()) != pred_end())
470459
return nullptr;

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8940,14 +8940,6 @@ class TermInst : public NonValueInstruction {
89408940
return const_cast<TermInst *>(this)->getSingleSuccessorBlock();
89418941
}
89428942

8943-
/// Returns true if \p BB is a successor of this block.
8944-
bool isSuccessorBlock(SILBasicBlock *BB) const {
8945-
auto Range = getSuccessorBlocks();
8946-
return any_of(Range, [&BB](const SILBasicBlock *SuccBB) -> bool {
8947-
return BB == SuccBB;
8948-
});
8949-
}
8950-
89518943
using SuccessorBlockArgumentListTy =
89528944
TransformRange<ConstSuccessorListTy, function_ref<ArrayRef<SILArgument *>(
89538945
const SILSuccessor &)>>;

lib/SILOptimizer/Analysis/LoopRegionAnalysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ void LoopRegionFunctionInfo::verify() {
218218

219219
// If R and OtherR are blocks, then OtherR should be a successor of the
220220
// real block.
221-
if (R->isBlock() && OtherR->isBlock())
222-
assert(R->getBlock()->isSuccessorBlock(OtherR->getBlock()) &&
221+
if (R->isBlock() && OtherR->isBlock()) {
222+
auto succs = R->getBlock()->getSuccessors();
223+
assert(std::find(succs.begin(), succs.end(), OtherR->getBlock()) != succs.end() &&
223224
"Expected either R was not a block or OtherR was a CFG level "
224225
"successor of R.");
226+
}
225227
}
226228
}
227229
#endif

0 commit comments

Comments
 (0)