//===- llvm/CodeGen/MachinePostDominators.h ----------------------*- C++ -*-==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file exposes interfaces to post dominance information for // target-specific code. // //===----------------------------------------------------------------------===// #ifndef LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H #define LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H #include "llvm/CodeGen/MachineDominators.h" namespace llvm { extern template class DominatorTreeBase; // PostDomTree namespace DomTreeBuilder { using MBBPostDomTree = PostDomTreeBase; using MBBPostDomTreeGraphDiff = GraphDiff; extern template void Calculate(MBBPostDomTree &DT); extern template void InsertEdge(MBBPostDomTree &DT, MachineBasicBlock *From, MachineBasicBlock *To); extern template void DeleteEdge(MBBPostDomTree &DT, MachineBasicBlock *From, MachineBasicBlock *To); extern template void ApplyUpdates(MBBPostDomTree &DT, MBBPostDomTreeGraphDiff &, MBBPostDomTreeGraphDiff *); extern template bool Verify(const MBBPostDomTree &DT, MBBPostDomTree::VerificationLevel VL); } // namespace DomTreeBuilder /// /// MachinePostDominatorTree - an analysis pass wrapper for DominatorTree /// used to compute the post-dominator tree for MachineFunctions. /// class MachinePostDominatorTree : public PostDomTreeBase { using Base = PostDomTreeBase; public: MachinePostDominatorTree() = default; explicit MachinePostDominatorTree(MachineFunction &MF) { recalculate(MF); } /// Handle invalidation explicitly. bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &); /// Make findNearestCommonDominator(const NodeT *A, const NodeT *B) available. using Base::findNearestCommonDominator; /// Returns the nearest common dominator of the given blocks. /// If that tree node is a virtual root, a nullptr will be returned. MachineBasicBlock * findNearestCommonDominator(ArrayRef Blocks) const; }; class MachinePostDominatorTreeAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; static AnalysisKey Key; public: using Result = MachinePostDominatorTree; Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); }; class MachinePostDominatorTreePrinterPass : public PassInfoMixin { raw_ostream &OS; public: explicit MachinePostDominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {} PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); static bool isRequired() { return true; } }; class MachinePostDominatorTreeWrapperPass : public MachineFunctionPass { std::optional PDT; public: static char ID; MachinePostDominatorTreeWrapperPass(); MachinePostDominatorTree &getPostDomTree() { return *PDT; } const MachinePostDominatorTree &getPostDomTree() const { return *PDT; } bool runOnMachineFunction(MachineFunction &MF) override; void getAnalysisUsage(AnalysisUsage &AU) const override; void releaseMemory() override { PDT.reset(); } void verifyAnalysis() const override; void print(llvm::raw_ostream &OS, const Module *M = nullptr) const override; }; } //end of namespace llvm #endif