Devang Patel wrote:> On Jul 25, 2008, at 12:58 PM, Marc de Kruijf wrote: > > I'd like to write a pass that does both: implements a code transformation and saves information that can be accessed by subsequent passes. > > Ideally, we want to use two separate pass. However, it is quiet possible that your requirement is unique. Would it be possible to provide more info. on what your pass does ? >We actually have a similar situation with Automatic Pool Allocation (APA) and SAFECode. Some of the SAFECode passes need to query the Automatic Pool Allocation transform pass to determine what it has done. Examples include: 1) Given a pointer, what pool did APA use to allocate objects to which the pointer can point? 2) Is a function a clone of an original function, and if so, which function is the original function? 3) What is the LLVM type of a pool descriptor? Different versions of APA use a different type. I think we could refactor APA into an analysis pass and transform pass. The analysis pass does nothing on its own but has update methods that other passes can use to update it's information. When APA is run, it updates the analysis pass, and when the SAFECode passes run, they get the APA information from the analysis pass. Just FYI. -- John T.> If such a pass is not an Analysis pass and that therefore subsequent passes are not supposed to use getAnalysis() to extract the information from that pass... what is the right way to do this? > > > Right now I am using getAnalysis to get the information from the non-analysis (transformation) pass. It works, but now it sounds like that's not correct usage.... > > One alternative approach is to use getAnalysisToUpdate() to access this info. This interface does not require you to register requirement using getAnalysisUsage(). getAnalysisToUpdate() will return null if the requested info is not available and users are expected to handle this. > > The reason why it is not a good idea to request transformation pass through getAnalysisUsage() is: when requested transformation pass does not preserve some info that is required by the original pass then pass manager may not able to handle this properly. > > However, if there is a good requirement, I'm ready to let getAnalysis() access transformation pass. > - > Devang > > > > > Marc > > On Fri, Jul 25, 2008 at 2:01 PM, Devang Patel <dpatel at apple.com<mailto:dpatel at apple.com>> wrote: > > On Jul 25, 2008, at 10:56 AM, Marc de Kruijf wrote: > > >> Could somebody please explain exactly what an "analysis pass" is? >> I've spent some time trying to understand this and I just don't get >> it. Right now my understanding is the following: if a pass is an >> "analysis" pass, the "print" function is called when giving the "- >> analyze" switch to opt. >> > > Yes. > > >> Is there more to it than that? >> > > Analysis pass collects information that is used by other passes, for > example alias info., loop info, dominator info etc.. > > >> If I've got it wrong, here are some potentially clarifying questions: >> >> 1. If a pass is an analysis pass, does it necessarily not alter the >> CFG? >> > > Yes, Analysis passes do not alter CFG. > > >> 2. Does a pass need to be an analysis pass if it is used by another >> pass calling getAnalysisUsage? >> > > The other passes uses getAnalysisUsage() to access information > collected by an analysis information. getAnalysisUsage() interface > should not be used to order transformation/code generation passes. > There are couple of cases where code generator violates this and I'd > like to eventually fix it. > > >> 3. How does whether or not a pass is an analysis pass or not affect >> the pass's execution? >> > > In general it does not. Analysis pass is executed just like any other > pass. > > The distinction is important for the pass manager, who is responsible > to automatically schedule an analysis pass if the analysis info is not > available (or dirty) and is required by a transformation pass. > > One small distinction is - pass manager will not re-run an analysis > pass if the information is up-to-date. However, the pass manager will > re-run a transformation pass if requested to do so. > > For example, > $ opt -domtree -domtree a.bc -disable-output > will run dominator tree analysis pass only once. > $ opt -instcombine -instcombine a.bc -disable-output > will run instruction combiner pass twice. > > - > Devang > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >
On Jul 25, 2008, at 16:57, John Criswell wrote:> Devang Patel wrote: > >> On Jul 25, 2008, at 12:58 PM, Marc de Kruijf wrote: >> >> I'd like to write a pass that does both: implements a code >> transformation and saves information that can be accessed by >> subsequent passes. >> >> Ideally, we want to use two separate pass. However, it is quiet >> possible that your requirement is unique. Would it be possible to >> provide more info. on what your pass does ? > > We actually have a similar situation with Automatic Pool Allocation > (APA) and SAFECode. Some of the SAFECode passes need to query the > Automatic Pool Allocation transform pass to determine what it has > done. Examples include: > > 1) Given a pointer, what pool did APA use to allocate objects to > which the pointer can point? > 2) Is a function a clone of an original function, and if so, which > function is the original function? > 3) What is the LLVM type of a pool descriptor? Different versions > of APA use a different type. > > I think we could refactor APA into an analysis pass and transform > pass. The analysis pass does nothing on its own but has update > methods that other passes can use to update it's information. When > APA is run, it updates the analysis pass, and when the SAFECode > passes run, they get the APA information from the analysis pass.This use case is not adequately serviced by the current LLVM pass manager. I had a similar problem with the GC metadata information. Ultimately, I had to structure it as an ImmutablePass (with an explicit pass to free the contained information) because it would be invalidated by other passes at random. This is essentially the same approach used to manage the MachineFunction representation. Speaking of which, I also have also attempted to eliminate Annotatable by storing the MachineFunction in a FunctionPass analysis used only to maintain the MachineFunction representation. That experiment failed for essentially the same reason. (It would've succeeded if I'd thought to use an ImmutablePass at the time.) Unsatisfactory. — Gordon
On Jul 25, 2008, at 1:57 PM, John Criswell wrote:> Devang Patel wrote: >> On Jul 25, 2008, at 12:58 PM, Marc de Kruijf wrote: >> >> I'd like to write a pass that does both: implements a code >> transformation and saves information that can be accessed by >> subsequent passes. >> >> Ideally, we want to use two separate pass. However, it is quiet >> possible that your requirement is unique. Would it be possible to >> provide more info. on what your pass does ? >> > We actually have a similar situation with Automatic Pool Allocation > (APA) and SAFECode. Some of the SAFECode passes need to query the > Automatic Pool Allocation transform pass to determine what it has > done. > Examples include: > > 1) Given a pointer, what pool did APA use to allocate objects to which > the pointer can point? > 2) Is a function a clone of an original function, and if so, which > function is the original function? > 3) What is the LLVM type of a pool descriptor? Different versions of > APA use a different type. > > I think we could refactor APA into an analysis pass and transform > pass. > The analysis pass does nothing on its own but has update methods that > other passes can use to update it's information. When APA is run, it > updates the analysis pass, and when the SAFECode passes run, they get > the APA information from the analysis pass. > > Just FYI.Let's say you do not refactor APA into two passes. And continue to request APA through getAnalysisUsage(). How does requesting APA ( a transformation pass) through getAnalysisUsage() help here ? Note, getAnalysisUsage() is a pass manager contract that ensures that APA pass is available. It does not handle how information is stored and extracted. Let's say your APA pass implements APA { void runOnFunction(); // do pool allocation. A const PoolInfo *getPoolInfo(); // provides pool info }; If pass A1 and A2 wants to use info collected during APA and request it through getAnalysisUsage() then following might happen A1 // requires APA SomeOtherPass // does not preserve APA A2 // requires APA will instruction pass manager to schedule APA A1 SomeOtherPass APA A2 Is it appropriate to run APA transformation pass twice ? - Devang
This seems like a separate issue. On Jul 26, 2008, at 5:56 PM, Gordon Henriksen wrote:> I had a similar problem with the GC metadata information. Ultimately, > I had to structure it as an ImmutablePass (with an explicit pass to > free the contained information) because it would be invalidated by > other passes at random.If GC metadata information is not explicitly listed as preserved and the GC metadata pass is not ImmutablePass the, of course, the pass manager will consider the info not available (or dirty) as soon as the pass manager schedules a pass that does not explicitly preserve GC metadata. What else pass manager could do here ? - Devang