From ebe18ef5c286bb7c33f6c43f1963a7d22cd73f40 Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Wed, 8 Feb 2012 21:22:34 +0000 Subject: [PATCH] Added Pass::createPass(ID) to handle pass configuration by ID git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150092 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/Passes.h | 2 +- include/llvm/Pass.h | 4 ++++ lib/CodeGen/Passes.cpp | 8 ++++++-- lib/VMCore/Pass.cpp | 7 +++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index 2585aebc1c0..88495717317 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -135,7 +135,7 @@ protected: /// /// Add a target-independent CodeGen pass at this point in the pipeline. - void addCommonPass(char &ID); + void addPass(char &ID); /// printNoVerify - Add a pass to dump the machine function, if debugging is /// enabled. diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 104b272d095..a0cbca121d5 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -175,6 +175,10 @@ public: // argument string, or null if it is not known. static const PassInfo *lookupPassInfo(StringRef Arg); + // createPass - Create a object for the specified pass class, + // or null if it is not known. + static Pass *createPass(char &TI); + /// getAnalysisIfAvailable() - Subclasses use this function to /// get analysis information that might be around, for example to update it. /// This is different than getAnalysis in that it can fail (if the analysis diff --git a/lib/CodeGen/Passes.cpp b/lib/CodeGen/Passes.cpp index eb567349830..2877cf165b6 100644 --- a/lib/CodeGen/Passes.cpp +++ b/lib/CodeGen/Passes.cpp @@ -103,8 +103,12 @@ TargetPassConfig::TargetPassConfig() llvm_unreachable("TargetPassConfig should not be constructed on-the-fly"); } -void TargetPassConfig::addCommonPass(char &ID) { - // FIXME: about to be implemented. +void TargetPassConfig::addPass(char &ID) { + // FIXME: check user overrides + Pass *P = Pass::createPass(ID); + if (!P) + llvm_unreachable("Pass ID not registered"); + PM.add(P); } void TargetPassConfig::printNoVerify(const char *Banner) const { diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 05d2efa850a..07ac3c35c1a 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -189,6 +189,13 @@ const PassInfo *Pass::lookupPassInfo(StringRef Arg) { return PassRegistry::getPassRegistry()->getPassInfo(Arg); } +Pass *Pass::createPass(char &TI) { + const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(&TI); + if (!PI) + return NULL; + return PI->createPass(); +} + Pass *PassInfo::createPass() const { assert((!isAnalysisGroup() || NormalCtor) && "No default implementation found for analysis group!");