-void PassManager::add(MethodPass *MP) {
- if (Batcher == 0) { // If we don't have a batcher yet, make one now.
- Batcher = new MethodPassBatcher();
- Passes.push_back(Batcher);
- }
- Batcher->add(MP); // The Batcher will queue them passes up
+
+// run - On a module, we run this pass by initializing, runOnFunction'ing once
+// for every function in the module, then by finalizing.
+//
+bool FunctionPass::run(Module &M) {
+ bool Changed = doInitialization(M);
+
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (!I->isExternal()) // Passes are not run on external functions!
+ Changed |= runOnFunction(*I);
+
+ return Changed | doFinalization(M);
+}
+
+// run - On a function, we simply initialize, run the function, then finalize.
+//
+bool FunctionPass::run(Function &F) {
+ if (F.isExternal()) return false;// Passes are not run on external functions!
+
+ return doInitialization(*F.getParent()) | runOnFunction(F)
+ | doFinalization(*F.getParent());
+}
+
+void FunctionPass::addToPassManager(PassManagerT<Module> *PM,
+ AnalysisUsage &AU) {
+ PM->addPass(this, AU);
+}
+
+void FunctionPass::addToPassManager(PassManagerT<Function> *PM,
+ AnalysisUsage &AU) {
+ PM->addPass(this, AU);
+}
+
+//===----------------------------------------------------------------------===//
+// BasicBlockPass Implementation
+//
+
+// To run this pass on a function, we simply call runOnBasicBlock once for each
+// function.
+//
+bool BasicBlockPass::runOnFunction(Function &F) {
+ bool Changed = false;
+ for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+ Changed |= runOnBasicBlock(*I);
+ return Changed;
+}
+
+// To run directly on the basic block, we initialize, runOnBasicBlock, then
+// finalize.
+//
+bool BasicBlockPass::run(BasicBlock &BB) {
+ Module &M = *BB.getParent()->getParent();
+ return doInitialization(M) | runOnBasicBlock(BB) | doFinalization(M);
+}
+
+void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,
+ AnalysisUsage &AU) {
+ PM->addPass(this, AU);