This is an archive of the discontinued LLVM Phabricator instance.

[docs][NewPM] Add section on analyses
ClosedPublic

Authored by aeubanks on Apr 20 2021, 4:36 PM.

Diff Detail

Event Timeline

aeubanks requested review of this revision.Apr 20 2021, 4:36 PM
aeubanks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 4:36 PM
mtrofin added inline comments.Apr 20 2021, 5:52 PM
llvm/docs/NewPassManager.rst
147

So does the LPM. We could say "similar to the legacy pass manager, the new pass manager has...". I'd add "there are differences, though, in how passes communicate to the infrastructure to ensure the validity of the cached values"

199

I'd stress here that this must be used when deleting the IR, explicitly, by the pass - and show the code example. I'd also stress that if passes don't do that, the risk is that the same key (==obj pointer) may be used for newly allocated IR and the stale cached value may appear valid when it's not.

239

but for simple cases that's not necessary, the default impl does that, no?

293

I'd recommend adding a subsection with guidelines for analysis authors, and one for consumers of analyses (i.e. pass authors), distilling the design into actionable DO/DON'T statements. Like "don't implement invalidate() and return false, unless you really mean to develop an immutable analysis*)

*assuming we fix the issues of bulk-invalidation by the likes of cgscc AM, but I digress :)

aeubanks added inline comments.Apr 20 2021, 7:26 PM
llvm/docs/NewPassManager.rst
147

I'm not explicitly trying to compare the new PM to the legacy PM in this doc. The couple points in this doc about the legacy PM are either about removing it in the future, or quick API differences for people who don't want to learn about the new PM in detail and just want to port things quickly

239

There's no default implementation?
Each analysis's Result type needs to implement invalidate(). Although that does bring up a good point that it's specifically the result that implements it, not the analysis interface. Will clarify.

293

good point, this is mixing users and implementors of analyses, I'll try to make the distinction better

mtrofin added inline comments.Apr 20 2021, 7:53 PM
llvm/docs/NewPassManager.rst
239

See PassManagerInternal.h:172 - there's a wrapper to the analysis result concept. Result::invalidate doesn't need to be implemented unless it does something non-trivial.

aeubanks added inline comments.Apr 20 2021, 8:26 PM
llvm/docs/NewPassManager.rst
199

Will do, although it's only an issue if a pass deletes then adds functions.

239

Oh I didn't know that, thanks for the pointer! Will definitely put that in.

aeubanks updated this revision to Diff 339093.Apr 20 2021, 9:22 PM

address comments

aeubanks updated this revision to Diff 339094.Apr 20 2021, 9:26 PM

mention stateless analyses

ychen added a comment.Apr 21 2021, 5:37 PM

Thanks for writing this up. It is very helpful. Some comments inline.

llvm/docs/NewPassManager.rst
243

It would be great to mention that we only do this for inner proxy and in the condition that it matters for performance. In other cases, users should stick with retuned PreservedAnalyses.

259

How about calling it Dependent analysis Invalidation or Analysis Invalidation Propagation or something similar? I think that's the motivation for PassResult::invalidate. Personally Analysis Invalidation reminds me of the returned PreservedAnalyses which is related but not exactly the same thing.

aeubanks updated this revision to Diff 339846.Apr 22 2021, 7:32 PM

address comments

aeubanks updated this revision to Diff 339847.Apr 22 2021, 7:34 PM

slight wording change

aeubanks marked an inline comment as done.Apr 22 2021, 7:34 PM
aeubanks added inline comments.
llvm/docs/NewPassManager.rst
259

Implementing Analysis Invalidation?

asbirlea added inline comments.Apr 24 2021, 12:09 PM
llvm/docs/NewPassManager.rst
161

s/peer/peek

165

s/a outer/an outer

184

I'd also stress that in the current design, outer analyses are not invalidated until all the passes at that IR level are completed. So using an outer analysis that is not immutable leaves the door open for using incorrect or incomplete analyses. The work around for this is what we do between the Function and Loop IR unit levels with LoopAnalysisResults, where analyses are Function level but used and *updated* by all the Loop passes in the respective LoopPassManager. These are a limited set of trusted analyses and by contract the loop passes will preserve all. This approach makes it harder to "get things wrong" by preventing passes to retrieve arbitrary outer analysis. They can still do it, but they'll need to jump through some hoops to respect the "preserve" contract.

318

s/when we invalidating/when we invalidate

aeubanks updated this revision to Diff 340862.Apr 27 2021, 8:45 AM

address comments

asbirlea accepted this revision.Apr 27 2021, 12:14 PM

Thank you writing this, well written and useful doc.
No more big comments from my side, please wait to see if the others have additional comments.

llvm/docs/NewPassManager.rst
202

s/updated/updated in

This revision is now accepted and ready to land.Apr 27 2021, 12:14 PM
ychen accepted this revision.Apr 29 2021, 12:12 AM

LGTM

This revision was automatically updated to reflect the committed changes.
Matt added a subscriber: Matt.May 4 2021, 6:35 AM
Matt added inline comments.
llvm/docs/NewPassManager.rst
152

s/does/has

aeubanks added inline comments.May 4 2021, 10:22 AM
llvm/docs/NewPassManager.rst
152