blob: de6ce20a1e9080fb4b6a79e4ce3c809d8e40a4d8 [file] [log] [blame]
Devang Patel6e5a1132006-11-07 21:31:57 +00001//===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LLVM Pass Manager infrastructure.
11//
12//===----------------------------------------------------------------------===//
13
14
15#include "llvm/PassManager.h"
16#include "llvm/Function.h"
17#include "llvm/Module.h"
18
19using namespace llvm;
20
Devang Patelf68a3492006-11-07 22:35:17 +000021// PassManagerAnalysisHelper implementation
22
23/// Return TRUE IFF pass P's required analysis set does not required new
24/// manager.
25bool PassManagerAnalysisHelper::manageablePass(Pass *P) {
26
27 AnalysisUsage AnUsage;
28 P->getAnalysisUsage(AnUsage);
29
30 // If this pass is not preserving information that is required by the other passes
31 // managed by this manager then use new manager
32 // TODO
33 return true;
34}
35
36/// Return TRUE iff AnalysisID AID is currently available.
37bool PassManagerAnalysisHelper::analysisCurrentlyAvailable(AnalysisID AID) {
38
39 // TODO
40 return false;
41}
42
43/// Augment RequiredSet by adding analysis required by pass P.
44void PassManagerAnalysisHelper::noteDownRequiredAnalysis(Pass *P) {
45
46 // TODO
47}
48
49/// Remove AnalysisID from the RequiredSet
50void PassManagerAnalysisHelper::removeAnalysis(AnalysisID AID) {
51
52 // TODO
53}
54
55/// Remove Analyss not preserved by Pass P
56void PassManagerAnalysisHelper::removeNotPreservedAnalysis(Pass *P) {
57
58 // TODO
59}
60
Devang Patel6e5a1132006-11-07 21:31:57 +000061/// BasicBlockPassManager implementation
62
63/// Add pass P into PassVector and return TRUE. If this pass is not
64/// manageable by this manager then return FALSE.
65bool
66BasicBlockPassManager_New::addPass (Pass *P) {
67
68 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
69 if (!BP)
70 return false;
71
Devang Patel3c8eb622006-11-07 22:56:50 +000072 // If this pass does not preserve anlysis that is used by other passes
73 // managed by this manager than it is not a suiable pass for this manager.
74 if (!manageablePass (P))
75 return false;
76
77 // Take a note of analysis required by this pass.
78 noteDownRequiredAnalysis(P);
Devang Patel6e5a1132006-11-07 21:31:57 +000079
80 // Add pass
81 PassVector.push_back(BP);
82 return true;
83}
84
85/// Execute all of the passes scheduled for execution by invoking
86/// runOnBasicBlock method. Keep track of whether any of the passes modifies
87/// the function, and if so, return true.
88bool
89BasicBlockPassManager_New::runOnFunction(Function &F) {
90
91 bool Changed = false;
92 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
93 for (std::vector<Pass *>::iterator itr = PassVector.begin(),
94 e = PassVector.end(); itr != e; ++itr) {
95 Pass *P = *itr;
96 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
97 Changed |= BP->runOnBasicBlock(*I);
98 }
99 return Changed;
100}
101
Devang Patel0c2012f2006-11-07 21:49:50 +0000102// FunctionPassManager_New implementation
103
104///////////////////////////////////////////////////////////////////////////////
105// FunctionPassManager
106
107/// Add pass P into the pass manager queue. If P is a BasicBlockPass then
108/// either use it into active basic block pass manager or create new basic
109/// block pass manager to handle pass P.
110bool
111FunctionPassManager_New::addPass (Pass *P) {
112
113 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
114 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
115
116 if (!activeBBPassManager
117 || !activeBBPassManager->addPass(BP)) {
118
119 activeBBPassManager = new BasicBlockPassManager_New();
120
121 PassVector.push_back(activeBBPassManager);
122 assert (!activeBBPassManager->addPass(BP) &&
123 "Unable to add Pass");
124 }
125 return true;
126 }
127
128 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
129 if (!FP)
130 return false;
131
Devang Patel3c8eb622006-11-07 22:56:50 +0000132 // If this pass does not preserve anlysis that is used by other passes
133 // managed by this manager than it is not a suiable pass for this manager.
134 if (!manageablePass (P))
135 return false;
136
137 // Take a note of analysis required by this pass.
138 noteDownRequiredAnalysis(P);
Devang Patel0c2012f2006-11-07 21:49:50 +0000139
140 PassVector.push_back(FP);
141 activeBBPassManager = NULL;
142 return true;
143}
144
145/// Execute all of the passes scheduled for execution by invoking
146/// runOnFunction method. Keep track of whether any of the passes modifies
147/// the function, and if so, return true.
148bool
149FunctionPassManager_New::runOnModule(Module &M) {
150
151 bool Changed = false;
152 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
153 for (std::vector<Pass *>::iterator itr = PassVector.begin(),
154 e = PassVector.end(); itr != e; ++itr) {
155 Pass *P = *itr;
156 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
157 Changed |= FP->runOnFunction(*I);
158 }
159 return Changed;
160}
161
162
Devang Patel05e1a972006-11-07 22:03:15 +0000163// ModulePassManager implementation
164
165/// Add P into pass vector if it is manageble. If P is a FunctionPass
166/// then use FunctionPassManager_New to manage it. Return FALSE if P
167/// is not manageable by this manager.
168bool
169ModulePassManager_New::addPass (Pass *P) {
170
171 // If P is FunctionPass then use function pass maanager.
172 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
173
174 activeFunctionPassManager = NULL;
175
176 if (!activeFunctionPassManager
177 || !activeFunctionPassManager->addPass(P)) {
178
179 activeFunctionPassManager = new FunctionPassManager_New();
180
181 PassVector.push_back(activeFunctionPassManager);
182 assert (!activeFunctionPassManager->addPass(FP) &&
183 "Unable to add Pass");
184 }
185 return true;
186 }
187
188 ModulePass *MP = dynamic_cast<ModulePass *>(P);
189 if (!MP)
190 return false;
191
Devang Patel3c8eb622006-11-07 22:56:50 +0000192 // If this pass does not preserve anlysis that is used by other passes
193 // managed by this manager than it is not a suiable pass for this manager.
194 if (!manageablePass (P))
195 return false;
196
197 // Take a note of analysis required by this pass.
198 noteDownRequiredAnalysis(P);
Devang Patel05e1a972006-11-07 22:03:15 +0000199
200 PassVector.push_back(MP);
201 activeFunctionPassManager = NULL;
202 return true;
203}
204
205
206/// Execute all of the passes scheduled for execution by invoking
207/// runOnModule method. Keep track of whether any of the passes modifies
208/// the module, and if so, return true.
209bool
210ModulePassManager_New::runOnModule(Module &M) {
211 bool Changed = false;
212 for (std::vector<Pass *>::iterator itr = PassVector.begin(),
213 e = PassVector.end(); itr != e; ++itr) {
214 Pass *P = *itr;
215 ModulePass *MP = dynamic_cast<ModulePass*>(P);
216 Changed |= MP->runOnModule(M);
217 }
218 return Changed;
219}
220
Devang Patelc290c8a2006-11-07 22:23:34 +0000221/// Schedule all passes from the queue by adding them in their
222/// respective manager's queue.
223void
224PassManager_New::schedulePasses() {
225 /* TODO */
226}
227
228/// Add pass P to the queue of passes to run.
229void
230PassManager_New::add(Pass *P) {
231 /* TODO */
232}
233
234// PassManager_New implementation
235/// Add P into active pass manager or use new module pass manager to
236/// manage it.
237bool
238PassManager_New::addPass (Pass *P) {
239
240 if (!activeManager) {
241 activeManager = new ModulePassManager_New();
242 PassManagers.push_back(activeManager);
243 }
244
245 return activeManager->addPass(P);
246}
247
248/// run - Execute all of the passes scheduled for execution. Keep track of
249/// whether any of the passes modifies the module, and if so, return true.
250bool
251PassManager_New::run(Module &M) {
252
253 schedulePasses();
254 bool Changed = false;
255 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
256 e = PassManagers.end(); itr != e; ++itr) {
257 ModulePassManager_New *pm = *itr;
258 Changed |= pm->runOnModule(M);
259 }
260 return Changed;
261}