[llvm-commits] CVS: llvm/lib/VMCore/Pass.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Sep 19 21:47:29 PDT 2004
Changes in directory llvm/lib/VMCore:
Pass.cpp updated: 1.62 -> 1.63
---
Log message:
'Pass' should now not be derived from by clients. Instead, they should derive
from ModulePass. Instead of implementing Pass::run, then should implement
ModulePass::runOnModule.
Also, fix some undefined behavior, expecting | on booleans to evaluate
left-to-right.
---
Diffs of the changes: (+19 -10)
Index: llvm/lib/VMCore/Pass.cpp
diff -u llvm/lib/VMCore/Pass.cpp:1.62 llvm/lib/VMCore/Pass.cpp:1.63
--- llvm/lib/VMCore/Pass.cpp:1.62 Wed Sep 1 17:55:37 2004
+++ llvm/lib/VMCore/Pass.cpp Sun Sep 19 23:47:19 2004
@@ -78,8 +78,12 @@
//
PassManager::PassManager() : PM(new PassManagerT<Module>()) {}
PassManager::~PassManager() { delete PM; }
-void PassManager::add(Pass *P) { PM->add(P); }
-bool PassManager::run(Module &M) { return PM->run(M); }
+void PassManager::add(Pass *P) {
+ ModulePass *MP = dynamic_cast<ModulePass*>(P);
+ assert(MP && "Not a modulepass?");
+ PM->add(MP);
+}
+bool PassManager::run(Module &M) { return PM->runOnModule(M); }
//===----------------------------------------------------------------------===//
// FunctionPassManager implementation - The FunctionPassManager class
@@ -101,7 +105,7 @@
std::cerr << "Error reading bytecode file!\n";
abort();
}
- return PM->run(F);
+ return PM->run(F);
}
@@ -188,7 +192,7 @@
// Pass Implementation
//
-void Pass::addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU) {
+void ModulePass::addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU) {
PM->addPass(this, AU);
}
@@ -238,7 +242,7 @@
// 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 FunctionPass::runOnModule(Module &M) {
bool Changed = doInitialization(M);
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
@@ -253,8 +257,9 @@
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());
+ bool Changed = doInitialization(*F.getParent());
+ Changed |= runOnFunction(F);
+ return Changed | doFinalization(*F.getParent());
}
void FunctionPass::addToPassManager(PassManagerT<Module> *PM,
@@ -284,11 +289,15 @@
// To run directly on the basic block, we initialize, runOnBasicBlock, then
// finalize.
//
-bool BasicBlockPass::run(BasicBlock &BB) {
+bool BasicBlockPass::runPass(BasicBlock &BB) {
Function &F = *BB.getParent();
Module &M = *F.getParent();
- return doInitialization(M) | doInitialization(F) | runOnBasicBlock(BB) |
- doFinalization(F) | doFinalization(M);
+ bool Changed = doInitialization(M);
+ Changed |= doInitialization(F);
+ Changed |= runOnBasicBlock(BB);
+ Changed |= doFinalization(F);
+ Changed |= doFinalization(M);
+ return Changed;
}
void BasicBlockPass::addToPassManager(PassManagerT<Function> *PM,
More information about the llvm-commits
mailing list