pub enum OptLevel {
O0,
O1,
O2,
O3,
Os,
Oz,
}Expand description
An optimisation level.
spec/16-performance.md section 16.4 gives each level a throughput budget and a code
quality budget, and the levels exist to make that tradeoff explicit rather than to be a
dial. There is no -O4, because a level nobody can state the contract for is a level
nobody can test.
Variants§
O0
-O0. Compile as fast as possible and keep every variable inspectable.
O1
-O1. The cheap wins, at roughly the cost of -O0.
O2
-O2. The full pipeline. This is the level the code quality claim is about.
O3
-O3. -O2 plus the transformations that trade size for speed.
Os
-Os. Optimise for size, at roughly -O2 compile time.
Oz
-Oz. Optimise for size, aggressively.
Implementations§
Source§impl OptLevel
impl OptLevel
Sourcepub const fn runs_optimizer(self) -> bool
pub const fn runs_optimizer(self) -> bool
Whether the middle end runs at all.
Sourcepub const fn schedules(self) -> bool
pub const fn schedules(self) -> bool
Whether the instructions of a block are put in the order the machine finishes soonest.
spec/optimizer/38-scheduling-and-layout.md section 38.6 says -O2 and above, and gcc
turns -fschedule-insns2 on at the two size levels as well, which costs nothing: a
schedule is a permutation of instructions that were all going to be written anyway, so it
is the one optimization here that cannot make a function larger.
Sourcepub const fn sibling_calls(self) -> bool
pub const fn sibling_calls(self) -> bool
Whether a call in tail position becomes a jump.
-O2 and above and the two size levels, which is where gcc turns
-foptimize-sibling-calls on. Not at -O1, where gcc leaves it off so that a backtrace
still shows every function the program went through.
Sourcepub const fn frame_pointer(self) -> bool
pub const fn frame_pointer(self) -> bool
Whether every function keeps a frame pointer when the command line did not say.
Only at -O0, which is where gcc keeps one. Code built without optimization is code
somebody is going to step through, and an asm statement written for that build may walk
the frame through %rbp itself, the way chibicc’s own test of asm returns early.