aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2006-11-15 19:39:54 +0000
committerDevang Patel <dpatel@apple.com>2006-11-15 19:39:54 +0000
commit214ca23aef8bd408c4ee4ce28ba93d57d2416587 (patch)
tree6877784a556576f7ca936cb4d6445d01511fb7ad
parentb71fd7897f6b4500cdbe602c5a9907316750cf5a (diff)
Add run(Function &F) support in FunctionPassManager_New
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31756 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/PassManager.h6
-rw-r--r--lib/VMCore/PassManager.cpp47
2 files changed, 47 insertions, 6 deletions
diff --git a/include/llvm/PassManager.h b/include/llvm/PassManager.h
index ae52f18224..f8ebd62ca6 100644
--- a/include/llvm/PassManager.h
+++ b/include/llvm/PassManager.h
@@ -135,6 +135,12 @@ public:
/// so, return true.
bool runOnModule(Module &M);
+ /// run - Execute all of the passes scheduled for execution. Keep
+ /// track of whether any of the passes modifies the function, and if
+ /// so, return true.
+ ///
+ bool run(Function &F);
+
/// doInitialization - Run all of the initializers for the function passes.
///
bool doInitialization();
diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp
index d0d54d4c4f..b8717ea42f 100644
--- a/lib/VMCore/PassManager.cpp
+++ b/lib/VMCore/PassManager.cpp
@@ -17,6 +17,7 @@
#include "llvm/ModuleProvider.h"
#include <vector>
#include <map>
+#include <iostream>
using namespace llvm;
@@ -158,6 +159,7 @@ public:
/// track of whether any of the passes modifies the function, and if
/// so, return true.
bool runOnModule(Module &M);
+ bool runOnFunction(Function &F);
/// Return true IFF AnalysisID AID is currently available.
Pass *getAnalysisPassFromManager(AnalysisID AID);
@@ -423,19 +425,31 @@ FunctionPassManager_New::FunctionPassManager_New() {
/// PassManager_X is destroyed, the pass will be destroyed as well, so
/// there is no need to delete the pass. (TODO delete passes.)
/// This implies that all passes MUST be allocated with 'new'.
-void
-FunctionPassManager_New::add(Pass *P) {
+void FunctionPassManager_New::add(Pass *P) {
FPM->add(P);
}
/// Execute all of the passes scheduled for execution. Keep
/// track of whether any of the passes modifies the function, and if
/// so, return true.
-bool
-FunctionPassManager_New::runOnModule(Module &M) {
+bool FunctionPassManager_New::runOnModule(Module &M) {
return FPM->runOnModule(M);
}
+/// run - Execute all of the passes scheduled for execution. Keep
+/// track of whether any of the passes modifies the function, and if
+/// so, return true.
+///
+bool FunctionPassManager_New::run(Function &F) {
+ std::string errstr;
+ if (MP->materializeFunction(&F, &errstr)) {
+ std::cerr << "Error reading bytecode file: " << errstr << "\n";
+ abort();
+ }
+ return FPM->runOnFunction(F);
+}
+
+
/// doInitialization - Run all of the initializers for the function passes.
///
bool FunctionPassManager_New::doInitialization() {
@@ -489,8 +503,7 @@ FunctionPassManagerImpl_New::addPass(Pass *P) {
/// Execute all of the passes scheduled for execution by invoking
/// runOnFunction method. Keep track of whether any of the passes modifies
/// the function, and if so, return true.
-bool
-FunctionPassManagerImpl_New::runOnModule(Module &M) {
+bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
bool Changed = false;
clearAnalysis();
@@ -509,6 +522,28 @@ FunctionPassManagerImpl_New::runOnModule(Module &M) {
return Changed;
}
+/// Execute all of the passes scheduled for execution by invoking
+/// runOnFunction method. Keep track of whether any of the passes modifies
+/// the function, and if so, return true.
+bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
+
+ bool Changed = false;
+ clearAnalysis();
+
+ for (std::vector<Pass *>::iterator itr = passVectorBegin(),
+ e = passVectorEnd(); itr != e; ++itr) {
+ Pass *P = *itr;
+
+ noteDownAvailableAnalysis(P);
+ FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
+ Changed |= FP->runOnFunction(F);
+ removeNotPreservedAnalysis(P);
+ removeDeadPasses(P);
+ }
+ return Changed;
+}
+
+
/// Return true IFF AnalysisID AID is currently available.
Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {