LLVM 20.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.
 
InstructionCostoperator+= (const InstructionCost &RHS)
 For all of the arithmetic operators provided here any invalid state is perpetuated and cannot be removed.
 
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.
 
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 29 of file InstructionCost.h.

Member Typedef Documentation

◆ CostType

Definition at line 31 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 34 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 69 of file InstructionCost.h.

Member Function Documentation

◆ getInvalid()

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

Definition at line 73 of file InstructionCost.h.

References setInvalid().

Referenced by llvm::ComputeSpeculationCost(), llvm::VPRegionBlock::cost(), llvm::TargetTransformInfoImplBase::getAltInstrCost(), llvm::X86TTIImpl::getAltInstrCost(), llvm::AArch64TTIImpl::getArithmeticInstrCost(), llvm::AArch64TTIImpl::getArithmeticReductionCost(), llvm::AArch64TTIImpl::getArithmeticReductionCostSVE(), llvm::BasicTTIImplBase< T >::getCastInstrCost(), llvm::BasicTTIImplBase< T >::getCmpSelInstrCost(), llvm::LoopVectorizationCostModel::getDivRemSpeculationCost(), llvm::AArch64TTIImpl::getGatherScatterOpCost(), getHistogramCost(), llvm::LoopVectorizationCostModel::getInstructionCost(), llvm::BasicTTIImplBase< T >::getInterleavedMemoryOpCost(), llvm::AArch64TTIImpl::getInterleavedMemoryOpCost(), llvm::RISCVTTIImpl::getInterleavedMemoryOpCost(), llvm::BasicTTIImplBase< T >::getIntrinsicInstrCost(), llvm::AArch64TTIImpl::getIntrinsicInstrCost(), llvm::TargetTransformInfoImplBase::getIntrinsicInstrCost(), llvm::RISCVTargetLowering::getLMULCost(), llvm::AArch64TTIImpl::getMaskedMemoryOpCost(), llvm::AArch64TTIImpl::getMemoryOpCost(), llvm::BasicTTIImplBase< T >::getMinMaxReductionCost(), llvm::AArch64TTIImpl::getMinMaxReductionCost(), llvm::BasicTTIImplBase< T >::getOrderedReductionCost(), llvm::BasicTTIImplBase< T >::getScalarizationOverhead(), llvm::AArch64TTIImpl::getScalarizationOverhead(), llvm::BasicTTIImplBase< T >::getShuffleCost(), llvm::AArch64TTIImpl::getSpliceCost(), llvm::TargetTransformInfoImplBase::getStridedMemoryOpCost(), llvm::BasicTTIImplBase< T >::getTreeReductionCost(), llvm::BasicTTIImplBase< T >::getTypeBasedIntrinsicInstrCost(), llvm::BasicTTIImplBase< T >::getTypeLegalizationCost(), map(), llvm::CostModelPrinterPass::run(), llvm::LoopVectorizationCostModel::setCostBasedWideningDecision(), llvm::LoopVectorizationCostModel::setVectorizedCallDecision(), and llvm::PPCTTIImpl::vectorCostAdjustmentFactor().

◆ getMax()

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

◆ getMin()

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

Definition at line 72 of file InstructionCost.h.

◆ getState()

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

Definition at line 82 of file InstructionCost.h.

◆ getValue()

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

◆ isValid()

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

◆ map()

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

Definition at line 245 of file InstructionCost.h.

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

◆ operator!=() [1/2]

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

Definition at line 214 of file InstructionCost.h.

References RHS.

◆ operator!=() [2/2]

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

Definition at line 207 of file InstructionCost.h.

References RHS.

◆ operator*=() [1/2]

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

Definition at line 150 of file InstructionCost.h.

References RHS.

◆ operator*=() [2/2]

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

Definition at line 134 of file InstructionCost.h.

References llvm::MulOverflow(), and RHS.

◆ operator++() [1/2]

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

Definition at line 168 of file InstructionCost.h.

◆ operator++() [2/2]

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

Definition at line 173 of file InstructionCost.h.

◆ operator+=() [1/2]

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

Definition at line 111 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 99 of file InstructionCost.h.

References llvm::AddOverflow(), and RHS.

◆ operator--() [1/2]

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

Definition at line 179 of file InstructionCost.h.

◆ operator--() [2/2]

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

Definition at line 184 of file InstructionCost.h.

◆ operator-=() [1/2]

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

Definition at line 128 of file InstructionCost.h.

References RHS.

◆ operator-=() [2/2]

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

Definition at line 117 of file InstructionCost.h.

References RHS, and llvm::SubOverflow().

◆ operator/=() [1/2]

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

Definition at line 162 of file InstructionCost.h.

References RHS.

◆ operator/=() [2/2]

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

Definition at line 156 of file InstructionCost.h.

References RHS.

◆ operator<() [1/2]

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

Definition at line 222 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 195 of file InstructionCost.h.

References RHS.

◆ operator<=() [1/2]

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

Definition at line 232 of file InstructionCost.h.

References RHS.

◆ operator<=() [2/2]

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

Definition at line 218 of file InstructionCost.h.

References RHS.

◆ operator==() [1/2]

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

Definition at line 209 of file InstructionCost.h.

References RHS.

◆ operator==() [2/2]

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

Definition at line 203 of file InstructionCost.h.

References RHS.

◆ operator>() [1/2]

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

Definition at line 227 of file InstructionCost.h.

References RHS.

◆ operator>() [2/2]

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

Definition at line 216 of file InstructionCost.h.

References RHS.

◆ operator>=() [1/2]

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

Definition at line 237 of file InstructionCost.h.

References RHS.

◆ operator>=() [2/2]

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

Definition at line 220 of file InstructionCost.h.

References RHS.

◆ print()

void InstructionCost::print ( raw_ostream OS) const

Definition at line 19 of file InstructionCost.cpp.

References isValid(), and OS.

◆ setInvalid()

void llvm::InstructionCost::setInvalid ( )
inline

Definition at line 81 of file InstructionCost.h.

References Invalid.

Referenced by getInvalid().

◆ setValid()

void llvm::InstructionCost::setValid ( )
inline

Definition at line 80 of file InstructionCost.h.

References Valid.


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