Path: blob/main/contrib/llvm-project/llvm/lib/Analysis/DominanceFrontier.cpp
35233 views
//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#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"1819using namespace llvm;2021namespace llvm {2223template class DominanceFrontierBase<BasicBlock, false>;24template class DominanceFrontierBase<BasicBlock, true>;25template class ForwardDominanceFrontierBase<BasicBlock>;2627} // end namespace llvm2829char DominanceFrontierWrapperPass::ID = 0;3031INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",32"Dominance Frontier Construction", true, true)33INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)34INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",35"Dominance Frontier Construction", true, true)3637DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()38: FunctionPass(ID) {39initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());40}4142void DominanceFrontierWrapperPass::releaseMemory() {43DF.releaseMemory();44}4546bool DominanceFrontierWrapperPass::runOnFunction(Function &) {47releaseMemory();48DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());49return false;50}5152void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {53AU.setPreservesAll();54AU.addRequired<DominatorTreeWrapperPass>();55}5657void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {58DF.print(OS);59}6061#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)62LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {63print(dbgs());64}65#endif6667/// Handle invalidation explicitly.68bool DominanceFrontier::invalidate(Function &F, const PreservedAnalyses &PA,69FunctionAnalysisManager::Invalidator &) {70// Check whether the analysis, all analyses on functions, or the function's71// CFG have been preserved.72auto PAC = PA.getChecker<DominanceFrontierAnalysis>();73return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||74PAC.preservedSet<CFGAnalyses>());75}7677AnalysisKey DominanceFrontierAnalysis::Key;7879DominanceFrontier DominanceFrontierAnalysis::run(Function &F,80FunctionAnalysisManager &AM) {81DominanceFrontier DF;82DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));83return DF;84}8586DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)87: OS(OS) {}8889PreservedAnalyses90DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {91OS << "DominanceFrontier for function: " << F.getName() << "\n";92AM.getResult<DominanceFrontierAnalysis>(F).print(OS);9394return PreservedAnalyses::all();95}969798