[LLVMdev] getAnalysisIfAvailable<>(...)

Garrison Venn
Tue, 08 Dec 2009 19:11:26 -0000

Is it consistent to have a Pass instance's run method's implementation
use getAnalysisIfAvailable<AnalysisType>() (vs just using getAnalysis<
AnalysisType >) when that same instance's getAnalysisUsage(AnalysisUsage
&au) implementation invokes au.addRequired<AnalysisType>()?

For example in the implementation of SelectionDAGISel::runOnMachineFunction(...)
(called from MachineFunctionPass::runOnFunction(...)):

DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();

is used vs:

DwarfWriter &DW = getAnalysis<DwarfWriter>();

even though SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) sets:

AU.addRequired<DwarfWriter>();

Since this occurs in 2.6 and trunk, and this pattern is repeated with other
analysis passes, I'm wondering if I'm not understanding something.

Thanks in advance

Garrison