[LLVMdev] PassManager vs FunctionPassManager

Dan Gohman djg at cray.com
Thu Jun 21 16:13:05 PDT 2007


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.



More information about the llvm-dev mailing list