X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FPass.cpp;h=d04f90c127a295f342da38ac58d8c59eb21977f6;hb=629c1a3f78494d0dd769fe82bd2bd17df0555843;hp=e6b31b302a952dd52ffb694df6b865cd95f87bd3;hpb=6e21ff0b0a8e4f0878431afa5628bb1c2db0b8e1;p=oota-llvm.git diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index e6b31b302a9..d04f90c127a 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -13,13 +13,14 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Pass.h" #include "llvm/PassManager.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/TypeInfo.h" #include +#include #include using namespace llvm; @@ -44,12 +45,14 @@ void Pass::dumpPassStructure(unsigned Offset) { cerr << std::string(Offset*2, ' ') << getPassName() << "\n"; } -// getPassName - Use C++ RTTI to get a SOMEWHAT intelligible name for the pass. -// +/// getPassName - Return a nice clean name for a pass. This usually +/// implemented in terms of the name that is registered by one of the +/// Registration templates, but can be overloaded directly. +/// const char *Pass::getPassName() const { if (const PassInfo *PI = getPassInfo()) return PI->getPassName(); - return typeid(*this).name(); + return "Unnamed pass: implement Pass::getPassName()"; } // print - Print out the internal state of the pass. This is called by Analyze @@ -91,7 +94,8 @@ bool FunctionPass::runOnModule(Module &M) { // run - On a function, we simply initialize, run the function, then finalize. // bool FunctionPass::run(Function &F) { - if (F.isDeclaration()) return false;// Passes are not run on external functions! + // Passes are not run on external functions! + if (F.isDeclaration()) return false; bool Changed = doInitialization(*F.getParent()); Changed |= runOnFunction(F); @@ -112,20 +116,6 @@ bool BasicBlockPass::runOnFunction(Function &F) { return Changed | doFinalization(F); } -// To run directly on the basic block, we initialize, runOnBasicBlock, then -// finalize. -// -bool BasicBlockPass::runPass(BasicBlock &BB) { - Function &F = *BB.getParent(); - Module &M = *F.getParent(); - bool Changed = doInitialization(M); - Changed |= doInitialization(F); - Changed |= runOnBasicBlock(BB); - Changed |= doFinalization(F); - Changed |= doFinalization(M); - return Changed; -} - //===----------------------------------------------------------------------===// // Pass Registration mechanism // @@ -133,7 +123,8 @@ namespace { class PassRegistrar { /// PassInfoMap - Keep track of the passinfo object for each registered llvm /// pass. - std::map PassInfoMap; + typedef std::map MapType; + MapType PassInfoMap; /// AnalysisGroupInfo - Keep track of information for each analysis group. struct AnalysisGroupInfo { @@ -147,20 +138,19 @@ class PassRegistrar { public: - const PassInfo *GetPassInfo(const std::type_info &TI) const { - std::map::const_iterator I = PassInfoMap.find(TI); + const PassInfo *GetPassInfo(intptr_t TI) const { + MapType::const_iterator I = PassInfoMap.find(TI); return I != PassInfoMap.end() ? I->second : 0; } - void RegisterPass(PassInfo &PI) { + void RegisterPass(const PassInfo &PI) { bool Inserted = - PassInfoMap.insert(std::make_pair(TypeInfo(PI.getTypeInfo()),&PI)).second; - assert(Inserted && "Pass registered multiple times!"); + PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second; + assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted; } - void UnregisterPass(PassInfo &PI) { - std::map::iterator I = - PassInfoMap.find(PI.getTypeInfo()); + void UnregisterPass(const PassInfo &PI) { + MapType::iterator I = PassInfoMap.find(PI.getTypeInfo()); assert(I != PassInfoMap.end() && "Pass registered but not in map!"); // Remove pass from the map. @@ -168,7 +158,7 @@ public: } void EnumerateWith(PassRegistrationListener *L) { - for (std::map::const_iterator I = PassInfoMap.begin(), + for (MapType::const_iterator I = PassInfoMap.begin(), E = PassInfoMap.end(); I != E; ++I) L->passEnumerate(I->second); } @@ -210,26 +200,25 @@ static PassRegistrar *getPassRegistrar() { // getPassInfo - Return the PassInfo data structure that corresponds to this // pass... const PassInfo *Pass::getPassInfo() const { - if (PassInfoCache) return PassInfoCache; - return lookupPassInfo(typeid(*this)); + return lookupPassInfo(PassID); } -const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) { +const PassInfo *Pass::lookupPassInfo(intptr_t TI) { return getPassRegistrar()->GetPassInfo(TI); } -void RegisterPassBase::registerPass() { - getPassRegistrar()->RegisterPass(PIObj); +void PassInfo::registerPass() { + getPassRegistrar()->RegisterPass(*this); // Notify any listeners. if (Listeners) for (std::vector::iterator I = Listeners->begin(), E = Listeners->end(); I != E; ++I) - (*I)->passRegistered(&PIObj); + (*I)->passRegistered(this); } -void RegisterPassBase::unregisterPass() { - getPassRegistrar()->UnregisterPass(PIObj); +void PassInfo::unregisterPass() { + getPassRegistrar()->UnregisterPass(*this); } //===----------------------------------------------------------------------===// @@ -238,22 +227,22 @@ void RegisterPassBase::unregisterPass() { // RegisterAGBase implementation // -RegisterAGBase::RegisterAGBase(const std::type_info &Interface, - const std::type_info *Pass, bool isDefault) - : RegisterPassBase(Interface), +RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID, + intptr_t PassID, bool isDefault) + : PassInfo(Name, InterfaceID), ImplementationInfo(0), isDefaultImplementation(isDefault) { - InterfaceInfo = const_cast(Pass::lookupPassInfo(Interface)); + InterfaceInfo = const_cast(Pass::lookupPassInfo(InterfaceID)); if (InterfaceInfo == 0) { // First reference to Interface, register it now. registerPass(); - InterfaceInfo = &PIObj; + InterfaceInfo = this; } - assert(PIObj.isAnalysisGroup() && + assert(isAnalysisGroup() && "Trying to join an analysis group that is a normal pass!"); - if (Pass) { - ImplementationInfo = Pass::lookupPassInfo(*Pass); + if (PassID) { + ImplementationInfo = Pass::lookupPassInfo(PassID); assert(ImplementationInfo && "Must register pass before adding to AnalysisGroup!"); @@ -266,11 +255,6 @@ RegisterAGBase::RegisterAGBase(const std::type_info &Interface, } } -void RegisterAGBase::setGroupName(const char *Name) { - assert(InterfaceInfo->getPassName()[0] == 0 && "Interface Name already set!"); - InterfaceInfo->setPassName(Name); -} - //===----------------------------------------------------------------------===// // PassRegistrationListener implementation