Line data Source code
1 : //===- lib/Codegen/MachineRegionInfo.cpp ----------------------------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #include "llvm/CodeGen/MachineRegionInfo.h"
11 : #include "llvm/ADT/Statistic.h"
12 : #include "llvm/Analysis/RegionInfoImpl.h"
13 : #include "llvm/CodeGen/MachinePostDominators.h"
14 : #include "llvm/Config/llvm-config.h"
15 : #include "llvm/Pass.h"
16 : #include "llvm/Support/Compiler.h"
17 : #include "llvm/Support/Debug.h"
18 :
19 : #define DEBUG_TYPE "machine-region-info"
20 :
21 : using namespace llvm;
22 :
23 : STATISTIC(numMachineRegions, "The # of machine regions");
24 : STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
25 :
26 : namespace llvm {
27 :
28 : template class RegionBase<RegionTraits<MachineFunction>>;
29 : template class RegionNodeBase<RegionTraits<MachineFunction>>;
30 : template class RegionInfoBase<RegionTraits<MachineFunction>>;
31 :
32 : } // end namespace llvm
33 :
34 : //===----------------------------------------------------------------------===//
35 : // MachineRegion implementation
36 :
37 0 : MachineRegion::MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit,
38 : MachineRegionInfo* RI,
39 0 : MachineDominatorTree *DT, MachineRegion *Parent) :
40 0 : RegionBase<RegionTraits<MachineFunction>>(Entry, Exit, RI, DT, Parent) {}
41 :
42 : MachineRegion::~MachineRegion() = default;
43 :
44 : //===----------------------------------------------------------------------===//
45 : // MachineRegionInfo implementation
46 :
47 : MachineRegionInfo::MachineRegionInfo() = default;
48 :
49 : MachineRegionInfo::~MachineRegionInfo() = default;
50 :
51 0 : void MachineRegionInfo::updateStatistics(MachineRegion *R) {
52 : ++numMachineRegions;
53 :
54 : // TODO: Slow. Should only be enabled if -stats is used.
55 0 : if (R->isSimple())
56 : ++numMachineSimpleRegions;
57 0 : }
58 :
59 0 : void MachineRegionInfo::recalculate(MachineFunction &F,
60 : MachineDominatorTree *DT_,
61 : MachinePostDominatorTree *PDT_,
62 : MachineDominanceFrontier *DF_) {
63 0 : DT = DT_;
64 0 : PDT = PDT_;
65 0 : DF = DF_;
66 :
67 : MachineBasicBlock *Entry = GraphTraits<MachineFunction*>::getEntryNode(&F);
68 :
69 0 : TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
70 0 : updateStatistics(TopLevelRegion);
71 0 : calculate(F);
72 0 : }
73 :
74 : //===----------------------------------------------------------------------===//
75 : // MachineRegionInfoPass implementation
76 : //
77 :
78 0 : MachineRegionInfoPass::MachineRegionInfoPass() : MachineFunctionPass(ID) {
79 0 : initializeMachineRegionInfoPassPass(*PassRegistry::getPassRegistry());
80 0 : }
81 :
82 : MachineRegionInfoPass::~MachineRegionInfoPass() = default;
83 :
84 0 : bool MachineRegionInfoPass::runOnMachineFunction(MachineFunction &F) {
85 0 : releaseMemory();
86 :
87 0 : auto DT = &getAnalysis<MachineDominatorTree>();
88 0 : auto PDT = &getAnalysis<MachinePostDominatorTree>();
89 0 : auto DF = &getAnalysis<MachineDominanceFrontier>();
90 :
91 0 : RI.recalculate(F, DT, PDT, DF);
92 :
93 : LLVM_DEBUG(RI.dump());
94 :
95 0 : return false;
96 : }
97 :
98 0 : void MachineRegionInfoPass::releaseMemory() {
99 0 : RI.releaseMemory();
100 0 : }
101 :
102 0 : void MachineRegionInfoPass::verifyAnalysis() const {
103 : // Only do verification when user wants to, otherwise this expensive check
104 : // will be invoked by PMDataManager::verifyPreservedAnalysis when
105 : // a regionpass (marked PreservedAll) finish.
106 0 : if (MachineRegionInfo::VerifyRegionInfo)
107 0 : RI.verifyAnalysis();
108 0 : }
109 :
110 0 : void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
111 : AU.setPreservesAll();
112 : AU.addRequired<MachineDominatorTree>();
113 : AU.addRequired<MachinePostDominatorTree>();
114 : AU.addRequired<MachineDominanceFrontier>();
115 0 : MachineFunctionPass::getAnalysisUsage(AU);
116 0 : }
117 :
118 0 : void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
119 0 : RI.print(OS);
120 0 : }
121 :
122 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
123 : LLVM_DUMP_METHOD void MachineRegionInfoPass::dump() const {
124 : RI.dump();
125 : }
126 : #endif
127 :
128 : char MachineRegionInfoPass::ID = 0;
129 : char &MachineRegionInfoPassID = MachineRegionInfoPass::ID;
130 :
131 31780 : INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE,
132 : "Detect single entry single exit regions", true, true)
133 31780 : INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
134 31780 : INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
135 31780 : INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier)
136 85147 : INITIALIZE_PASS_END(MachineRegionInfoPass, DEBUG_TYPE,
137 : "Detect single entry single exit regions", true, true)
138 :
139 : // Create methods available outside of this file, to use them
140 : // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
141 : // the link time optimization.
142 :
143 : namespace llvm {
144 :
145 0 : FunctionPass *createMachineRegionInfoPass() {
146 0 : return new MachineRegionInfoPass();
147 : }
148 :
149 : } // end namespace llvm
|