LLVM  6.0.0svn
Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::LegalizerInfo Class Reference

#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"

Inheritance diagram for llvm::LegalizerInfo:
Inheritance graph
[legend]

Public Types

enum  LegalizeAction : std::uint8_t {
  Legal, NarrowScalar, WidenScalar, FewerElements,
  MoreElements, Lower, Libcall, Custom,
  Unsupported, NotFound
}
 
typedef std::pair< uint16_t, LegalizeActionSizeAndAction
 
typedef std::vector< SizeAndActionSizeAndActionsVec
 
using SizeChangeStrategy = std::function< SizeAndActionsVec(const SizeAndActionsVec &v)>
 

Public Member Functions

 LegalizerInfo ()
 
virtual ~LegalizerInfo ()=default
 
void computeTables ()
 Compute any ancillary tables needed to quickly decide how an operation should be handled. More...
 
void setAction (const InstrAspect &Aspect, LegalizeAction Action)
 More friendly way to set an action for common types that have an LLT representation. More...
 
void setLegalizeScalarToDifferentSizeStrategy (const unsigned Opcode, const unsigned TypeIdx, SizeChangeStrategy S)
 The setAction calls record the non-size-changing legalization actions to take on specificly-sized types. More...
 
void setLegalizeVectorElementToDifferentSizeStrategy (const unsigned Opcode, const unsigned TypeIdx, SizeChangeStrategy S)
 See also setLegalizeScalarToDifferentSizeStrategy. More...
 
std::pair< LegalizeAction, LLTgetAction (const InstrAspect &Aspect) const
 Determine what action should be taken to legalize the given generic instruction opcode, type-index and type. More...
 
std::tuple< LegalizeAction, unsigned, LLTgetAction (const MachineInstr &MI, const MachineRegisterInfo &MRI) const
 Determine what action should be taken to legalize the given generic instruction. More...
 
bool isLegal (const MachineInstr &MI, const MachineRegisterInfo &MRI) const
 
virtual bool legalizeCustom (MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder) const
 

Static Public Member Functions

static bool needsLegalizingToDifferentSize (const LegalizeAction Action)
 
static SizeAndActionsVec unsupportedForDifferentSizes (const SizeAndActionsVec &v)
 A SizeChangeStrategy for the common case where legalization for a particular operation consists of only supporting a specific set of type sizes. More...
 
static SizeAndActionsVec widenToLargerTypesAndNarrowToLargest (const SizeAndActionsVec &v)
 A SizeChangeStrategy for the common case where legalization for a particular operation consists of widening the type to a large legal type, unless there is no such type and then instead it should be narrowed to the largest legal type. More...
 
static SizeAndActionsVec widenToLargerTypesUnsupportedOtherwise (const SizeAndActionsVec &v)
 
static SizeAndActionsVec narrowToSmallerAndUnsupportedIfTooSmall (const SizeAndActionsVec &v)
 
static SizeAndActionsVec narrowToSmallerAndWidenToSmallest (const SizeAndActionsVec &v)
 
static SizeAndActionsVec moreToWiderTypesAndLessToWidest (const SizeAndActionsVec &v)
 A SizeChangeStrategy for the common case where legalization for a particular vector operation consists of having more elements in the vector, to a type that is legal. More...
 
static SizeAndActionsVec increaseToLargerTypesAndDecreaseToLargest (const SizeAndActionsVec &v, LegalizeAction IncreaseAction, LegalizeAction DecreaseAction)
 Helper function to implement many typical SizeChangeStrategy functions. More...
 
static SizeAndActionsVec decreaseToSmallerTypesAndIncreaseToSmallest (const SizeAndActionsVec &v, LegalizeAction DecreaseAction, LegalizeAction IncreaseAction)
 Helper function to implement many typical SizeChangeStrategy functions. More...
 

Detailed Description

Definition at line 54 of file LegalizerInfo.h.

Member Typedef Documentation

◆ SizeAndAction

typedef std::pair<uint16_t, LegalizeAction> llvm::LegalizerInfo::SizeAndAction

Definition at line 124 of file LegalizerInfo.h.

◆ SizeAndActionsVec

Definition at line 125 of file LegalizerInfo.h.

◆ SizeChangeStrategy

Definition at line 127 of file LegalizerInfo.h.

Member Enumeration Documentation

◆ LegalizeAction

Enumerator
Legal 

The operation is expected to be selectable directly by the target, and no transformation is necessary.

NarrowScalar 

The operation should be synthesized from multiple instructions acting on a narrower scalar base-type.

For example a 64-bit add might be implemented in terms of 32-bit add-with-carry.

WidenScalar 

The operation should be implemented in terms of a wider scalar base-type.

For example a <2 x s8> add could be implemented as a <2 x s32> add (ignoring the high bits).

FewerElements 

The (vector) operation should be implemented by splitting it into sub-vectors where the operation is legal.

For example a <8 x s64> add might be implemented as 4 separate <2 x s64> adds.

MoreElements 

The (vector) operation should be implemented by widening the input vector and ignoring the lanes added by doing so.

For example <2 x i8> is rarely legal, but you might perform an <8 x i8> and then only look at the first two results.

Lower 

The operation itself must be expressed in terms of simpler actions on this target.

E.g. a SREM replaced by an SDIV and subtraction.

Libcall 

The operation should be implemented as a call to some kind of runtime support library.

For example this usually happens on machines that don't support floating-point operations natively.

Custom 

The target wants to do something special with this combination of operand and type.

A callback will be issued when it is needed.

Unsupported 

This operation is completely unsupported on the target.

A programming error has occurred.

NotFound 

Sentinel value for when no action was found in the specified table.

Definition at line 56 of file LegalizerInfo.h.

Constructor & Destructor Documentation

◆ LegalizerInfo()

LegalizerInfo::LegalizerInfo ( )

◆ ~LegalizerInfo()

virtual llvm::LegalizerInfo::~LegalizerInfo ( )
virtualdefault

Member Function Documentation

◆ computeTables()

void LegalizerInfo::computeTables ( )

Compute any ancillary tables needed to quickly decide how an operation should be handled.

This must be called after all "set*Action"methods but before any query is made or incorrect results may be returned.

Definition at line 69 of file LegalizerInfo.cpp.

References assert(), llvm::LLT::getAddressSpace(), llvm::LLT::getElementType(), llvm::LLT::getSizeInBits(), llvm::LLT::isPointer(), llvm::LLT::isVector(), Legal, moreToWiderTypesAndLessToWidest(), llvm::parallel::sort(), and unsupportedForDifferentSizes().

Referenced by llvm::AArch64LegalizerInfo::AArch64LegalizerInfo(), llvm::AMDGPULegalizerInfo::AMDGPULegalizerInfo(), llvm::ARMLegalizerInfo::ARMLegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ decreaseToSmallerTypesAndIncreaseToSmallest()

LegalizerInfo::SizeAndActionsVec LegalizerInfo::decreaseToSmallerTypesAndIncreaseToSmallest ( const SizeAndActionsVec v,
LegalizeAction  DecreaseAction,
LegalizeAction  IncreaseAction 
)
static

◆ getAction() [1/2]

std::pair< LegalizerInfo::LegalizeAction, LLT > LegalizerInfo::getAction ( const InstrAspect Aspect) const

Determine what action should be taken to legalize the given generic instruction opcode, type-index and type.

Requires computeTables to have been called.

Returns
a pair consisting of the kind of legalization that should be performed and the destination type.

Definition at line 166 of file LegalizerInfo.cpp.

References assert(), llvm::LLT::isPointer(), llvm::LLT::isScalar(), llvm::LLT::isVector(), and llvm::InstrAspect::Type.

Referenced by getAction(), isLegal(), llvm::LegalizerHelper::legalizeInstrStep(), and llvm::LegalizationArtifactCombiner::tryCombineInstruction().

◆ getAction() [2/2]

std::tuple< LegalizerInfo::LegalizeAction, unsigned, LLT > LegalizerInfo::getAction ( const MachineInstr MI,
const MachineRegisterInfo MRI 
) const

Determine what action should be taken to legalize the given generic instruction.

Returns
a tuple consisting of the LegalizeAction that should be performed, the type-index it should be performed on and the destination type.

Definition at line 190 of file LegalizerInfo.cpp.

References getAction(), llvm::MachineInstr::getDesc(), llvm::MCOperandInfo::getGenericTypeIndex(), llvm::MCInstrDesc::getNumOperands(), llvm::MachineInstr::getOpcode(), getTypeFromTypeIdx(), Legal, llvm::MCInstrDesc::OpInfo, and llvm::SmallBitVector::set().

◆ increaseToLargerTypesAndDecreaseToLargest()

LegalizerInfo::SizeAndActionsVec LegalizerInfo::increaseToLargerTypesAndDecreaseToLargest ( const SizeAndActionsVec v,
LegalizeAction  IncreaseAction,
LegalizeAction  DecreaseAction 
)
static

Helper function to implement many typical SizeChangeStrategy functions.

Definition at line 226 of file LegalizerInfo.cpp.

◆ isLegal()

bool LegalizerInfo::isLegal ( const MachineInstr MI,
const MachineRegisterInfo MRI 
) const

Definition at line 215 of file LegalizerInfo.cpp.

References getAction(), and Legal.

◆ legalizeCustom()

bool LegalizerInfo::legalizeCustom ( MachineInstr MI,
MachineRegisterInfo MRI,
MachineIRBuilder MIRBuilder 
) const
virtual

◆ moreToWiderTypesAndLessToWidest()

static SizeAndActionsVec llvm::LegalizerInfo::moreToWiderTypesAndLessToWidest ( const SizeAndActionsVec v)
inlinestatic

A SizeChangeStrategy for the common case where legalization for a particular vector operation consists of having more elements in the vector, to a type that is legal.

Unless there is no such type and then instead it should be legalized towards the widest vector that's still legal. E.g. setAction({G_ADD, LLT::vector(8, 8)}, Legal); setAction({G_ADD, LLT::vector(16, 8)}, Legal); setAction({G_ADD, LLT::vector(2, 32)}, Legal); setAction({G_ADD, LLT::vector(4, 32)}, Legal); setLegalizeVectorElementToDifferentSizeStrategy( G_ADD, 0, moreToWiderTypesAndLessToWidest); will result in the following getAction results:

  • getAction({G_ADD, LLT::vector(8,8)}) returns (Legal, vector(8,8)).
  • getAction({G_ADD, LLT::vector(9,8)}) returns (MoreElements, vector(16,8)).
  • getAction({G_ADD, LLT::vector(8,32)}) returns (FewerElements, vector(4,32)).

Definition at line 246 of file LegalizerInfo.h.

References assert(), llvm::sys::path::end(), llvm::find(), first, MI, MRI, llvm::InstrAspect::Opcode, llvm::SmallVectorImpl< T >::resize(), second, llvm::SmallVectorTemplateCommon< T, typename >::size(), and llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Size.

Referenced by computeTables().

◆ narrowToSmallerAndUnsupportedIfTooSmall()

static SizeAndActionsVec llvm::LegalizerInfo::narrowToSmallerAndUnsupportedIfTooSmall ( const SizeAndActionsVec v)
inlinestatic

Definition at line 213 of file LegalizerInfo.h.

Referenced by LegalizerInfo().

◆ narrowToSmallerAndWidenToSmallest()

static SizeAndActionsVec llvm::LegalizerInfo::narrowToSmallerAndWidenToSmallest ( const SizeAndActionsVec v)
inlinestatic

Definition at line 219 of file LegalizerInfo.h.

References assert().

Referenced by llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ needsLegalizingToDifferentSize()

static bool llvm::LegalizerInfo::needsLegalizingToDifferentSize ( const LegalizeAction  Action)
inlinestatic

Definition at line 111 of file LegalizerInfo.h.

Referenced by decreaseToSmallerTypesAndIncreaseToSmallest().

◆ setAction()

void llvm::LegalizerInfo::setAction ( const InstrAspect Aspect,
LegalizeAction  Action 
)
inline

More friendly way to set an action for common types that have an LLT representation.

The LegalizeAction must be one for which NeedsLegalizingToDifferentSize returns false.

Definition at line 133 of file LegalizerInfo.h.

References assert(), llvm::InstrAspect::Idx, llvm::InstrAspect::Opcode, and llvm::InstrAspect::Type.

Referenced by llvm::AArch64LegalizerInfo::AArch64LegalizerInfo(), llvm::AMDGPULegalizerInfo::AMDGPULegalizerInfo(), llvm::ARMLegalizerInfo::ARMLegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ setLegalizeScalarToDifferentSizeStrategy()

void llvm::LegalizerInfo::setLegalizeScalarToDifferentSizeStrategy ( const unsigned  Opcode,
const unsigned  TypeIdx,
SizeChangeStrategy  S 
)
inline

The setAction calls record the non-size-changing legalization actions to take on specificly-sized types.

The SizeChangeStrategy defines what to do when the size of the type needs to be changed to reach a legally sized type (i.e., one that was defined through a setAction call). e.g. setAction ({G_ADD, 0, LLT::scalar(32)}, Legal); setLegalizeScalarToDifferentSizeStrategy( G_ADD, 0, widenToLargerTypesAndNarrowToLargest); will end up defining getAction({G_ADD, 0, T}) to return the following actions for different scalar types T: LLT::scalar(1)..LLT::scalar(31): {WidenScalar, 0, LLT::scalar(32)} LLT::scalar(32): {Legal, 0, LLT::scalar(32)} LLT::scalar(33)..: {NarrowScalar, 0, LLT::scalar(32)}

If no SizeChangeAction gets defined, through this function, the default is unsupportedForDifferentSizes.

Definition at line 158 of file LegalizerInfo.h.

Referenced by llvm::AArch64LegalizerInfo::AArch64LegalizerInfo(), llvm::ARMLegalizerInfo::ARMLegalizerInfo(), LegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ setLegalizeVectorElementToDifferentSizeStrategy()

void llvm::LegalizerInfo::setLegalizeVectorElementToDifferentSizeStrategy ( const unsigned  Opcode,
const unsigned  TypeIdx,
SizeChangeStrategy  S 
)
inline

See also setLegalizeScalarToDifferentSizeStrategy.

This function allows to set the SizeChangeStrategy for vector elements.

Definition at line 169 of file LegalizerInfo.h.

◆ unsupportedForDifferentSizes()

static SizeAndActionsVec llvm::LegalizerInfo::unsupportedForDifferentSizes ( const SizeAndActionsVec v)
inlinestatic

A SizeChangeStrategy for the common case where legalization for a particular operation consists of only supporting a specific set of type sizes.

E.g. setAction ({G_DIV, 0, LLT::scalar(32)}, Legal); setAction ({G_DIV, 0, LLT::scalar(64)}, Legal); setLegalizeScalarToDifferentSizeStrategy( G_DIV, 0, unsupportedForDifferentSizes); will result in getAction({G_DIV, 0, T}) to return Legal for s32 and s64, and Unsupported for all other scalar types T.

Definition at line 188 of file LegalizerInfo.h.

Referenced by computeTables().

◆ widenToLargerTypesAndNarrowToLargest()

static SizeAndActionsVec llvm::LegalizerInfo::widenToLargerTypesAndNarrowToLargest ( const SizeAndActionsVec v)
inlinestatic

A SizeChangeStrategy for the common case where legalization for a particular operation consists of widening the type to a large legal type, unless there is no such type and then instead it should be narrowed to the largest legal type.

Definition at line 198 of file LegalizerInfo.h.

References assert().

Referenced by LegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ widenToLargerTypesUnsupportedOtherwise()

static SizeAndActionsVec llvm::LegalizerInfo::widenToLargerTypesUnsupportedOtherwise ( const SizeAndActionsVec v)
inlinestatic

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