//===- IteratedDominanceFrontier.h - Calculate IDF --------------*- 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 // //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_IDF_H #define LLVM_ANALYSIS_IDF_H #include "llvm/Support/CFGDiff.h" #include "llvm/Support/GenericIteratedDominanceFrontier.h" namespace llvm { class BasicBlock; namespace IDFCalculatorDetail { /// Specialization for BasicBlock for the optional use of GraphDiff. template struct ChildrenGetterTy { using NodeRef = BasicBlock *; using ChildrenTy = SmallVector; ChildrenGetterTy() = default; ChildrenGetterTy(const GraphDiff *GD) : GD(GD) { assert(GD); } ChildrenTy get(const NodeRef &N); const GraphDiff *GD = nullptr; }; } // end of namespace IDFCalculatorDetail template class IDFCalculator final : public IDFCalculatorBase { public: using IDFCalculatorBase = typename llvm::IDFCalculatorBase; using ChildrenGetterTy = typename IDFCalculatorBase::ChildrenGetterTy; IDFCalculator(DominatorTreeBase &DT) : IDFCalculatorBase(DT) {} IDFCalculator(DominatorTreeBase &DT, const GraphDiff *GD) : IDFCalculatorBase(DT, ChildrenGetterTy(GD)) { assert(GD); } }; using ForwardIDFCalculator = IDFCalculator; using ReverseIDFCalculator = IDFCalculator; //===----------------------------------------------------------------------===// // Implementation. //===----------------------------------------------------------------------===// namespace IDFCalculatorDetail { template typename ChildrenGetterTy::ChildrenTy ChildrenGetterTy::get(const NodeRef &N) { using OrderedNodeTy = typename IDFCalculatorBase::OrderedNodeTy; if (!GD) { auto Children = children(N); return {Children.begin(), Children.end()}; } return GD->template getChildren(N); } } // end of namespace IDFCalculatorDetail } // end of namespace llvm #endif