Doubt regarding getAnalysisUsage

Hi,

I have a doubt regarding getAnalysisUsage. My assumption is that, as analysis passes will not change the IR, all the passes required by an analysis pass should be preserved. Say, I have an analysis pass which requires another analysis pass called SomeAnalysis and I have not added AU.addPreserved() to my pass.

Would the pass manager still considers the SomeAnlaysis as preserved?

Hi,

the legacy pass manager (the one that uses getAnalysisUsage) makes no
distinction between analyses and other passes. E.g., passes can also
depend on transformative passes. If your pass is does not change the
IR, then you can add AU.setPreservesAll() into getAnalysisUsage. Any
additional addPreserved calls will have no effect as you told the pass
manager already that you preserve all passes.If you do not add
setPreservesAll/addPreserved the pass manager will treat your pass as
a transformative pass and re-compute SomeAnalysis after your pass has
run.

Michael

Hi,

the legacy pass manager (the one that uses getAnalysisUsage) makes no
distinction between analyses and other passes. E.g., passes can also
depend on transformative passes. If your pass is does not change the
IR, then you can add AU.setPreservesAll() into getAnalysisUsage. Any
additional addPreserved calls will have no effect as you told the pass
manager already that you preserve all passes.

If you do not add
setPreservesAll/addPreserved the pass manager will treat your pass as
a transformative pass and re-compute SomeAnalysis after your pass has
run.

I am under the impression that the pass manager will re-run the un-preserved analysis passes only if the current pass returns with a ‘true’.

The legacy pass manager uses a precomputed pass/analysis execution
order which does not (and cannot) depend on the dynamic return value
of the `runOn...` methods.

The advantage is the that this ensures that passes/analyses are free'd
directly after the last use and will be only computed once (per pass
manager of its level) if all passes preserve it.

The disadvantage is that it will be recomputed even if transforming
passes dynamically decide to not modify the IR.

Michael