Right now, addPassesToEmitFile requires a FunctionPassManager. If I'm
working with code that uses a plain PassManager and want it to generate
code, are there any options better than doing this:
/**
* Wrapper class to run a FunctionPassManager as a ModulePass so that it
* can be added to a plain PassManager.
*/
class FunctionPassManagerModulePass : public ModulePass {
FunctionPassManager &Passes;
public:
static char ID; // Pass ID, replacement for typeid
explicit FunctionPassManagerModulePass(FunctionPassManager &FPM) :
ModulePass((intptr_t)&ID),
Passes(FPM)
{}
bool runOnModule(Module &M) {
bool Changes = false;
Changes |= Passes.doInitialization();
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration())
Changes |= Passes.run(*I);
Changes |= Passes.doFinalization();
return Changes;
}
};
?
Thanks,
Dan
--
Dan Gohman, Cray Inc.
On Jun 21, 2007, at 4:13 PM, Dan Gohman wrote:> Right now, addPassesToEmitFile requires a FunctionPassManager. If I'm > working with code that uses a plain PassManager and want it to > generate > code, are there any options better than doing this:That's what FPPassManager does (include/llvm/PassManagers.h) . Function pass manager itself is a module level pass. FunctionPassManager is external stand alone interface hence it does not derive from ModulePass. - Devang> /** > * Wrapper class to run a FunctionPassManager as a ModulePass so that > it > * can be added to a plain PassManager. > */ > class FunctionPassManagerModulePass : public ModulePass { > FunctionPassManager &Passes; > public: > static char ID; // Pass ID, replacement for typeid > explicit FunctionPassManagerModulePass(FunctionPassManager &FPM) : > ModulePass((intptr_t)&ID), > Passes(FPM) > {} > > bool runOnModule(Module &M) { > bool Changes = false; > > Changes |= Passes.doInitialization(); > > for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) > if (!I->isDeclaration()) > Changes |= Passes.run(*I); > > Changes |= Passes.doFinalization(); > > return Changes; > } > }; > > > ? > > Thanks, > > Dan > > -- > Dan Gohman, Cray Inc. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On Thu, Jun 21, 2007 at 04:37:14PM -0700, Devang Patel wrote:> > On Jun 21, 2007, at 4:13 PM, Dan Gohman wrote: > > > Right now, addPassesToEmitFile requires a FunctionPassManager. If I'm > > working with code that uses a plain PassManager and want it to > > generate > > code, are there any options better than doing this: > > That's what FPPassManager does (include/llvm/PassManagers.h) . > Function pass manager itself is a module level pass. > FunctionPassManager is external stand alone interface hence it does > not derive from ModulePass.To be clear, I'm specifically talking about addPassesToEmitFile and other functions in include/llvm/Target/TargetMachine.h which, as currently written, require an actual FunctionPassManager. It doesn't look like FPPassManager is immediately useful here. Looking at this some more, I'm wondering if it would make sense to add a run(Module &) method to FunctionPassManager, for this purpose. Dan -- Dan Gohman, Cray Inc.