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 }
 These states can currently be used to indicate whether a cost is valid or invalid. More...
 
using CostType = int
 

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 getInvalid (CostType Val=0)
 

Detailed Description

Definition at line 26 of file InstructionCost.h.

Member Typedef Documentation

◆ CostType

Definition at line 28 of file InstructionCost.h.

Member Enumeration Documentation

◆ CostState

These states can currently be used to indicate whether a cost is valid or invalid.

Examples of an invalid cost might be where the cost is prohibitively expensive and the user wants to prevent certain optimizations being performed. Or perhaps the cost is simply unknown because the operation makes no sense in certain circumstances. These states can be expanded in future to support other cases if necessary.

Enumerator
Valid 
Invalid 

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

Member Function Documentation

◆ getInvalid()

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

◆ getState()

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

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

References isValid(), and llvm::None.

Referenced by llvm::CodeMetrics::analyzeBasicBlock(), analyzeLoopUnrollCost(), llvm::ARMTTIImpl::getCmpSelInstrCost(), map(), and llvm::LoopVectorizationCostModel::selectVectorizationFactor().

◆ isValid()

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

◆ map()

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

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

◆ operator!=() [2/2]

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

Definition at line 167 of file InstructionCost.h.

◆ operator*=() [1/2]

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

Definition at line 110 of file InstructionCost.h.

◆ operator*=() [2/2]

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

Definition at line 104 of file InstructionCost.h.

◆ operator++() [1/2]

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

Definition at line 128 of file InstructionCost.h.

◆ operator++() [2/2]

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

Definition at line 133 of file InstructionCost.h.

◆ operator+=() [1/2]

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

Definition at line 86 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. Regardless of the state, arithmetic and comparisons work on the actual values in the same way as they would on a basic type, such as integer.

Definition at line 80 of file InstructionCost.h.

◆ operator--() [1/2]

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

Definition at line 139 of file InstructionCost.h.

◆ operator--() [2/2]

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

Definition at line 144 of file InstructionCost.h.

◆ operator-=() [1/2]

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

Definition at line 98 of file InstructionCost.h.

◆ operator-=() [2/2]

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

Definition at line 92 of file InstructionCost.h.

◆ operator/=() [1/2]

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

Definition at line 122 of file InstructionCost.h.

◆ operator/=() [2/2]

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

Definition at line 116 of file InstructionCost.h.

◆ operator<() [1/2]

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

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

◆ operator<=() [1/2]

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

Definition at line 192 of file InstructionCost.h.

◆ operator<=() [2/2]

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

Definition at line 178 of file InstructionCost.h.

◆ operator==() [1/2]

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

Definition at line 169 of file InstructionCost.h.

◆ operator==() [2/2]

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

Definition at line 163 of file InstructionCost.h.

◆ operator>() [1/2]

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

Definition at line 187 of file InstructionCost.h.

◆ operator>() [2/2]

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

Definition at line 176 of file InstructionCost.h.

◆ operator>=() [1/2]

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

Definition at line 197 of file InstructionCost.h.

◆ operator>=() [2/2]

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

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

References Invalid.

Referenced by getInvalid().

◆ setValid()

void llvm::InstructionCost::setValid ( )
inline

Definition at line 61 of file InstructionCost.h.

References Valid.


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