Hello, I am trying to add some thing into LLVM, while I encountered some problems. So my situation is that I have some information W, some transform passes may change it, after these passes, I need the new W. What I did is to create an analysis pass similar to scalar-evolution or loopinfo, I can get the information by using getAnalysis<W>(); and preserve this information W by using AU.addPreserved<W>();. Then the problem came, for the module pass, the information can’t be preserved. (I found this: To the best of my knowledge, the LLVM pass manager never preserves a FunctionPass analysis that is requested by a ModulePass; every time you call getAnalysis for a function, the FunctionPass is re-run. http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html ) So this means that I can’t update W when some module passes changed it? My questions are: 1, Module pass really can’t preserve the W? 2, If it’s real, why and how can I fix this? If it’s not, what should I do to keep the information W? 3, The way of using an analysis pass to keep the information of W is suitable? Any other better solution? Thank you, Best regards, Hanbing -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140404/b8576129/attachment.html>
John Criswell
2014-Apr-04 22:27 UTC
[LLVMdev] Add a new information and preserve it in LLVM
On 4/4/14 3:02 PM, Hanbing Li wrote:> > Hello, > > > I am trying to add some thing into LLVM, while I encountered some > problems. > > > So my situation is that I have some information W, some transform > passes may change it, after these passes, I need the new W. What I did > is to create an analysis pass similar to scalar-evolution or loopinfo, > I can get the information by using getAnalysis<W>(); and preserve this > information W by using AU.addPreserved<W>();. Then the problem came, > for the module pass, the information can't be preserved. (I found > this: To the best of my knowledge, the LLVM pass manager never > preserves a FunctionPass analysis that is requested by a ModulePass; > every time you call getAnalysis for a function, the FunctionPass is > re-run. > http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html) So > this means that I can't update W when some module passes changed it? > > > My questions are: > > 1, Module pass really can't preserve the W? >If W is a FunctionPass, then I believe you are correct: a ModulePass will re-run the FunctionPass every time it uses the FunctionPass. I get the impression that you're using the PassManager infrastructure improperly, and that is probably why you're not getting the results you want. First, the ability to preserve a pass's results with addPreserved<W>() is an optimization. A FunctionPass or ModulePass() that analyzes the LLVM IR should work whether it is run one time or a hundred times. The addPreserved<>() functionality is only there so that the LLVM compiler can cache the results of analysis passes for efficiency. Second, the way to fix your problem depends on what you want to do. If you want pass W to analyze the LLVM IR of a program and cache its results (because the analysis it does is expensive), then make it a ModulePass. That way, other ModulePass'es can update and preserve its results. If you are just using W as a container in which to record information that transform passes are doing, then you might want to make W an ImmutablePass. ImmutablePasses are only run once and are never invalidated; other passes can use them to record information about what they do. ImmutablePasses, I think, were not really designed for this purpose, but they'll get the job done. Regards, John Criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140404/87c2a043/attachment.html>
Hi John, Thank you for your answer. I tried ImmutablePasses, while the problem came again. Because the W need some information like loopinfo, so I need LoopInfo *LI = &getAnalysis<LoopInfo>(F); in this ImmutablePasses, and Function or Module are needed. I didn't find a way to get the Module or Function in ImmutablePasses. So, 1, can I use LoopInfo *LI = &getAnalysis<LoopInfo>(F); in ImmutablePasses? 2, is there a method to get the Module in ImmutablePasses? Thank you! Sincerely, Hanbing ----- Mail original -----> De: "John Criswell" <criswell at illinois.edu> > À: "Hanbing Li" <hanbing.li at inria.fr>, llvmdev at cs.uiuc.edu > Envoyé: Samedi 5 Avril 2014 00:27:13 > Objet: Re: [LLVMdev] Add a new information and preserve it in LLVM> On 4/4/14 3:02 PM, Hanbing Li wrote:> > Hello, >> > I am trying to add some thing into LLVM, while I encountered some problems. >> > So my situation is that I have some information W, some transform passes > > may > > change it, after these passes, I need the new W. What I did is to create an > > analysis pass similar to scalar-evolution or loopinfo, I can get the > > information by using getAnalysis<W>(); and preserve this information W by > > using AU.addPreserved<W>();. Then the problem came, for the module pass, > > the > > information can’t be preserved. (I found this: To the best of my knowledge, > > the LLVM pass manager never preserves a FunctionPass analysis that is > > requested by a ModulePass; every time you call getAnalysis for a function, > > the FunctionPass is re-run. > > http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html ) So this > > means that I can’t update W when some module passes changed it? >> > My questions are: >> > 1, Module pass really can’t preserve the W? >> If W is a FunctionPass, then I believe you are correct: a ModulePass will > re-run the FunctionPass every time it uses the FunctionPass.> I get the impression that you're using the PassManager infrastructure > improperly, and that is probably why you're not getting the results you > want.> First, the ability to preserve a pass's results with addPreserved<W>() is an > optimization. A FunctionPass or ModulePass() that analyzes the LLVM IR > should work whether it is run one time or a hundred times. The > addPreserved<>() functionality is only there so that the LLVM compiler can > cache the results of analysis passes for efficiency.> Second, the way to fix your problem depends on what you want to do. If you > want pass W to analyze the LLVM IR of a program and cache its results > (because the analysis it does is expensive), then make it a ModulePass. That > way, other ModulePass'es can update and preserve its results.> If you are just using W as a container in which to record information that > transform passes are doing, then you might want to make W an ImmutablePass. > ImmutablePasses are only run once and are never invalidated; other passes > can use them to record information about what they do. ImmutablePasses, I > think, were not really designed for this purpose, but they'll get the job > done.> Regards,> John Criswell-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140407/0061b257/attachment.html>
Daniel Stewart
2014-Apr-17 19:29 UTC
[LLVMdev] Add a new information and preserve it in LLVM
"The addPreserved<>() functionality is only there so that the LLVM compiler can cache the results of analysis passes for efficiency." The addPreserved() function only tells the compiler to cache it? I was under the impression from the code that it was an indication that a transformation pass doesn't invalidate whatever analysis pass it says it preserves. If it is only an indication that the compiler should cache it, how does the compiler know if a particular analysis pass should be re-run? I'm going through the LegacyPassManager now and there definitely are some parts I don't understand what they are for. Daniel From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of John Criswell Sent: Friday, April 04, 2014 6:27 PM To: Hanbing Li; llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Add a new information and preserve it in LLVM On 4/4/14 3:02 PM, Hanbing Li wrote: Hello, I am trying to add some thing into LLVM, while I encountered some problems. So my situation is that I have some information W, some transform passes may change it, after these passes, I need the new W. What I did is to create an analysis pass similar to scalar-evolution or loopinfo, I can get the information by using getAnalysis<W>(); and preserve this information W by using AU.addPreserved<W>();. Then the problem came, for the module pass, the information can't be preserved. (I found this: To the best of my knowledge, the LLVM pass manager never preserves a FunctionPass analysis that is requested by a ModulePass; every time you call getAnalysis for a function, the FunctionPass is re-run. http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html) So this means that I can't update W when some module passes changed it? My questions are: 1, Module pass really can't preserve the W? If W is a FunctionPass, then I believe you are correct: a ModulePass will re-run the FunctionPass every time it uses the FunctionPass. I get the impression that you're using the PassManager infrastructure improperly, and that is probably why you're not getting the results you want. First, the ability to preserve a pass's results with addPreserved<W>() is an optimization. A FunctionPass or ModulePass() that analyzes the LLVM IR should work whether it is run one time or a hundred times. The addPreserved<>() functionality is only there so that the LLVM compiler can cache the results of analysis passes for efficiency. Second, the way to fix your problem depends on what you want to do. If you want pass W to analyze the LLVM IR of a program and cache its results (because the analysis it does is expensive), then make it a ModulePass. That way, other ModulePass'es can update and preserve its results. If you are just using W as a container in which to record information that transform passes are doing, then you might want to make W an ImmutablePass. ImmutablePasses are only run once and are never invalidated; other passes can use them to record information about what they do. ImmutablePasses, I think, were not really designed for this purpose, but they'll get the job done. Regards, John Criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140417/e3179398/attachment.html>