<div dir="ltr"><div>Hi,</div><div><br></div><div> I wrote my own FunctionPass that depends on DominatorTree and LoopInfo passes. Then my own pass is executed outside the LLVM optimizer infrastructure (I.e., in a main file). However, I got the following error: </div>
<div><br></div><div>LLVM/llvm-3.3.src/lib/IR/PassManager.cpp:637: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed.</div>
<div><br></div><div> Since the pass was not executed by opt, I took it that I did not need to register the pass or modify the LLVM code base to accommodate it ... Then I try to fix the problem by calling INITIALIZE_PASS_DEPENDENCY right after char XXXPass::ID=0. Then the compiler complains something about it has to be declared inside the llvm namespace. Any hints on how to fix that?</div>
<div><br></div><div>Best Regards,</div><div>Paulie</div><div><br></div><div><br></div><div>--------------------------- Code -----------------------------------</div><div><br></div><div>using namespace llvm;</div><div><br>
</div><div>class XXXPass : public FunctionPass {</div><div>public:</div><div> XXXPass() : FunctionPass(ID) {}</div><div><br></div><div> void getAnalysisUsage(AnalysisUsage &AU) const {</div><div> AU.setPreservesCFG();</div>
<div> AU.addRequired<DominatorTree>();</div><div> AU.addRequired<LoopInfo>();</div><div> }</div><div> virtual bool runOnFunction(Function &F) {</div><div> DominatorTree *DT = &getAnalysis<DominatorTree>();</div>
<div> LoopInfo *li = &getAnalysis<LoopInfo>();</div><div> return false;</div><div> }</div><div> static char ID;</div><div>};</div><div><br></div><div>char XXXPass::ID = 0;</div><div><br></div><div>int main(int argc, char **argv) {</div>
<div> SMDiagnostic Err;</div><div> Module *Mod = ParseIRFile(argv[2], Err, getGlobalContext());</div><div> if (!Mod) {</div><div> Err.print(argv[0], errs());</div><div> return 1;</div><div> }</div><div> Function *Func = Mod->getFunction("test");</div>
<div><br></div><div> PassManager PM;</div><div> PM.add(new XXXPass());</div><div> PM.run(*Mod);</div><div> return 0;</div><div>}</div></div>