Expand description
What a function does to memory, one answer for each pointer parameter.
Section 34.3 of spec/optimizer/34-ipa.md, and the analysis section 34.6 asks for right after
crate::purity. Purity answers one question about the whole of memory: does this function
read it, does it write it. That is enough to delete a call whose result nobody reads and it is
not enough to move a load past one, because a loop that calls helper(other) and reloads
mine[i] does not want to know whether helper wrote something. It wants to know whether
helper wrote this, and the answer to that is per parameter.
§What a summary holds, which is section 34.6’s deliverable and no more
For each pointer parameter: does the function read through it, does it write through it, does the address go somewhere the caller cannot see. And one answer for everything else, which is the globals and every address the body did not get as an argument.
No offsets, no sizes, no access trees, no aggregate granularity. A parameter is a whole object
here or it is nothing. gcc/ipa-modref.cc keeps far more than this over five and a half
thousand lines, and the part that pays for itself in a loop is the part that is here.
§Working it out
summarize is the analysis and it goes the way crate::purity::infer goes, for section
34.5’s reason: start every function at “touches nothing”, read the bodies over the condensation
callee before caller, and lower an answer when the body contradicts it. Starting at the other
end and raising would answer “writes everything” for a pair of functions that call each other
and touch nothing, which is the case the optimism is for.
The escape analysis underneath is the same walk Escapes does and it runs with what this
module has worked out so far, which is section 34.6’s upgrade to it: an address handed to a
call is an address gone to Escapes::of, and that is most of what a C program does with the
address of a local, so a callee whose summary says it keeps nothing takes a whole class of
locals back out of the escaped set. Both directions of that are used here. A local this
function only lent out stays private, so what the callee did to it never reaches the summary,
and a parameter handed on takes the callee’s own answer for that position rather than the
blanket one.
One thing is deliberately not as precise as it could be, and it is written down in tamnd/rucc#1557 rather than done here: a parameter is a whole object, so a callee that writes one field of a structure is a callee that wrote the structure.
Structs§
- Summaries
- What is known about each function in the module.
- Summary
- What a function does to memory.
- Touch
- What a function does to the object one parameter points at.
Enums§
- Effect
- What a function does to one part of memory.
Functions§
- summarize
- Works out what every function in the module does to memory.