questions about getAnalysisUsage

Hi,

   I notice that there are several different methods called inside getAnalysisUsage(). The parameters of addRequiredID and addPreservedID are passID. What is the difference between Required and Preserved? There are also function named addRequired<PassName>() called. What is the difference between addRequired<PassName>() and addRequiredID(PassID)?

   Thanks a lot!

   Best,

                                                           Linhai

Hi,

  I notice that there are several different methods called inside getAnalysisUsage(). The parameters of addRequiredID and addPreservedID are passID. What is the difference between Required and Preserved?

A Required pass is one that must be run before the pass requiring it. The required pass is an analysis pass that your pass will query for analysis information. This information is used by the PassManager to determine which analysis passes must be run before another analysis or optimization pass.

A Preserved pass is an analysis pass whose analysis results your pass does not modify. For example, a pass may modify the code in a way that does not modify the results of a dominator analysis. The PassManager uses this information to avoid rerunning expensive analyses unnecessarily.

There are also function named addRequired<PassName>() called. What is the difference between addRequired<PassName>() and addRequiredID(PassID)?

I suspect that addRequired<PassName>() and addRequiredID() do the same thing but have different inputs. When writing a pass, you should just use addRequired<PassName>(); I've never seen anyone use addRequiredID().

Regards,

John Criswell

addRequiredID is only used when PassName is not statically known. There’s an example in PassPrinters.cpp. I agree with John that you should use addRequired whenever possible.

Jingyue