Skip to content

Commit c60ea06

Browse files
committed
[FixIrreducible] Use CycleInfo instead of a custom SCC traversal
1. CycleInfo efficiently locates all cycles in a single pass, while the SCC is repeated inside every natural loop. 2. CycleInfo provides a hierarchy of irreducible cycles, and the new implementation transforms each cycle in this hierarchy separately instead of reducing an entire irreducible SCC in a single step. This reduces the number of control-flow paths that pass through the header of each newly created loop. This is evidenced by the reduced number of predecessors on the "guard" blocks in the lit tests, and fewer operands on the corresponding PHI nodes. 3. When an entry of an irreducible cycle is the header of a child natural loop, the original impleementation destroyed that loop. This is now preserved, since the incoming edges on non-header entries are not touched.
1 parent d0b4b6b commit c60ea06

File tree

9 files changed

+350
-349
lines changed

9 files changed

+350
-349
lines changed

llvm/include/llvm/ADT/GenericCycleInfo.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ template <typename ContextT> class GenericCycle {
107107
return is_contained(Entries, Block);
108108
}
109109

110+
/// \brief Replace all entries with \p Block as single entry.
111+
void setSingleEntry(BlockT *Block) {
112+
Entries.clear();
113+
Entries.push_back(Block);
114+
}
115+
110116
/// \brief Return whether \p Block is contained in the cycle.
111117
bool contains(const BlockT *Block) const { return Blocks.contains(Block); }
112118

@@ -189,6 +195,21 @@ template <typename ContextT> class GenericCycle {
189195
//@{
190196
using const_entry_iterator =
191197
typename SmallVectorImpl<BlockT *>::const_iterator;
198+
const_entry_iterator entry_begin() const {
199+
return const_entry_iterator{Entries.begin()};
200+
}
201+
const_entry_iterator entry_end() const {
202+
return const_entry_iterator{Entries.end()};
203+
}
204+
205+
using const_reverse_entry_iterator =
206+
typename SmallVectorImpl<BlockT *>::const_reverse_iterator;
207+
const_reverse_entry_iterator entry_rbegin() const {
208+
return const_reverse_entry_iterator{Entries.rbegin()};
209+
}
210+
const_reverse_entry_iterator entry_rend() const {
211+
return const_reverse_entry_iterator{Entries.rend()};
212+
}
192213

193214
size_t getNumEntries() const { return Entries.size(); }
194215
iterator_range<const_entry_iterator> entries() const {
@@ -252,12 +273,6 @@ template <typename ContextT> class GenericCycleInfo {
252273
/// the subtree.
253274
void moveTopLevelCycleToNewParent(CycleT *NewParent, CycleT *Child);
254275

255-
/// Assumes that \p Cycle is the innermost cycle containing \p Block.
256-
/// \p Block will be appended to \p Cycle and all of its parent cycles.
257-
/// \p Block will be added to BlockMap with \p Cycle and
258-
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
259-
void addBlockToCycle(BlockT *Block, CycleT *Cycle);
260-
261276
public:
262277
GenericCycleInfo() = default;
263278
GenericCycleInfo(GenericCycleInfo &&) = default;
@@ -275,6 +290,12 @@ template <typename ContextT> class GenericCycleInfo {
275290
unsigned getCycleDepth(const BlockT *Block) const;
276291
CycleT *getTopLevelParentCycle(BlockT *Block);
277292

293+
/// Assumes that \p Cycle is the innermost cycle containing \p Block.
294+
/// \p Block will be appended to \p Cycle and all of its parent cycles.
295+
/// \p Block will be added to BlockMap with \p Cycle and
296+
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
297+
void addBlockToCycle(BlockT *Block, CycleT *Cycle);
298+
278299
/// Methods for debug and self-test.
279300
//@{
280301
#ifndef NDEBUG

0 commit comments

Comments
 (0)