LLVM 20.0.0git
Public Member Functions | Static Public Attributes | List of all members
llvm::OptimizationLevel Class Referencefinal

#include "llvm/Passes/OptimizationLevel.h"

Public Member Functions

 OptimizationLevel ()=default
 
bool isOptimizingForSpeed () const
 
bool isOptimizingForSize () const
 
bool operator== (const OptimizationLevel &Other) const
 
bool operator!= (const OptimizationLevel &Other) const
 
unsigned getSpeedupLevel () const
 
unsigned getSizeLevel () const
 

Static Public Attributes

static const OptimizationLevel O0
 Disable as many optimizations as possible.
 
static const OptimizationLevel O1
 Optimize quickly without destroying debuggability.
 
static const OptimizationLevel O2
 Optimize for fast execution as much as possible without triggering significant incremental compile time or code size growth.
 
static const OptimizationLevel O3
 Optimize for fast execution as much as possible.
 
static const OptimizationLevel Os
 Similar to O2 but tries to optimize for small code size instead of fast execution without triggering significant incremental execution time slowdowns.
 
static const OptimizationLevel Oz
 A very specialized mode that will optimize for code size at any and all costs.
 

Detailed Description

Definition at line 22 of file OptimizationLevel.h.

Constructor & Destructor Documentation

◆ OptimizationLevel()

llvm::OptimizationLevel::OptimizationLevel ( )
default

Member Function Documentation

◆ getSizeLevel()

unsigned llvm::OptimizationLevel::getSizeLevel ( ) const
inline

Definition at line 123 of file OptimizationLevel.h.

◆ getSpeedupLevel()

unsigned llvm::OptimizationLevel::getSpeedupLevel ( ) const
inline

◆ isOptimizingForSize()

bool llvm::OptimizationLevel::isOptimizingForSize ( ) const
inline

Definition at line 112 of file OptimizationLevel.h.

◆ isOptimizingForSpeed()

bool llvm::OptimizationLevel::isOptimizingForSpeed ( ) const
inline

Definition at line 110 of file OptimizationLevel.h.

◆ operator!=()

bool llvm::OptimizationLevel::operator!= ( const OptimizationLevel Other) const
inline

Definition at line 117 of file OptimizationLevel.h.

References llvm::Other.

◆ operator==()

bool llvm::OptimizationLevel::operator== ( const OptimizationLevel Other) const
inline

Definition at line 114 of file OptimizationLevel.h.

References llvm::Other.

Member Data Documentation

◆ O0

const OptimizationLevel OptimizationLevel::O0
static

◆ O1

const OptimizationLevel OptimizationLevel::O1
static
Initial value:
= {
1,
0}

Optimize quickly without destroying debuggability.

This level is tuned to produce a result from the optimizer as quickly as possible and to avoid destroying debuggability. This tends to result in a very good development mode where the compiled code will be immediately executed as part of testing. As a consequence, where possible, we would like to produce efficient-to-execute code, but not if it significantly slows down compilation or would prevent even basic debugging of the resulting binary.

As an example, complex loop transformations such as versioning, vectorization, or fusion don't make sense here due to the degree to which the executed code differs from the source code, and the compile time cost.

Definition at line 57 of file OptimizationLevel.h.

Referenced by llvm::PassBuilder::buildLTODefaultPipeline(), parseOptLevel(), llvm::AMDGPUTargetMachine::registerPassBuilderCallbacks(), and runNewPMPasses().

◆ O2

const OptimizationLevel OptimizationLevel::O2
static
Initial value:
= {
2,
0}

Optimize for fast execution as much as possible without triggering significant incremental compile time or code size growth.

The key idea is that optimizations at this level should "pay for themselves". So if an optimization increases compile time by 5% or increases code size by 5% for a particular benchmark, that benchmark should also be one which sees a 5% runtime improvement. If the compile time or code size penalties happen on average across a diverse range of LLVM users' benchmarks, then the improvements should as well.

And no matter what, the compile time needs to not grow superlinearly with the size of input to LLVM so that users can control the runtime of the optimizer in this mode.

This is expected to be a good default optimization level for the vast majority of users.

Definition at line 74 of file OptimizationLevel.h.

Referenced by llvm::PassBuilder::buildInlinerPipeline(), parseOptLevel(), and runNewPMPasses().

◆ O3

const OptimizationLevel OptimizationLevel::O3
static
Initial value:
= {
3,
0}

Optimize for fast execution as much as possible.

This mode is significantly more aggressive in trading off compile time and code size to get execution time improvements. The core idea is that this mode should include any optimization that helps execution time on balance across a diverse collection of benchmarks, even if it increases code size or compile time for some benchmarks without corresponding improvements to execution time.

Despite being willing to trade more compile time off to get improved execution time, this mode still tries to avoid superlinear growth in order to make even significantly slower compile times at least scale reasonably. This does not preclude very substantial constant factor costs though.

Definition at line 89 of file OptimizationLevel.h.

Referenced by llvm::PassBuilder::buildFunctionSimplificationPipeline(), llvm::PassBuilder::buildInlinerPipeline(), llvm::PassBuilder::buildModuleOptimizationPipeline(), llvm::PassBuilder::buildModuleSimplificationPipeline(), parseOptLevel(), and runNewPMPasses().

◆ Os

const OptimizationLevel OptimizationLevel::Os
static
Initial value:
= {
2,
1}

Similar to O2 but tries to optimize for small code size instead of fast execution without triggering significant incremental execution time slowdowns.

The logic here is exactly the same as O2, but with code size and execution time metrics swapped.

A consequence of the different core goal is that this should in general produce substantially smaller executables that still run in a reasonable amount of time.

Definition at line 100 of file OptimizationLevel.h.

Referenced by llvm::PassBuilder::buildLTODefaultPipeline(), llvm::PassBuilder::buildModuleSimplificationPipeline(), and parseOptLevel().

◆ Oz

const OptimizationLevel OptimizationLevel::Oz
static
Initial value:
= {
2,
2}

A very specialized mode that will optimize for code size at any and all costs.

This is useful primarily when there are absolute size limitations and any effort taken to reduce the size is worth it regardless of the execution time impact. You should expect this level to produce rather slow, but very small, code.

Definition at line 108 of file OptimizationLevel.h.

Referenced by llvm::PassBuilder::buildFunctionSimplificationPipeline(), llvm::PassBuilder::buildLTODefaultPipeline(), llvm::PassBuilder::buildModuleOptimizationPipeline(), llvm::PassBuilder::buildModuleSimplificationPipeline(), and parseOptLevel().


The documentation for this class was generated from the following files: