Hi, I'm confused about the is_analysis parameter of the RegisterPass constructor (defined in PassSupport.h). The only explanation I can find is that is_analysis should be set to true if the pass is "an analysis pass, for example dominator tree pass". Can someone please clarify what is meant by "analysis pass"? Also -- and this is more of a C++ question than an LLVM question -- the Hello pass (in lib/Transforms/Hello/Hello.cpp) puts its class inside an anonymous namespace. But I thought an anonymous namespace limits the scope of anything in that namespace to the file level (so you can't call the functions in that namespace from outside the file). If so, how is it possible for LLVM to access the Hello pass? Thanks, Trevor
On Thursday 25 February 2010 19:24:30 Trevor Harmon wrote:> Hi, > > I'm confused about the is_analysis parameter of the RegisterPass > constructor (defined in PassSupport.h). The only explanation I can > find is that is_analysis should be set to true if the pass is "an > analysis pass, for example dominator tree pass". Can someone please > clarify what is meant by "analysis pass"?I don't have the sources at my fingertips but my expectation is that if is_analysis is true, LLVM assumes the pass does not modify the IR.> Also -- and this is more of a C++ question than an LLVM question -- > the Hello pass (in lib/Transforms/Hello/Hello.cpp) puts its class > inside an anonymous namespace. But I thought an anonymous namespace > limits the scope of anything in that namespace to the file level (so > you can't call the functions in that namespace from outside the file). > If so, how is it possible for LLVM to access the Hello pass?The RegisterPass template takes care of notifying the PassManager that the pass exists. One of the advantages of PassManager is that it decouples pass execution from the rest of the infrastructure so the class need not be visible to anything outside the implementation of the pass itself. HTH. -Dave
On Feb 25, 2010, at 5:45 PM, David A. Greene wrote:> The RegisterPass template takes care of notifying the PassManager > that the pass exists. One of the advantages of PassManager is > that it decouples pass execution from the rest of the infrastructure > so the class need not be visible to anything outside the > implementation > of the pass itself.Even though the PassManager implements the Hollywood Principle, something outside of the pass implementation still has to invoke one of the runOn* functions. And I'm not understanding how this invocation can occur if the implementation is invisible. Maybe I should just chalk this up to template magic... On a related note, the source code comments in PassSupport.h (line 156) say that the RegisterPass instance should be declared in the global scope, and indeed, the Hello.cpp example puts it in the global scope. However, the "Writing an LLVM Pass" document puts it in the anonymous namespace, and when I tried this on my own pass implementation, it worked fine. Is there a particular reason why it has to be in the global scope? (Maybe if I understood the contradiction, I'd be able to understand my original question.) Thanks, Trevor
On Thu, Feb 25, 2010 at 5:24 PM, Trevor Harmon <Trevor.W.Harmon at nasa.gov> wrote:> Hi, > > I'm confused about the is_analysis parameter of the RegisterPass > constructor (defined in PassSupport.h). The only explanation I can > find is that is_analysis should be set to true if the pass is "an > analysis pass, for example dominator tree pass". Can someone please > clarify what is meant by "analysis pass"?An analysis pass collects information. A transformation/codegen pass operates on IR. This flag is used by pass manager to decide whether to run a requested pass again or not. The user may intentionally want to run a transformation pass multiple times. For example, $ opt -dom-tree -dom-tree -instcombine -instcombine in.bc -o out.bc runs dominator tree pass only once, but instcombine pass twice. - Devang