Buse Yilmaz via llvm-dev
2018-Aug-25 21:22 UTC
[llvm-dev] correct way to pass data structures between passes?
Hi all, I have a function pass which does some analysis and populates A a; where typedef std::map< std::string, B* > A; class B { typedef std::vector< C* > D; D d; } class C { // some class packing information about basic blocks; } Hence I have a map of vectors traversed by string. I wrote associated destructors for these classes. This pass works successfully on its own. I have another function pass needing this structure of type A to make some transformations. I used bool secondPass::doInitialization(Module &M) { errs() << "now running secondPass\n"; a = getAnalysis<firstPass>().getA(); return false; } void secondPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<firstPass>(); AU.setPreservesAll(); } the whole code compiles fine. But I get seg. fault when printing this structure at the end of my first pass *if I call my second pass since B* is null.* How should I wrap this data structure and pass it to the second pass without issues? Thanks in advance. -- Buse -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180825/75d90b2b/attachment.html>
Bekket McClane via llvm-dev
2018-Aug-25 21:33 UTC
[llvm-dev] correct way to pass data structures between passes?
> On Aug 25, 2018, at 5:22 PM, Buse Yilmaz via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hi all, > I have a function pass which does some analysis and populates > > A a; > > where > > typedef std::map< std::string, B* > A; > > class B { > typedef std::vector< C* > D; > D d; > } > > class C { > // some class packing information about basic blocks; > } > > Hence I have a map of vectors traversed by string. > I wrote associated destructors for these classes. This pass works successfully on its own. > > I have another function pass needing this structure of type A to make some transformations. I used > > bool secondPass::doInitialization(Module &M) { > errs() << "now running secondPass\n"; > a = getAnalysis<firstPass>().getA();You probably shouldn't call getAnalysis in doInitialization. doInitialization, according to the document, “is designed to do simple stuff not depend on the functions begin processed”. You should call getAnalysis in runOnFunction.> > return false; > } > > void secondPass::getAnalysisUsage(AnalysisUsage &AU) const { > AU.addRequired<firstPass>(); > AU.setPreservesAll(); > } > > the whole code compiles fine. But I get seg. fault when printing this structure at the end of my first pass if I call my second pass since B* is null.Have you checked(set a breakpoint for example) to see if firstPass::runOnFunction is executed?> > How should I wrap this data structure and pass it to the second pass without issues? > > Thanks in advance. > > >Best, Bekket> > > -- > Buse > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180825/382131b5/attachment.html>