LLVM  13.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
 
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 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

◆ 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()

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 87 of file InstructionCost.h.

References isValid(), and llvm::None.

Referenced by llvm::CodeMetrics::analyzeBasicBlock(), analyzeLoopUnrollCost(), llvm::SystemZTTIImpl::getUnrollingPreferences(), map(), and llvm::LoopVectorizePass::processLoop().

◆ 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(), getValue(), and isValid().

◆ operator!=() [1/2]

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

Definition at line 214 of file InstructionCost.h.

◆ operator!=() [2/2]

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

Definition at line 207 of file InstructionCost.h.

◆ operator*=() [1/2]

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

Definition at line 150 of file InstructionCost.h.

◆ operator*=() [2/2]

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

Definition at line 134 of file InstructionCost.h.

References llvm::MulOverflow().

◆ 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.

◆ 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().

◆ 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.

◆ operator-=() [2/2]

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

Definition at line 117 of file InstructionCost.h.

References llvm::SubOverflow().

◆ operator/=() [1/2]

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

Definition at line 162 of file InstructionCost.h.

◆ operator/=() [2/2]

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

Definition at line 156 of file InstructionCost.h.

◆ operator<() [1/2]

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

Definition at line 222 of file InstructionCost.h.

◆ 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.

◆ operator<=() [1/2]

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

Definition at line 232 of file InstructionCost.h.

◆ operator<=() [2/2]

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

Definition at line 218 of file InstructionCost.h.

◆ operator==() [1/2]

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

Definition at line 209 of file InstructionCost.h.

◆ operator==() [2/2]

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

Definition at line 203 of file InstructionCost.h.

◆ operator>() [1/2]

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

Definition at line 227 of file InstructionCost.h.

◆ operator>() [2/2]

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

Definition at line 216 of file InstructionCost.h.

◆ operator>=() [1/2]

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

Definition at line 237 of file InstructionCost.h.

◆ operator>=() [2/2]

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

Definition at line 220 of file InstructionCost.h.

◆ 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 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: