summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-07-23 18:08:00 +0000
committerChris Lattner <sabre@nondot.org>2002-07-23 18:08:00 +0000
commit37d3c95b0f3ef660ad54227c1ff3a8dd39d23edd (patch)
tree913da125181c846bae5d4cfbaa8d5672f53ef1b1 /llvm/lib
parent7f8845a52394d755c43127a5bbc23852a9c2ef20 (diff)
downloadbcm5719-llvm-37d3c95b0f3ef660ad54227c1ff3a8dd39d23edd.tar.gz
bcm5719-llvm-37d3c95b0f3ef660ad54227c1ff3a8dd39d23edd.zip
Add support for pass registration
llvm-svn: 3018
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Pass.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Pass.cpp b/llvm/lib/VMCore/Pass.cpp
index 4b29371fff8..2480d70bb2f 100644
--- a/llvm/lib/VMCore/Pass.cpp
+++ b/llvm/lib/VMCore/Pass.cpp
@@ -11,6 +11,7 @@
#include "llvm/Module.h"
#include "Support/STLExtras.h"
#include "Support/CommandLine.h"
+#include "Support/TypeInfo.h"
#include <typeinfo>
#include <iostream>
#include <sys/time.h>
@@ -284,3 +285,95 @@ void BasicBlockPass::addToPassManager(PassManagerT<BasicBlock> *PM,
PM->addPass(this, AU);
}
+
+//===----------------------------------------------------------------------===//
+// Pass Registration mechanism
+//
+static std::map<TypeInfo, PassInfo*> *PassInfoMap = 0;
+static std::vector<PassRegistrationListener*> *Listeners = 0;
+
+// getPassInfo - Return the PassInfo data structure that corresponds to this
+// pass...
+const PassInfo *Pass::getPassInfo() const {
+ assert(PassInfoMap && "PassInfoMap not constructed yet??");
+ std::map<TypeInfo, PassInfo*>::iterator I =
+ PassInfoMap->find(typeid(*this));
+ assert(I != PassInfoMap->end() && "Pass has not been registered!");
+ return I->second;
+}
+
+void RegisterPassBase::registerPass(PassInfo *PI) {
+ if (PassInfoMap == 0)
+ PassInfoMap = new std::map<TypeInfo, PassInfo*>();
+
+ assert(PassInfoMap->find(PI->getTypeInfo()) == PassInfoMap->end() &&
+ "Pass already registered!");
+ PIObj = PI;
+ PassInfoMap->insert(std::make_pair(TypeInfo(PI->getTypeInfo()), PI));
+
+ // Notify any listeners...
+ if (Listeners)
+ for (std::vector<PassRegistrationListener*>::iterator
+ I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
+ (*I)->passRegistered(PI);
+}
+
+RegisterPassBase::~RegisterPassBase() {
+ assert(PassInfoMap && "Pass registered but not in map!");
+ std::map<TypeInfo, PassInfo*>::iterator I =
+ PassInfoMap->find(PIObj->getTypeInfo());
+ assert(I != PassInfoMap->end() && "Pass registered but not in map!");
+
+ // Remove pass from the map...
+ PassInfoMap->erase(I);
+ if (PassInfoMap->empty()) {
+ delete PassInfoMap;
+ PassInfoMap = 0;
+ }
+
+ // Notify any listeners...
+ if (Listeners)
+ for (std::vector<PassRegistrationListener*>::iterator
+ I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
+ (*I)->passUnregistered(PIObj);
+
+ // Delete the PassInfo object itself...
+ delete PIObj;
+}
+
+
+
+//===----------------------------------------------------------------------===//
+// PassRegistrationListener implementation
+//
+
+// PassRegistrationListener ctor - Add the current object to the list of
+// PassRegistrationListeners...
+PassRegistrationListener::PassRegistrationListener() {
+ if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>();
+ Listeners->push_back(this);
+}
+
+// dtor - Remove object from list of listeners...
+PassRegistrationListener::~PassRegistrationListener() {
+ std::vector<PassRegistrationListener*>::iterator I =
+ std::find(Listeners->begin(), Listeners->end(), this);
+ assert(Listeners && I != Listeners->end() &&
+ "PassRegistrationListener not registered!");
+ Listeners->erase(I);
+
+ if (Listeners->empty()) {
+ delete Listeners;
+ Listeners = 0;
+ }
+}
+
+// enumeratePasses - Iterate over the registered passes, calling the
+// passEnumerate callback on each PassInfo object.
+//
+void PassRegistrationListener::enumeratePasses() {
+ if (PassInfoMap)
+ for (std::map<TypeInfo, PassInfo*>::iterator I = PassInfoMap->begin(),
+ E = PassInfoMap->end(); I != E; ++I)
+ passEnumerate(I->second);
+}
OpenPOWER on IntegriCloud