MachinePostDominators.h 2.9 KB

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