Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:13

0001 //===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_ANALYSIS_ITERATEDDOMINANCEFRONTIER_H
0010 #define LLVM_ANALYSIS_ITERATEDDOMINANCEFRONTIER_H
0011 
0012 #include "llvm/Support/CFGDiff.h"
0013 #include "llvm/Support/GenericIteratedDominanceFrontier.h"
0014 
0015 namespace llvm {
0016 
0017 class BasicBlock;
0018 
0019 namespace IDFCalculatorDetail {
0020 
0021 /// Specialization for BasicBlock for the optional use of GraphDiff.
0022 template <bool IsPostDom> struct ChildrenGetterTy<BasicBlock, IsPostDom> {
0023   using NodeRef = BasicBlock *;
0024   using ChildrenTy = SmallVector<BasicBlock *, 8>;
0025 
0026   ChildrenGetterTy() = default;
0027   ChildrenGetterTy(const GraphDiff<BasicBlock *, IsPostDom> *GD) : GD(GD) {
0028     assert(GD);
0029   }
0030 
0031   ChildrenTy get(const NodeRef &N);
0032 
0033   const GraphDiff<BasicBlock *, IsPostDom> *GD = nullptr;
0034 };
0035 
0036 } // end of namespace IDFCalculatorDetail
0037 
0038 template <bool IsPostDom>
0039 class IDFCalculator final : public IDFCalculatorBase<BasicBlock, IsPostDom> {
0040 public:
0041   using IDFCalculatorBase =
0042       typename llvm::IDFCalculatorBase<BasicBlock, IsPostDom>;
0043   using ChildrenGetterTy = typename IDFCalculatorBase::ChildrenGetterTy;
0044 
0045   IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT)
0046       : IDFCalculatorBase(DT) {}
0047 
0048   IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT,
0049                 const GraphDiff<BasicBlock *, IsPostDom> *GD)
0050       : IDFCalculatorBase(DT, ChildrenGetterTy(GD)) {
0051     assert(GD);
0052   }
0053 };
0054 
0055 using ForwardIDFCalculator = IDFCalculator<false>;
0056 using ReverseIDFCalculator = IDFCalculator<true>;
0057 
0058 //===----------------------------------------------------------------------===//
0059 // Implementation.
0060 //===----------------------------------------------------------------------===//
0061 
0062 namespace IDFCalculatorDetail {
0063 
0064 template <bool IsPostDom>
0065 typename ChildrenGetterTy<BasicBlock, IsPostDom>::ChildrenTy
0066 ChildrenGetterTy<BasicBlock, IsPostDom>::get(const NodeRef &N) {
0067 
0068   using OrderedNodeTy =
0069       typename IDFCalculatorBase<BasicBlock, IsPostDom>::OrderedNodeTy;
0070 
0071   if (!GD) {
0072     auto Children = children<OrderedNodeTy>(N);
0073     return {Children.begin(), Children.end()};
0074   }
0075 
0076   return GD->template getChildren<IsPostDom>(N);
0077 }
0078 
0079 } // end of namespace IDFCalculatorDetail
0080 
0081 } // end of namespace llvm
0082 
0083 #endif