Expand description
What things cost on a target, and every tuning constant the optimizer has.
This is document 40 of spec/optimizer/, made real. The crate exists because of the failure
that document opens with: a compiler where each pass has its own idea of what an operation
costs is a compiler where two passes undo each other, and neither of them is wrong. Putting the
numbers in one place does not make them right, but it makes them one thing that can be measured
and changed, instead of thirty things that have to be found first.
§What is in here
Cycles and Bytes, which are separate types so that a cost in time is never compared
against a threshold in space. Cost, which is a time and a complexity compared
lexicographically with an explicit infinity, from GCC’s comp_cost. CostTable, which a
target fills in completely or not at all. TuneFlag, which is the half of a cost model that
is a boolean rather than a number. And heuristics, which is the file every threshold in
every pass has to come from.
§Two tables, not one table and a policy
Section 40.3 reads ix86_cur_cost() at gcc/config/i386/i386.h:269 and takes the design
from it: optimizing for size is a different cost table, not a weighting applied to the same
one. -Os selects the second table and every pass then goes on asking the same questions in
the same way. It makes -Os behaviour inspectable as data, and it means no pass has to
remember to ask whether it is optimizing for size, which is the sort of thing a pass forgets
in exactly one of its five decisions.
§What is not in here
Anything derived from a function. Register pressure, block frequency and branch predictability are all things section 40.6 wants computed once per function and shared, and all three need the IR, so they belong with the analyses rather than with the target description. This crate is below the IR on purpose.
Re-exports§
pub use cost::Complexity;pub use cost::Cost;pub use cycles::Bytes;pub use cycles::Cycles;pub use table::AddrMode;pub use table::Builder;pub use table::CostTable;pub use table::Width;pub use tune::TuneFlag;pub use tune::Tuning;
Modules§
- cost
- A cost is a pair, and the second half of it is a preference the first half cannot express.
- cycles
- The two units a cost is measured in, and the reason they are two types.
- heuristics
- Every threshold any pass consults, with where it came from.
- table
- The table a target fills in, and the machinery that makes filling it in completely mandatory.
- tune
- The half of a cost model that is not a number.
- x86_64
- The two cost tables for x86-64, and what the target answers about tuning.
Enums§
- Goal
- Which of a target’s two tables is wanted.
Traits§
- Target
Costs - What a pass asks a target about costs, per section 40.12.
Functions§
- for_
arch - The costs for a target, or nothing for one nobody has written a table for.