LLVM API Documentation

MachineRegionInfo.cpp
Go to the documentation of this file.
00001 
00002 #include "llvm/CodeGen/MachineRegionInfo.h"
00003 #include "llvm/CodeGen/MachinePostDominators.h"
00004 #include "llvm/ADT/Statistic.h"
00005 #include "llvm/Analysis/RegionInfoImpl.h"
00006 
00007 #define DEBUG_TYPE "region"
00008 
00009 using namespace llvm;
00010 
00011 STATISTIC(numMachineRegions,       "The # of machine regions");
00012 STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
00013 
00014 namespace llvm {
00015 template class RegionBase<RegionTraits<MachineFunction>>;
00016 template class RegionNodeBase<RegionTraits<MachineFunction>>;
00017 template class RegionInfoBase<RegionTraits<MachineFunction>>;
00018 }
00019 
00020 //===----------------------------------------------------------------------===//
00021 // MachineRegion implementation
00022 //
00023 
00024 MachineRegion::MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit,
00025                              MachineRegionInfo* RI,
00026                              MachineDominatorTree *DT, MachineRegion *Parent) :
00027   RegionBase<RegionTraits<MachineFunction>>(Entry, Exit, RI, DT, Parent) {
00028 
00029 }
00030 
00031 MachineRegion::~MachineRegion() { }
00032 
00033 //===----------------------------------------------------------------------===//
00034 // MachineRegionInfo implementation
00035 //
00036 
00037 MachineRegionInfo::MachineRegionInfo() :
00038   RegionInfoBase<RegionTraits<MachineFunction>>() {
00039 
00040 }
00041 
00042 MachineRegionInfo::~MachineRegionInfo() {
00043 
00044 }
00045 
00046 void MachineRegionInfo::updateStatistics(MachineRegion *R) {
00047   ++numMachineRegions;
00048 
00049   // TODO: Slow. Should only be enabled if -stats is used.
00050   if (R->isSimple())
00051     ++numMachineSimpleRegions;
00052 }
00053 
00054 void MachineRegionInfo::recalculate(MachineFunction &F,
00055                                     MachineDominatorTree *DT_,
00056                                     MachinePostDominatorTree *PDT_,
00057                                     MachineDominanceFrontier *DF_) {
00058   DT = DT_;
00059   PDT = PDT_;
00060   DF = DF_;
00061 
00062   MachineBasicBlock *Entry = GraphTraits<MachineFunction*>::getEntryNode(&F);
00063 
00064   TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
00065   updateStatistics(TopLevelRegion);
00066   calculate(F);
00067 }
00068 
00069 //===----------------------------------------------------------------------===//
00070 // MachineRegionInfoPass implementation
00071 //
00072 
00073 MachineRegionInfoPass::MachineRegionInfoPass() : MachineFunctionPass(ID) {
00074   initializeMachineRegionInfoPassPass(*PassRegistry::getPassRegistry());
00075 }
00076 
00077 MachineRegionInfoPass::~MachineRegionInfoPass() {
00078 
00079 }
00080 
00081 bool MachineRegionInfoPass::runOnMachineFunction(MachineFunction &F) {
00082   releaseMemory();
00083 
00084   auto DT = &getAnalysis<MachineDominatorTree>();
00085   auto PDT = &getAnalysis<MachinePostDominatorTree>();
00086   auto DF = &getAnalysis<MachineDominanceFrontier>();
00087 
00088   RI.recalculate(F, DT, PDT, DF);
00089   return false;
00090 }
00091 
00092 void MachineRegionInfoPass::releaseMemory() {
00093   RI.releaseMemory();
00094 }
00095 
00096 void MachineRegionInfoPass::verifyAnalysis() const {
00097   // Only do verification when user wants to, otherwise this expensive check
00098   // will be invoked by PMDataManager::verifyPreservedAnalysis when
00099   // a regionpass (marked PreservedAll) finish.
00100   if (MachineRegionInfo::VerifyRegionInfo)
00101     RI.verifyAnalysis();
00102 }
00103 
00104 void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
00105   AU.setPreservesAll();
00106   AU.addRequiredTransitive<DominatorTreeWrapperPass>();
00107   AU.addRequired<PostDominatorTree>();
00108   AU.addRequired<DominanceFrontier>();
00109 }
00110 
00111 void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
00112   RI.print(OS);
00113 }
00114 
00115 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
00116 void MachineRegionInfoPass::dump() const {
00117   RI.dump();
00118 }
00119 #endif
00120 
00121 char MachineRegionInfoPass::ID = 0;
00122 
00123 INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, "regions",
00124                 "Detect single entry single exit regions", true, true)
00125 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
00126 INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
00127 INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier)
00128 INITIALIZE_PASS_END(MachineRegionInfoPass, "regions",
00129                 "Detect single entry single exit regions", true, true)
00130 
00131 // Create methods available outside of this file, to use them
00132 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
00133 // the link time optimization.
00134 
00135 namespace llvm {
00136   FunctionPass *createMachineRegionInfoPass() {
00137     return new MachineRegionInfoPass();
00138   }
00139 }
00140