1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LLVM Pass Manager infrastructure.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/PassManager.h"
16 #include "llvm/Function.h"
17 #include "llvm/Module.h"
21 /// BasicBlockPassManager implementation
23 /// Add pass P into PassVector and return TRUE. If this pass is not
24 /// manageable by this manager then return FALSE.
26 BasicBlockPassManager_New::addPass (Pass *P) {
28 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
32 // TODO: Check if it suitable to manage P using this BasicBlockPassManager
33 // or we need another instance of BasicBlockPassManager
36 PassVector.push_back(BP);
40 /// Execute all of the passes scheduled for execution by invoking
41 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
42 /// the function, and if so, return true.
44 BasicBlockPassManager_New::runOnFunction(Function &F) {
47 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
48 for (std::vector<Pass *>::iterator itr = PassVector.begin(),
49 e = PassVector.end(); itr != e; ++itr) {
51 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
52 Changed |= BP->runOnBasicBlock(*I);
57 // FunctionPassManager_New implementation
59 ///////////////////////////////////////////////////////////////////////////////
60 // FunctionPassManager
62 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
63 /// either use it into active basic block pass manager or create new basic
64 /// block pass manager to handle pass P.
66 FunctionPassManager_New::addPass (Pass *P) {
68 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
69 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
71 if (!activeBBPassManager
72 || !activeBBPassManager->addPass(BP)) {
74 activeBBPassManager = new BasicBlockPassManager_New();
76 PassVector.push_back(activeBBPassManager);
77 assert (!activeBBPassManager->addPass(BP) &&
78 "Unable to add Pass");
83 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
87 // TODO: Check if it suitable to manage P using this FunctionPassManager
88 // or we need another instance of BasicBlockPassManager
90 PassVector.push_back(FP);
91 activeBBPassManager = NULL;
95 /// Execute all of the passes scheduled for execution by invoking
96 /// runOnFunction method. Keep track of whether any of the passes modifies
97 /// the function, and if so, return true.
99 FunctionPassManager_New::runOnModule(Module &M) {
101 bool Changed = false;
102 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
103 for (std::vector<Pass *>::iterator itr = PassVector.begin(),
104 e = PassVector.end(); itr != e; ++itr) {
106 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
107 Changed |= FP->runOnFunction(*I);