//===- GenericDomTreeConstruction.h - Dominator Calculation ------*- C++ -*-==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file /// /// Generic dominator tree construction - this file provides routines to /// construct immediate dominator information for a flow-graph based on the /// Semi-NCA algorithm described in this dissertation: /// /// [1] Linear-Time Algorithms for Dominators and Related Problems /// Loukas Georgiadis, Princeton University, November 2005, pp. 21-23: /// ftp://ftp.cs.princeton.edu/reports/2005/737.pdf /// /// Semi-NCA algorithm runs in O(n^2) worst-case time but usually slightly /// faster than Simple Lengauer-Tarjan in practice. /// /// O(n^2) worst cases happen when the computation of nearest common ancestors /// requires O(n) average time, which is very unlikely in real world. If this /// ever turns out to be an issue, consider implementing a hybrid algorithm /// that uses SLT to perform full constructions and SemiNCA for incremental /// updates. /// /// The file uses the Depth Based Search algorithm to perform incremental /// updates (insertion and deletions). The implemented algorithm is based on /// this publication: /// /// [2] An Experimental Study of Dynamic Dominators /// Loukas Georgiadis, et al., April 12 2016, pp. 5-7, 9-10: /// https://arxiv.org/pdf/1604.02711.pdf /// //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_GENERICDOMTREECONSTRUCTION_H #define LLVM_SUPPORT_GENERICDOMTREECONSTRUCTION_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GenericDomTree.h" #include <optional> #include <queue> #define DEBUG_TYPE … namespace llvm { namespace DomTreeBuilder { template <typename DomTreeT> struct SemiNCAInfo { … }; template <class DomTreeT> void Calculate(DomTreeT &DT) { … } template <typename DomTreeT> void CalculateWithUpdates(DomTreeT &DT, ArrayRef<typename DomTreeT::UpdateType> Updates) { … } template <class DomTreeT> void InsertEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To) { … } template <class DomTreeT> void DeleteEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To) { … } template <class DomTreeT> void ApplyUpdates(DomTreeT &DT, GraphDiff<typename DomTreeT::NodePtr, DomTreeT::IsPostDominator> &PreViewCFG, GraphDiff<typename DomTreeT::NodePtr, DomTreeT::IsPostDominator> *PostViewCFG) { … } template <class DomTreeT> bool Verify(const DomTreeT &DT, typename DomTreeT::VerificationLevel VL) { … } } // namespace DomTreeBuilder } // namespace llvm #undef DEBUG_TYPE #endif