aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-01-23 05:49:41 +0000
committerChris Lattner <sabre@nondot.org>2002-01-23 05:49:41 +0000
commite21206268d267b8eaa416e21ac8e12353cf6bda9 (patch)
treef473714825a6c76eef468431045d95a04b869696 /lib/VMCore
parentc560f88e915158b78c198fbc982a35cbbdf03644 (diff)
downloadexternal_llvm-e21206268d267b8eaa416e21ac8e12353cf6bda9.zip
external_llvm-e21206268d267b8eaa416e21ac8e12353cf6bda9.tar.gz
external_llvm-e21206268d267b8eaa416e21ac8e12353cf6bda9.tar.bz2
* Expose new command line arg --debug-pass for gccas and llc debugging
* Remember to initialize MethodPassBatcher::BBPBatcher instance var in ctor * Move PassManager::run() from header file git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1556 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Pass.cpp69
1 files changed, 60 insertions, 9 deletions
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 2668368..13df793 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -8,6 +8,34 @@
#include "llvm/Pass.h"
#include "Support/STLExtras.h"
+#include <algorithm>
+
+// Pass debugging information. Often it is useful to find out what pass is
+// running when a crash occurs in a utility. When this library is compiled with
+// debugging on, a command line option (--debug-pass) is enabled that causes the
+// pass name to be printed before it executes.
+//
+#ifdef NDEBUG
+// If not debugging, remove the option
+inline static void PrintPassInformation(const char *, Pass *, Value *) { }
+#else
+
+#include "Support/CommandLine.h"
+#include <typeinfo>
+#include <iostream>
+
+// The option is hidden from --help by default
+static cl::Flag PassDebugEnabled("debug-pass",
+ "Print pass names as they are executed by the PassManager", cl::Hidden);
+
+static void PrintPassInformation(const char *Action, Pass *P, Value *V) {
+ if (PassDebugEnabled)
+ std::cerr << Action << " Pass '" << typeid(*P).name() << "' on "
+ << typeid(*V).name() << " '" << V->getName() << "'...\n";
+}
+#endif
+
+
PassManager::~PassManager() {
for_each(Passes.begin(), Passes.end(), deleter<Pass>);
@@ -26,8 +54,10 @@ public:
virtual bool doInitialization(Module *M) {
bool Changed = false;
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Initializing", *I, M);
Changed |= (*I)->doInitialization(M);
+ }
return Changed;
}
@@ -36,17 +66,20 @@ public:
for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Executing", *I, *MI);
Changed |= (*I)->runOnBasicBlock(*MI);
+ }
return Changed;
}
virtual bool doFinalization(Module *M) {
bool Changed = false;
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Finalizing", *I, M);
Changed |= (*I)->doFinalization(M);
-
+ }
return Changed;
}
};
@@ -56,7 +89,9 @@ class MethodPassBatcher : public Pass {
SubPassesType SubPasses;
BasicBlockPassBatcher *BBPBatcher;
public:
- ~MethodPassBatcher() {
+ inline MethodPassBatcher() : BBPBatcher(0) {}
+
+ inline ~MethodPassBatcher() {
for_each(SubPasses.begin(), SubPasses.end(), deleter<MethodPass>);
}
@@ -80,18 +115,23 @@ public:
virtual bool run(Module *M) {
bool Changed = false;
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Initializing", *I, M);
Changed |= (*I)->doInitialization(M);
+ }
for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Executing", *I, M);
Changed |= (*I)->runOnMethod(*MI);
+ }
for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
- I != E; ++I)
+ I != E; ++I) {
+ PrintPassInformation("Finalizing", *I, M);
Changed |= (*I)->doFinalization(M);
-
+ }
return Changed;
}
};
@@ -127,3 +167,14 @@ void PassManager::add(Pass *P) {
Passes.push_back(P);
}
}
+
+
+bool PassManager::run(Module *M) {
+ bool MadeChanges = false;
+ // Run all of the pass initializers
+ for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
+ PrintPassInformation("Executing", Passes[i], M);
+ MadeChanges |= Passes[i]->run(M);
+ }
+ return MadeChanges;
+}