LLVM  16.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::InstructionCost Class Reference

#include "llvm/Support/InstructionCost.h"

Public Types

enum  CostState { Valid, Invalid }
 CostState describes the state of a cost. More...
 
using CostType = int64_t
 

Public Member Functions

 InstructionCost ()=default
 
 InstructionCost (CostState)=delete
 
 InstructionCost (CostType Val)
 
bool isValid () const
 
void setValid ()
 
void setInvalid ()
 
CostState getState () const
 
std::optional< CostTypegetValue () const
 This function is intended to be used as sparingly as possible, since the class provides the full range of operator support required for arithmetic and comparisons. More...
 
InstructionCostoperator+= (const InstructionCost &RHS)
 For all of the arithmetic operators provided here any invalid state is perpetuated and cannot be removed. More...
 
InstructionCostoperator+= (const CostType RHS)
 
InstructionCostoperator-= (const InstructionCost &RHS)
 
InstructionCostoperator-= (const CostType RHS)
 
InstructionCostoperator*= (const InstructionCost &RHS)
 
InstructionCostoperator*= (const CostType RHS)
 
InstructionCostoperator/= (const InstructionCost &RHS)
 
InstructionCostoperator/= (const CostType RHS)
 
InstructionCostoperator++ ()
 
InstructionCost operator++ (int)
 
InstructionCostoperator-- ()
 
InstructionCost operator-- (int)
 
bool operator< (const InstructionCost &RHS) const
 For the comparison operators we have chosen to use lexicographical ordering where valid costs are always considered to be less than invalid costs. More...
 
bool operator== (const InstructionCost &RHS) const
 
bool operator!= (const InstructionCost &RHS) const
 
bool operator== (const CostType RHS) const
 
bool operator!= (const CostType RHS) const
 
bool operator> (const InstructionCost &RHS) const
 
bool operator<= (const InstructionCost &RHS) const
 
bool operator>= (const InstructionCost &RHS) const
 
bool operator< (const CostType RHS) const
 
bool operator> (const CostType RHS) const
 
bool operator<= (const CostType RHS) const
 
bool operator>= (const CostType RHS) const
 
void print (raw_ostream &OS) const
 
template<class Function >
auto map (const Function &F) const -> InstructionCost
 

Static Public Member Functions

static InstructionCost getMax ()
 
static InstructionCost getMin ()
 
static InstructionCost getInvalid (CostType Val=0)
 

Detailed Description

Definition at line 30 of file InstructionCost.h.

Member Typedef Documentation

◆ CostType

Definition at line 32 of file InstructionCost.h.

Member Enumeration Documentation

◆ CostState

CostState describes the state of a cost.

Enumerator
Valid 
Invalid 

< The cost value represents a valid cost, even when the cost-value is large.

< Invalid indicates there is no way to represent the cost as a numeric value. This state exists to represent a possible issue, e.g. if the cost-model knows the operation cannot be expanded into a valid code-sequence by the code-generator. While some passes may assert that the calculated cost must be valid, it is up to individual passes how to interpret an Invalid cost. For example, a transformation pass could choose not to perform a transformation if the resulting cost would end up Invalid. Because some passes may assert a cost is Valid, it is not recommended to use Invalid costs to model 'Unknown'. Note that Invalid is semantically different from a (very) high, but valid cost, which intentionally indicates no issue, but rather a strong preference not to select a certain operation.

Definition at line 35 of file InstructionCost.h.

Constructor & Destructor Documentation

◆ InstructionCost() [1/3]

llvm::InstructionCost::InstructionCost ( )
default

◆ InstructionCost() [2/3]

llvm::InstructionCost::InstructionCost ( CostState  )
delete

◆ InstructionCost() [3/3]

llvm::InstructionCost::InstructionCost ( CostType  Val)
inline

Definition at line 70 of file InstructionCost.h.

Member Function Documentation

◆ getInvalid()

static InstructionCost llvm::InstructionCost::getInvalid ( CostType  Val = 0)
inlinestatic

◆ getMax()

static InstructionCost llvm::InstructionCost::getMax ( )
inlinestatic

◆ getMin()

static InstructionCost llvm::InstructionCost::getMin ( )
inlinestatic

Definition at line 73 of file InstructionCost.h.

◆ getState()

CostState llvm::InstructionCost::getState ( ) const
inline

Definition at line 83 of file InstructionCost.h.

◆ getValue()

std::optional<CostType> llvm::InstructionCost::getValue ( ) const
inline

This function is intended to be used as sparingly as possible, since the class provides the full range of operator support required for arithmetic and comparisons.

Definition at line 88 of file InstructionCost.h.

References isValid().

Referenced by analyzeLoopUnrollCost(), areRuntimeChecksProfitable(), computeHeuristicUnrollFactor(), llvm::SystemZTTIImpl::getUnrollingPreferences(), llvm::LoopVectorizationCostModel::selectInterleaveCount(), tryToUnrollAndJamLoop(), and tryToUnrollLoop().

◆ isValid()

bool llvm::InstructionCost::isValid ( ) const
inline

◆ map()

template<class Function >
auto llvm::InstructionCost::map ( const Function F) const -> InstructionCost
inline

Definition at line 246 of file InstructionCost.h.

References F, getInvalid(), and isValid().

◆ operator!=() [1/2]

bool llvm::InstructionCost::operator!= ( const CostType  RHS) const
inline

Definition at line 215 of file InstructionCost.h.

References RHS.

◆ operator!=() [2/2]

bool llvm::InstructionCost::operator!= ( const InstructionCost RHS) const
inline

Definition at line 208 of file InstructionCost.h.

References RHS.

◆ operator*=() [1/2]

InstructionCost& llvm::InstructionCost::operator*= ( const CostType  RHS)
inline

Definition at line 151 of file InstructionCost.h.

References RHS.

◆ operator*=() [2/2]

InstructionCost& llvm::InstructionCost::operator*= ( const InstructionCost RHS)
inline

Definition at line 135 of file InstructionCost.h.

References llvm::MulOverflow(), and RHS.

◆ operator++() [1/2]

InstructionCost& llvm::InstructionCost::operator++ ( )
inline

Definition at line 169 of file InstructionCost.h.

◆ operator++() [2/2]

InstructionCost llvm::InstructionCost::operator++ ( int  )
inline

Definition at line 174 of file InstructionCost.h.

◆ operator+=() [1/2]

InstructionCost& llvm::InstructionCost::operator+= ( const CostType  RHS)
inline

Definition at line 112 of file InstructionCost.h.

References RHS.

◆ operator+=() [2/2]

InstructionCost& llvm::InstructionCost::operator+= ( const InstructionCost RHS)
inline

For all of the arithmetic operators provided here any invalid state is perpetuated and cannot be removed.

Once a cost becomes invalid it stays invalid, and it also inherits any invalid state from the RHS. Arithmetic work on the actual values is implemented with saturation, to avoid overflow when using more extreme cost values.

Definition at line 100 of file InstructionCost.h.

References llvm::AddOverflow(), and RHS.

◆ operator--() [1/2]

InstructionCost& llvm::InstructionCost::operator-- ( )
inline

Definition at line 180 of file InstructionCost.h.

◆ operator--() [2/2]

InstructionCost llvm::InstructionCost::operator-- ( int  )
inline

Definition at line 185 of file InstructionCost.h.

◆ operator-=() [1/2]

InstructionCost& llvm::InstructionCost::operator-= ( const CostType  RHS)
inline

Definition at line 129 of file InstructionCost.h.

References RHS.

◆ operator-=() [2/2]

InstructionCost& llvm::InstructionCost::operator-= ( const InstructionCost RHS)
inline

Definition at line 118 of file InstructionCost.h.

References RHS, and llvm::SubOverflow().

◆ operator/=() [1/2]

InstructionCost& llvm::InstructionCost::operator/= ( const CostType  RHS)
inline

Definition at line 163 of file InstructionCost.h.

References RHS.

◆ operator/=() [2/2]

InstructionCost& llvm::InstructionCost::operator/= ( const InstructionCost RHS)
inline

Definition at line 157 of file InstructionCost.h.

References RHS.

◆ operator<() [1/2]

bool llvm::InstructionCost::operator< ( const CostType  RHS) const
inline

Definition at line 223 of file InstructionCost.h.

References RHS.

◆ operator<() [2/2]

bool llvm::InstructionCost::operator< ( const InstructionCost RHS) const
inline

For the comparison operators we have chosen to use lexicographical ordering where valid costs are always considered to be less than invalid costs.

This avoids having to add asserts to the comparison operators that the states are valid and users can test for validity of the cost explicitly.

Definition at line 196 of file InstructionCost.h.

References RHS.

◆ operator<=() [1/2]

bool llvm::InstructionCost::operator<= ( const CostType  RHS) const
inline

Definition at line 233 of file InstructionCost.h.

References RHS.

◆ operator<=() [2/2]

bool llvm::InstructionCost::operator<= ( const InstructionCost RHS) const
inline

Definition at line 219 of file InstructionCost.h.

References RHS.

◆ operator==() [1/2]

bool llvm::InstructionCost::operator== ( const CostType  RHS) const
inline

Definition at line 210 of file InstructionCost.h.

References RHS.

◆ operator==() [2/2]

bool llvm::InstructionCost::operator== ( const InstructionCost RHS) const
inline

Definition at line 204 of file InstructionCost.h.

References RHS.

◆ operator>() [1/2]

bool llvm::InstructionCost::operator> ( const CostType  RHS) const
inline

Definition at line 228 of file InstructionCost.h.

References RHS.

◆ operator>() [2/2]

bool llvm::InstructionCost::operator> ( const InstructionCost RHS) const
inline

Definition at line 217 of file InstructionCost.h.

References RHS.

◆ operator>=() [1/2]

bool llvm::InstructionCost::operator>= ( const CostType  RHS) const
inline

Definition at line 238 of file InstructionCost.h.

References RHS.

◆ operator>=() [2/2]

bool llvm::InstructionCost::operator>= ( const InstructionCost RHS) const
inline

Definition at line 221 of file InstructionCost.h.

References RHS.

◆ print()

void InstructionCost::print ( raw_ostream OS) const

Definition at line 19 of file InstructionCost.cpp.

References isValid().

Referenced by llvm::operator<<().

◆ setInvalid()

void llvm::InstructionCost::setInvalid ( )
inline

Definition at line 82 of file InstructionCost.h.

References Invalid.

Referenced by getInvalid().

◆ setValid()

void llvm::InstructionCost::setValid ( )
inline

Definition at line 81 of file InstructionCost.h.

References Valid.


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