Skip to content

Commit babfe4c

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 implementation destroyed that loop. This is now preserved, since the incoming edges on non-header entries are not touched. 4. In the new implementation, if an irreducible cycle is a superset of a natural loop with the same header, then that natural loop is destroyed and replaced by the newly created loop.
1 parent 01beb62 commit babfe4c

File tree

9 files changed

+344
-351
lines changed

9 files changed

+344
-351
lines changed

llvm/include/llvm/ADT/GenericCycleInfo.h

+27-6
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

@@ -192,6 +198,21 @@ template <typename ContextT> class GenericCycle {
192198
//@{
193199
using const_entry_iterator =
194200
typename SmallVectorImpl<BlockT *>::const_iterator;
201+
const_entry_iterator entry_begin() const {
202+
return const_entry_iterator{Entries.begin()};
203+
}
204+
const_entry_iterator entry_end() const {
205+
return const_entry_iterator{Entries.end()};
206+
}
207+
208+
using const_reverse_entry_iterator =
209+
typename SmallVectorImpl<BlockT *>::const_reverse_iterator;
210+
const_reverse_entry_iterator entry_rbegin() const {
211+
return const_reverse_entry_iterator{Entries.rbegin()};
212+
}
213+
const_reverse_entry_iterator entry_rend() const {
214+
return const_reverse_entry_iterator{Entries.rend()};
215+
}
195216

196217
size_t getNumEntries() const { return Entries.size(); }
197218
iterator_range<const_entry_iterator> entries() const {
@@ -255,12 +276,6 @@ template <typename ContextT> class GenericCycleInfo {
255276
/// the subtree.
256277
void moveTopLevelCycleToNewParent(CycleT *NewParent, CycleT *Child);
257278

258-
/// Assumes that \p Cycle is the innermost cycle containing \p Block.
259-
/// \p Block will be appended to \p Cycle and all of its parent cycles.
260-
/// \p Block will be added to BlockMap with \p Cycle and
261-
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
262-
void addBlockToCycle(BlockT *Block, CycleT *Cycle);
263-
264279
public:
265280
GenericCycleInfo() = default;
266281
GenericCycleInfo(GenericCycleInfo &&) = default;
@@ -278,6 +293,12 @@ template <typename ContextT> class GenericCycleInfo {
278293
unsigned getCycleDepth(const BlockT *Block) const;
279294
CycleT *getTopLevelParentCycle(BlockT *Block);
280295

296+
/// Assumes that \p Cycle is the innermost cycle containing \p Block.
297+
/// \p Block will be appended to \p Cycle and all of its parent cycles.
298+
/// \p Block will be added to BlockMap with \p Cycle and
299+
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
300+
void addBlockToCycle(BlockT *Block, CycleT *Cycle);
301+
281302
/// Methods for debug and self-test.
282303
//@{
283304
void verifyCycleNest(bool VerifyFull = false) const;

0 commit comments

Comments
 (0)