Buse Yilmaz via llvm-dev
2018-Aug-27 16:25 UTC
[llvm-dev] correct way to pass data structures between passes? Now data structure is retrieved successfully. But I need a little more help
Hello Bekket, Thanks a lot for your reply. Here's what I did: I wrote a ModulePass. In my module pass I do bool MCRBuilder::runOnModule(Module &M) { errs() << "hello world!\n"; for(Function& F : M) { errs() << "F: " << F.getName() << "\n"; if(!F.getName().equals("main") && !F.isDeclaration()) getAnalysis<firstPass>(F); } StringRef main = StringRef("main"); A& a = getAnalysis<firstPass>(*(M.getFunction(main))).getA(); } void MCRBuilder::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<firstPass>(); } Now this works. structure a is successfully received. I can confirm that I can print A a. Now I can invoke opt as: opt -load ./libLLVMPasses.so -modulePass < hello.bc But I need a little bit more help. I added this line and it gets a seg. fault. getAnalysis<firstPass>().printA(); I wrote a wrapper pass (basically I examined BranchProbabilityInfoWrapperPass) for firstPass so that I can get the pass object and invoke its functions. namespace llvm { class firstPassWrapperPass : public FunctionPass { firstPass FT; public: static char ID; firstPassWrapperPass() : FunctionPass(ID) {} firstPass &getFT() { return FT; } //void getAnalysisUsage(AnalysisUsage &AU) const override; bool runOnFunction(Function &F) override; }; } using namespace llvm; char firstPassWrapperPass::ID = 0; static RegisterPass<firstPassWrapperPass> XWrapper("firstPassWrapper", "firstPass Wrapper Pass", false /* Only looks at CFG */, false /* Analysis Pass */); bool firstPassWrapperPass::runOnFunction(Function &F) { errs() << F.getName() << "in firstPassWrapperPass\n"; return false; } I added this to my module pass and it gets a seg. fault too. firstPass& FT = getAnalysis<firstPassWrapperPass>().getFT(); FT.printA(); I don't know what I'm doing wrong. Could anyone help me with this? Last problem: 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. 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. How can I achieve this? What are the examples in the llvm source code that I can look at? Thank you very much! -- Buse -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180827/e2b8b94a/attachment-0001.html>