Skip to content

Commit 913920c

Browse files
committed
[sil] Rename SILSuccessorIterator -> SILSuccessor::pred_iterator.
This iterator is not actually a SILSuccessorIterator since it is not iterating over the "successors" of a block. Instead it is used to given the head of a CFG edge, iterate over the CFG edge's predecessors using the double linked list stored inside SILSuccessor. This rename/refactor ties SILSuccessor closer to SILSuccessorIterator and makes it clear what we are actually iterating over.
1 parent 3ab6604 commit 913920c

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
286286
return makeTransformRange(getSuccessors(), F);
287287
}
288288

289-
using pred_iterator = SILSuccessorIterator;
289+
using pred_iterator = SILSuccessor::pred_iterator;
290290

291291
bool pred_empty() const { return PredList == nullptr; }
292292
pred_iterator pred_begin() const { return pred_iterator(PredList); }

include/swift/SIL/SILSuccessor.h

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class TermInst;
3434
/// predecessors. This is done by using an ilist that is embedded into
3535
/// SILSuccessors.
3636
class SILSuccessor {
37-
friend class SILSuccessorIterator;
38-
3937
/// The terminator instruction that contains this SILSuccessor.
4038
TermInst *ContainingInst = nullptr;
4139

@@ -78,41 +76,40 @@ class SILSuccessor {
7876
// Do not copy or move these.
7977
SILSuccessor(const SILSuccessor &) = delete;
8078
SILSuccessor(SILSuccessor &&) = delete;
81-
};
82-
83-
/// SILSuccessorIterator - This is an iterator for walking the successor list of
84-
/// a SILBasicBlock.
85-
class SILSuccessorIterator {
86-
SILSuccessor *Cur;
87-
public:
88-
using difference_type = std::ptrdiff_t;
89-
using value_type = SILBasicBlock *;
90-
using pointer = SILBasicBlock **;
91-
using reference = SILBasicBlock *&;
92-
using iterator_category = std::forward_iterator_tag;
93-
94-
SILSuccessorIterator(SILSuccessor *Cur = 0) : Cur(Cur) {}
95-
96-
bool operator==(SILSuccessorIterator I2) const { return Cur == I2.Cur; }
97-
bool operator!=(SILSuccessorIterator I2) const { return Cur != I2.Cur; }
9879

99-
SILSuccessorIterator &operator++() {
100-
assert(Cur && "Trying to advance past end");
101-
Cur = Cur->Next;
102-
return *this;
103-
}
104-
105-
SILSuccessorIterator operator++(int) {
106-
SILSuccessorIterator copy = *this;
107-
++*this;
108-
return copy;
109-
}
110-
111-
SILSuccessor *getSuccessorRef() const { return Cur; }
112-
SILBasicBlock *operator*();
113-
const SILBasicBlock *operator*() const;
80+
/// This is an iterator for walking the predecessor list of a SILBasicBlock.
81+
class pred_iterator {
82+
SILSuccessor *Cur;
83+
84+
public:
85+
using difference_type = std::ptrdiff_t;
86+
using value_type = SILBasicBlock *;
87+
using pointer = SILBasicBlock **;
88+
using reference = SILBasicBlock *&;
89+
using iterator_category = std::forward_iterator_tag;
90+
91+
pred_iterator(SILSuccessor *Cur = 0) : Cur(Cur) {}
92+
93+
bool operator==(pred_iterator I2) const { return Cur == I2.Cur; }
94+
bool operator!=(pred_iterator I2) const { return Cur != I2.Cur; }
95+
96+
pred_iterator &operator++() {
97+
assert(Cur && "Trying to advance past end");
98+
Cur = Cur->Next;
99+
return *this;
100+
}
101+
102+
pred_iterator operator++(int) {
103+
pred_iterator copy = *this;
104+
++*this;
105+
return copy;
106+
}
107+
108+
SILSuccessor *getSuccessorRef() const { return Cur; }
109+
SILBasicBlock *operator*();
110+
const SILBasicBlock *operator*() const;
111+
};
114112
};
115-
116113

117114
} // end swift namespace
118115

lib/SIL/SILSuccessor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ void SILSuccessor::operator=(SILBasicBlock *BB) {
3838
SuccessorBlock = BB;
3939
}
4040

41-
// Dereferencing the SuccIterator returns the predecessor's SILBasicBlock.
42-
SILBasicBlock *SILSuccessorIterator::operator*() {
41+
// Dereferencing the pred_iterator returns the predecessor's SILBasicBlock.
42+
SILBasicBlock *SILSuccessor::pred_iterator::operator*() {
4343
assert(Cur && "Can't deference end (or default constructed) iterator");
4444
return Cur->ContainingInst->getParent();
4545
}
4646

47-
// Dereferencing the SuccIterator returns the predecessor's SILBasicBlock.
48-
const SILBasicBlock *SILSuccessorIterator::operator*() const {
47+
// Dereferencing the pred_iterator returns the predecessor's SILBasicBlock.
48+
const SILBasicBlock *SILSuccessor::pred_iterator::operator*() const {
4949
assert(Cur && "Can't deference end (or default constructed) iterator");
5050
return Cur->ContainingInst->getParent();
5151
}

0 commit comments

Comments
 (0)