<div dir="ltr">Hello Bekket,<div>Thanks a lot for your reply. Here's what I did:</div><div><br></div><div>I wrote a ModulePass.</div><div><br></div><div>In my module pass I do</div><div><div>bool MCRBuilder::runOnModule(Module &M) {</div><div>      errs() << "hello world!\n";</div><div>   </div><div>      for(Function& F : M) {</div><div>         errs() << "F: " << F.getName() << "\n";</div><div>         if(!F.getName().equals("main") && !F.isDeclaration())</div><div>          getAnalysis<firstPass>(F);</div><div>   }</div></div><div><br></div><div><div>   StringRef main = StringRef("main");</div><div>   A& a = getAnalysis<firstPass>(*(M.getFunction(main))).getA();</div></div><div>}</div><div><br></div><div><div><div>void MCRBuilder::getAnalysisUsage(AnalysisUsage &AU) const {</div><div>    AU.addRequired<firstPass>();</div></div><div>}</div></div><div><br></div><div>Now this works. structure a is successfully received. I can confirm that I can print A a. Now I can invoke opt as:</div><div>opt -load ./libLLVMPasses.so  -modulePass < hello.bc<br></div><div><br></div><div>But I need a little bit more help.  I added this line and it gets a seg. fault.</div><div>getAnalysis<firstPass>().printA();<br></div><div><br></div><div>I wrote a wrapper pass (basically I examined BranchProbabilityInfoWrapperPass) for firstPass so that I can get the pass object and invoke its functions.<br></div><div><div>namespace llvm {</div><div>class firstPassWrapperPass : public FunctionPass {</div><div> firstPass FT;</div><div><br></div><div> public:</div><div>   static char ID;</div><div><br></div><div>   firstPassWrapperPass() : FunctionPass(ID) {}</div><div><br></div><div>   firstPass &getFT() { return FT; }</div><div><br></div><div>   //void getAnalysisUsage(AnalysisUsage &AU) const override;</div><div>   bool runOnFunction(Function &F) override;</div><div> };</div><div>}</div><div><br></div><div>using namespace llvm;</div><div>char firstPassWrapperPass::ID = 0;</div><div>static RegisterPass<firstPassWrapperPass> XWrapper("firstPassWrapper", "firstPass Wrapper Pass",</div><div>                                         false /* Only looks at CFG */,</div><div>                                         false /* Analysis Pass */);</div><div><br></div><div>bool firstPassWrapperPass::runOnFunction(Function &F) {</div><div>  errs() << F.getName() << "in firstPassWrapperPass\n";</div><div><br></div><div>  return false;</div><div>}</div></div><div><br></div><div>I added this to my module pass and it gets a seg. fault too.</div><div><div>firstPass& FT = getAnalysis<firstPassWrapperPass>().getFT();</div><div>FT.printA();</div></div><div><br></div><div>I don't know what I'm doing wrong. Could anyone help me with this?</div><div><br></div><div>Last problem:</div><div>My goal is to run my firstPass on all functions (it's an analysis pass) and get the built data structure(s) so that my secondPass can transform whatever is accumulated in A.</div><div>But passes run on functions in a per function fashion. I want my secondPass to run right after firstPass when it's finished and on a subset of the functions.</div><div>How can I achieve this? What are the examples in the llvm source code that I can look at?</div><div><br></div><div>Thank you very much!</div><div><br></div><div><br></div><div><br></div><div> </div><div><br></div><div><br></div><div><br></div><div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Buse</div></div></div></div>