Skip to content

[FixIrreducible] Use CycleInfo instead of a custom SCC traversal #101386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions llvm/include/llvm/ADT/GenericCycleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ template <typename ContextT> class GenericCycle {
return is_contained(Entries, Block);
}

/// \brief Replace all entries with \p Block as single entry.
void setSingleEntry(BlockT *Block) {
assert(contains(Block));
Entries.clear();
Entries.push_back(Block);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be nullptr? Should we add an assert to guard against this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Replaced it with a stronger test to check that Block is contained in the current cycle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

/// \brief Return whether \p Block is contained in the cycle.
bool contains(const BlockT *Block) const { return Blocks.contains(Block); }

Expand Down Expand Up @@ -192,11 +199,16 @@ template <typename ContextT> class GenericCycle {
//@{
using const_entry_iterator =
typename SmallVectorImpl<BlockT *>::const_iterator;

const_entry_iterator entry_begin() const { return Entries.begin(); }
const_entry_iterator entry_end() const { return Entries.end(); }
size_t getNumEntries() const { return Entries.size(); }
iterator_range<const_entry_iterator> entries() const {
return llvm::make_range(Entries.begin(), Entries.end());
return llvm::make_range(entry_begin(), entry_end());
}
using const_reverse_entry_iterator =
typename SmallVectorImpl<BlockT *>::const_reverse_iterator;
const_reverse_entry_iterator entry_rbegin() const { return Entries.rbegin(); }
const_reverse_entry_iterator entry_rend() const { return Entries.rend(); }
//@}

Printable printEntries(const ContextT &Ctx) const {
Expand Down Expand Up @@ -255,12 +267,6 @@ template <typename ContextT> class GenericCycleInfo {
/// the subtree.
void moveTopLevelCycleToNewParent(CycleT *NewParent, CycleT *Child);

/// Assumes that \p Cycle is the innermost cycle containing \p Block.
/// \p Block will be appended to \p Cycle and all of its parent cycles.
/// \p Block will be added to BlockMap with \p Cycle and
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
void addBlockToCycle(BlockT *Block, CycleT *Cycle);

public:
GenericCycleInfo() = default;
GenericCycleInfo(GenericCycleInfo &&) = default;
Expand All @@ -278,6 +284,12 @@ template <typename ContextT> class GenericCycleInfo {
unsigned getCycleDepth(const BlockT *Block) const;
CycleT *getTopLevelParentCycle(BlockT *Block);

/// Assumes that \p Cycle is the innermost cycle containing \p Block.
/// \p Block will be appended to \p Cycle and all of its parent cycles.
/// \p Block will be added to BlockMap with \p Cycle and
/// BlockMapTopLevel with \p Cycle's top level parent cycle.
void addBlockToCycle(BlockT *Block, CycleT *Cycle);

/// Methods for debug and self-test.
//@{
void verifyCycleNest(bool VerifyFull = false) const;
Expand Down
Loading
Loading