Skip to main content

Module analysis

Module analysis 

Source
Expand description

The analysis cache, and what a pass has to say about what it left standing.

Design: section 4.3 of spec/optimizer/04-pass-manager.md, which calls this the analysis manager and gives it four jobs and no more than four. Compute an analysis when somebody asks and keep the answer. Throw an answer away when a pass says it broke the thing the answer was about. Throw away everything built on top of that answer at the same time. Catch a pass that says it preserved something it did not.

The type is called Analyses rather than Manager because this crate already has a pass manager in crate::pipeline, and a bare Manager re-exported at the top of the crate would not say which of the two it was.

§What is cached and what is not

The nine here are the nine that own their data: Cfg, Dominators, PostDominators, Loops, Frontiers, ControlDependence, Frequencies, Liveness and Pressure. Each is built from the function once and then answers questions without looking at it again, so each is a thing a cache can hold.

The rest of the analyses in this crate are not here and do not belong here. crate::Alias, crate::memssa, crate::Scev and crate::range::query::Ranges all borrow the function they answer about, which means holding one across an edit is not something the cache would have to be careful about, it is something the compiler refuses. They are query engines built on top of the ones here, and the ones here are what they cost.

§Why the cache is keyed by function elsewhere

There is one of these per function, and crate::pipeline keeps a map from function to cache because it runs a pass over the whole module before the next pass starts. Under that order a cache that lived only as long as one function would be thrown away between every pass and every analysis would be recomputed for every pass that wanted it. Section 4.2 of the design says to turn the loop inside out in M4 and run every pass over one function before moving to the next, and the day that lands the map goes away and one of these lives on the stack of the loop.

Structs§

Analyses
The analyses of one function, computed when asked for and kept until something breaks them.
Preserved
What a pass leaves standing.

Enums§

Analysis
One analysis this cache holds.