6 #ifndef JLM_LLVM_OPT_ALIAS_ANALYSES_ONLINECYCLEDETECTION_HPP
7 #define JLM_LLVM_OPT_ALIAS_ANALYSES_ONLINECYCLEDETECTION_HPP
26 template<
typename GetSuccessorsFunctor,
typename UnifyPo
interObjectsFunctor>
33 const GetSuccessorsFunctor & GetSuccessors,
34 const UnifyPointerObjectsFunctor & UnifyPointerObjects)
56 std::vector<PointerObjectIndex> sccIndex;
57 std::vector<PointerObjectIndex> reverseTopologicalOrder;
65 util::FindStronglyConnectedComponents<PointerObjectIndex>(
70 reverseTopologicalOrder);
74 for (
auto it = reverseTopologicalOrder.rbegin(); it != reverseTopologicalOrder.rend(); ++it)
79 if (
const auto nextIt = it + 1;
80 nextIt != reverseTopologicalOrder.rend() && sccIndex[*it] == sccIndex[*nextIt])
106 std::optional<PointerObjectIndex>
132 const bool isFirstVisit = !
DfsStack_.top().second;
162 if (topo < lowerTopo || topo > upperTopo)
166 DfsStack_.emplace(successorParent,
false);
193 std::optional<PointerObjectIndex> optUnificationRoot = std::nullopt;
220 auto nextTopologicalIndex = lowerTopo;
221 for (
auto i = lowerTopo; i <= upperTopo; i++)
242 nextTopologicalIndex++;
252 nextTopologicalIndex++;
256 while (nextTopologicalIndex <= upperTopo)
259 nextTopologicalIndex++;
265 return optUnificationRoot;
318 if (successorRoot == node)
332 if (backReference != i)
395 std::numeric_limits<PointerObjectIndex>::max();
411 std::stack<std::pair<PointerObjectIndex, bool>>
DfsStack_;
std::vector< PointerObjectIndex > ObjectToTopoOrder_
static constexpr PointerObjectIndex EmptyTopologicalSlot
size_t NumOnlineCycleUnifications_
const GetSuccessorsFunctor & GetSuccessors_
size_t NumOnlineCyclesDetected() const noexcept
bool ComesAfter(PointerObjectIndex after, PointerObjectIndex before) const
std::stack< std::pair< PointerObjectIndex, bool > > DfsStack_
util::HashSet< PointerObjectIndex > DfsCycleNodes_
OnlineCycleDetector(PointerObjectSet &set, const GetSuccessorsFunctor &GetSuccessors, const UnifyPointerObjectsFunctor &UnifyPointerObjects)
std::optional< PointerObjectIndex > MaintainTopologicalOrder(PointerObjectIndex subset, PointerObjectIndex superset)
std::vector< PointerObjectIndex > TopoOrderToObject_
bool IsTopologicalOrderIndexFilled(PointerObjectIndex topologicalIndex) const
const UnifyPointerObjectsFunctor & UnifyPointerObjects_
util::HashSet< PointerObjectIndex > DfsNodesVisited_
std::vector< PointerObjectIndex > DfsSupersetAndBeyond_
bool HasValidTopologicalOrder() const
size_t NumOnlineCyclesDetected_
void InitializeTopologicalOrdering()
size_t NumOnlineCycleUnifications() const noexcept
bool ObjectIsInTopologicalOrder(PointerObjectIndex object) const
PointerObjectIndex GetUnificationRoot(PointerObjectIndex index) const noexcept
bool IsUnificationRoot(PointerObjectIndex index) const noexcept
size_t NumPointerObjects() const noexcept
bool insert(ItemType item)
std::size_t Size() const noexcept
bool Contains(const ItemType &item) const noexcept
IteratorRange< ItemConstIterator > Items() const noexcept
bool IsEmpty() const noexcept
uint32_t PointerObjectIndex