IteratedDominanceFrontier.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IteratedDominanceFrontier.h - Calculate IDF --------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ANALYSIS_ITERATEDDOMINANCEFRONTIER_H
  14. #define LLVM_ANALYSIS_ITERATEDDOMINANCEFRONTIER_H
  15. #include "llvm/Support/CFGDiff.h"
  16. #include "llvm/Support/GenericIteratedDominanceFrontier.h"
  17. namespace llvm {
  18. class BasicBlock;
  19. namespace IDFCalculatorDetail {
  20. /// Specialization for BasicBlock for the optional use of GraphDiff.
  21. template <bool IsPostDom> struct ChildrenGetterTy<BasicBlock, IsPostDom> {
  22. using NodeRef = BasicBlock *;
  23. using ChildrenTy = SmallVector<BasicBlock *, 8>;
  24. ChildrenGetterTy() = default;
  25. ChildrenGetterTy(const GraphDiff<BasicBlock *, IsPostDom> *GD) : GD(GD) {
  26. assert(GD);
  27. }
  28. ChildrenTy get(const NodeRef &N);
  29. const GraphDiff<BasicBlock *, IsPostDom> *GD = nullptr;
  30. };
  31. } // end of namespace IDFCalculatorDetail
  32. template <bool IsPostDom>
  33. class IDFCalculator final : public IDFCalculatorBase<BasicBlock, IsPostDom> {
  34. public:
  35. using IDFCalculatorBase =
  36. typename llvm::IDFCalculatorBase<BasicBlock, IsPostDom>;
  37. using ChildrenGetterTy = typename IDFCalculatorBase::ChildrenGetterTy;
  38. IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT)
  39. : IDFCalculatorBase(DT) {}
  40. IDFCalculator(DominatorTreeBase<BasicBlock, IsPostDom> &DT,
  41. const GraphDiff<BasicBlock *, IsPostDom> *GD)
  42. : IDFCalculatorBase(DT, ChildrenGetterTy(GD)) {
  43. assert(GD);
  44. }
  45. };
  46. using ForwardIDFCalculator = IDFCalculator<false>;
  47. using ReverseIDFCalculator = IDFCalculator<true>;
  48. //===----------------------------------------------------------------------===//
  49. // Implementation.
  50. //===----------------------------------------------------------------------===//
  51. namespace IDFCalculatorDetail {
  52. template <bool IsPostDom>
  53. typename ChildrenGetterTy<BasicBlock, IsPostDom>::ChildrenTy
  54. ChildrenGetterTy<BasicBlock, IsPostDom>::get(const NodeRef &N) {
  55. using OrderedNodeTy =
  56. typename IDFCalculatorBase<BasicBlock, IsPostDom>::OrderedNodeTy;
  57. if (!GD) {
  58. auto Children = children<OrderedNodeTy>(N);
  59. return {Children.begin(), Children.end()};
  60. }
  61. return GD->template getChildren<IsPostDom>(N);
  62. }
  63. } // end of namespace IDFCalculatorDetail
  64. } // end of namespace llvm
  65. #endif
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif