MachinePostDominators.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/MachinePostDominators.h ----------------------*- 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. //
  14. // This file exposes interfaces to post dominance information for
  15. // target-specific code.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H
  19. #define LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H
  20. #include "llvm/CodeGen/MachineDominators.h"
  21. #include "llvm/CodeGen/MachineFunctionPass.h"
  22. #include <memory>
  23. namespace llvm {
  24. ///
  25. /// MachinePostDominatorTree - an analysis pass wrapper for DominatorTree
  26. /// used to compute the post-dominator tree for MachineFunctions.
  27. ///
  28. class MachinePostDominatorTree : public MachineFunctionPass {
  29. using PostDomTreeT = PostDomTreeBase<MachineBasicBlock>;
  30. std::unique_ptr<PostDomTreeT> PDT;
  31. public:
  32. static char ID;
  33. MachinePostDominatorTree();
  34. PostDomTreeT &getBase() {
  35. if (!PDT)
  36. PDT.reset(new PostDomTreeT());
  37. return *PDT;
  38. }
  39. FunctionPass *createMachinePostDominatorTreePass();
  40. MachineDomTreeNode *getRootNode() const { return PDT->getRootNode(); }
  41. MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
  42. return PDT->getNode(BB);
  43. }
  44. MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
  45. return PDT->getNode(BB);
  46. }
  47. bool dominates(const MachineDomTreeNode *A,
  48. const MachineDomTreeNode *B) const {
  49. return PDT->dominates(A, B);
  50. }
  51. bool dominates(const MachineBasicBlock *A, const MachineBasicBlock *B) const {
  52. return PDT->dominates(A, B);
  53. }
  54. bool properlyDominates(const MachineDomTreeNode *A,
  55. const MachineDomTreeNode *B) const {
  56. return PDT->properlyDominates(A, B);
  57. }
  58. bool properlyDominates(const MachineBasicBlock *A,
  59. const MachineBasicBlock *B) const {
  60. return PDT->properlyDominates(A, B);
  61. }
  62. bool isVirtualRoot(const MachineDomTreeNode *Node) const {
  63. return PDT->isVirtualRoot(Node);
  64. }
  65. MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
  66. MachineBasicBlock *B) const {
  67. return PDT->findNearestCommonDominator(A, B);
  68. }
  69. /// Returns the nearest common dominator of the given blocks.
  70. /// If that tree node is a virtual root, a nullptr will be returned.
  71. MachineBasicBlock *
  72. findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
  73. bool runOnMachineFunction(MachineFunction &MF) override;
  74. void getAnalysisUsage(AnalysisUsage &AU) const override;
  75. void releaseMemory() override { PDT.reset(nullptr); }
  76. void verifyAnalysis() const override;
  77. void print(llvm::raw_ostream &OS, const Module *M = nullptr) const override;
  78. };
  79. } //end of namespace llvm
  80. #endif
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif