[llvm-dev] correct way to pass data structures between passes?

Bekket McClane via llvm-dev llvm-dev at lists.llvm.org
Sat Aug 25 14:33:57 PDT 2018



> 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>


More information about the llvm-dev mailing list