[DWARF] Fix referencing Range List Tables from CUs for DWARF64.
[llvm-complete.git] / include / llvm / Analysis / IteratedDominanceFrontier.h
blob7c826780c3185fe0c323c165312a5d5ed228f8ce
1 //===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_ANALYSIS_IDF_H
10 #define LLVM_ANALYSIS_IDF_H
12 #include "llvm/IR/CFGDiff.h"
13 #include "llvm/Support/GenericIteratedDominanceFrontier.h"
15 namespace llvm {
17 class BasicBlock;
19 namespace IDFCalculatorDetail {
21 /// Specialization for BasicBlock for the optional use of GraphDiff.
22 template <bool IsPostDom> struct ChildrenGetterTy<BasicBlock, IsPostDom> {
23 using NodeRef = BasicBlock *;
24 using ChildrenTy = SmallVector<BasicBlock *, 8>;
26 ChildrenGetterTy() = default;
27 ChildrenGetterTy(const GraphDiff<BasicBlock *, IsPostDom> *GD) : GD(GD) {
28 assert(GD);
31 ChildrenTy get(const NodeRef &N);
33 const GraphDiff<BasicBlock *, IsPostDom> *GD = nullptr;
36 } // end of namespace IDFCalculatorDetail
38 template <bool IsPostDom>
39 class IDFCalculator final : public IDFCalculatorBase<BasicBlock, IsPostDom> {
40 public:
41 using IDFCalculatorBase =
42 typename llvm::IDFCalculatorBase<BasicBlock, IsPostDom>;
43 using ChildrenGetterTy = typename IDFCalculatorBase::ChildrenGetterTy;
45 IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT)
46 : IDFCalculatorBase(DT) {}
48 IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT,
49 const GraphDiff<BasicBlock *, IsPostDom> *GD)
50 : IDFCalculatorBase(DT, ChildrenGetterTy(GD)) {
51 assert(GD);
55 using ForwardIDFCalculator = IDFCalculator<false>;
56 using ReverseIDFCalculator = IDFCalculator<true>;
58 //===----------------------------------------------------------------------===//
59 // Implementation.
60 //===----------------------------------------------------------------------===//
62 namespace IDFCalculatorDetail {
64 template <bool IsPostDom>
65 typename ChildrenGetterTy<BasicBlock, IsPostDom>::ChildrenTy
66 ChildrenGetterTy<BasicBlock, IsPostDom>::get(const NodeRef &N) {
68 using OrderedNodeTy =
69 typename IDFCalculatorBase<BasicBlock, IsPostDom>::OrderedNodeTy;
71 if (!GD) {
72 auto Children = children<OrderedNodeTy>(N);
73 return {Children.begin(), Children.end()};
76 using SnapShotBBPairTy =
77 std::pair<const GraphDiff<BasicBlock *, IsPostDom> *, OrderedNodeTy>;
79 ChildrenTy Ret;
80 for (const auto &SnapShotBBPair : children<SnapShotBBPairTy>({GD, N}))
81 Ret.emplace_back(SnapShotBBPair.second);
82 return Ret;
85 } // end of namespace IDFCalculatorDetail
87 } // end of namespace llvm
89 #endif