[LLVMdev] How to keep FunctionPass analysis result alive in Module Pass?

Fan Long fanl at csail.mit.edu
Fri Mar 9 14:10:02 PST 2012


Hello,
	I am trying to write a new ModulePass using LoopInfo analysis result, but it seems I misunderstand some concept about PassManager. Basically I want to keep LoopInfo analysis result alive. Here is an example showing the problem I encountered, assuming I already addRequired<llvm::LoopInfo>() in getAnalysisUsage:
	
	void foo(llvm::Function *F1, llvm::Function *F2) {
		llvm::LoopInfo *LI1, LI2;
		LI1 = &getAnalysis<llvm::LoopInfo>(*F1);
		llvm::Loop* L1 = LI1->getLoopFor(F1->begin());
		LI2 = &getAnalysis<llvm::LoopInfo>(*F2);
		llvm::Loop* L2 = LI2->getLoopFor(F2->begin());
		L1->dump();  // crash
		L2->dump();
	}

	I checked why this program crashes. It is because the getAnalysis returns same LoopInfo instance. Each time it clears previous results and run it on the new function. Thus it invalidate the pointer L1 after calling &getAnalysis<llvm::LoopInfo>(*F2).
	
	My questions is whether there is a way to get around this, and to keep the analysis result of Function Pass of all functions alive during my Module Pass? I am using LLVM-3.1-svn version. I would really appreciate your help!

Best,
Fan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120309/cab130e2/attachment.bin>


More information about the llvm-dev mailing list