DominanceFrontier.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
  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. #include "llvm/Analysis/DominanceFrontier.h"
  9. #include "llvm/Analysis/DominanceFrontierImpl.h"
  10. #include "llvm/Config/llvm-config.h"
  11. #include "llvm/IR/Dominators.h"
  12. #include "llvm/IR/Function.h"
  13. #include "llvm/IR/PassManager.h"
  14. #include "llvm/InitializePasses.h"
  15. #include "llvm/Pass.h"
  16. #include "llvm/Support/Compiler.h"
  17. #include "llvm/Support/raw_ostream.h"
  18. using namespace llvm;
  19. namespace llvm {
  20. template class DominanceFrontierBase<BasicBlock, false>;
  21. template class DominanceFrontierBase<BasicBlock, true>;
  22. template class ForwardDominanceFrontierBase<BasicBlock>;
  23. } // end namespace llvm
  24. char DominanceFrontierWrapperPass::ID = 0;
  25. INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
  26. "Dominance Frontier Construction", true, true)
  27. INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
  28. INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
  29. "Dominance Frontier Construction", true, true)
  30. DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
  31. : FunctionPass(ID) {
  32. initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
  33. }
  34. void DominanceFrontierWrapperPass::releaseMemory() {
  35. DF.releaseMemory();
  36. }
  37. bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
  38. releaseMemory();
  39. DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
  40. return false;
  41. }
  42. void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
  43. AU.setPreservesAll();
  44. AU.addRequired<DominatorTreeWrapperPass>();
  45. }
  46. void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
  47. DF.print(OS);
  48. }
  49. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  50. LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
  51. print(dbgs());
  52. }
  53. #endif
  54. /// Handle invalidation explicitly.
  55. bool DominanceFrontier::invalidate(Function &F, const PreservedAnalyses &PA,
  56. FunctionAnalysisManager::Invalidator &) {
  57. // Check whether the analysis, all analyses on functions, or the function's
  58. // CFG have been preserved.
  59. auto PAC = PA.getChecker<DominanceFrontierAnalysis>();
  60. return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
  61. PAC.preservedSet<CFGAnalyses>());
  62. }
  63. AnalysisKey DominanceFrontierAnalysis::Key;
  64. DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
  65. FunctionAnalysisManager &AM) {
  66. DominanceFrontier DF;
  67. DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
  68. return DF;
  69. }
  70. DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
  71. : OS(OS) {}
  72. PreservedAnalyses
  73. DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
  74. OS << "DominanceFrontier for function: " << F.getName() << "\n";
  75. AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
  76. return PreservedAnalyses::all();
  77. }