LLVM  8.0.1
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

using SizeAndAction = std::pair< uint16_t, LegalizeAction >
 
using SizeAndActionsVec = std::vector< SizeAndAction >
 
using SizeChangeStrategy = std::function< SizeAndActionsVec(const SizeAndActionsVec &v)>
 

Public Member Functions

 LegalizerInfo ()
 
virtual ~LegalizerInfo ()=default
 
unsigned getOpcodeIdxForOpcode (unsigned Opcode) const
 
unsigned getActionDefinitionsIdx (unsigned Opcode) const
 
void computeTables ()
 Compute any ancillary tables needed to quickly decide how an operation should be handled. More...
 
void verify (const MCInstrInfo &MII) const
 Perform simple self-diagnostic and assert if there is anything obviously wrong with the actions set up. 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...
 
const LegalizeRuleSetgetActionDefinitions (unsigned Opcode) const
 Get the action definitions for the given opcode. More...
 
LegalizeRuleSetgetActionDefinitionsBuilder (unsigned Opcode)
 Get the action definition builder for the given opcode. More...
 
LegalizeRuleSetgetActionDefinitionsBuilder (std::initializer_list< unsigned > Opcodes)
 Get the action definition builder for the given set of opcodes. More...
 
void aliasActionDefinitions (unsigned OpcodeTo, unsigned OpcodeFrom)
 
LegalizeActionStep getAction (const LegalityQuery &Query) const
 Determine what action should be taken to legalize the described instruction. More...
 
LegalizeActionStep getAction (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, GISelChangeObserver &Observer) 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 749 of file LegalizerInfo.h.

Member Typedef Documentation

◆ SizeAndAction

using llvm::LegalizerInfo::SizeAndAction = std::pair<uint16_t, LegalizeAction>

Definition at line 780 of file LegalizerInfo.h.

◆ SizeAndActionsVec

Definition at line 781 of file LegalizerInfo.h.

◆ SizeChangeStrategy

Definition at line 783 of file LegalizerInfo.h.

Constructor & Destructor Documentation

◆ LegalizerInfo()

LegalizerInfo::LegalizerInfo ( )

◆ ~LegalizerInfo()

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

Member Function Documentation

◆ aliasActionDefinitions()

void LegalizerInfo::aliasActionDefinitions ( unsigned  OpcodeTo,
unsigned  OpcodeFrom 
)

◆ 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 145 of file LegalizerInfo.cpp.

References assert(), llvm::LLT::getAddressSpace(), llvm::LLT::getElementType(), llvm::LLT::getSizeInBits(), llvm::LLT::isPointer(), llvm::LLT::isScalar(), llvm::LLT::isVector(), llvm::LegalizeActions::Legal, moreToWiderTypesAndLessToWidest(), llvm::size(), llvm::sort(), llvm::InstrAspect::Type, and unsupportedForDifferentSizes().

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

◆ decreaseToSmallerTypesAndIncreaseToSmallest()

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

◆ getAction() [1/2]

LegalizeActionStep LegalizerInfo::getAction ( const LegalityQuery Query) const

Determine what action should be taken to legalize the described instruction.

Requires computeTables to have been called.

Returns
a description of the next legalization step to perform.

Definition at line 322 of file LegalizerInfo.cpp.

References llvm::LegalizeActionStep::Action, llvm::LegalizeRuleSet::apply(), llvm::dbgs(), getActionDefinitions(), llvm::LegalizeActions::Legal, LLVM_DEBUG, llvm::LegalityQuery::Opcode, llvm::LegalityQuery::Types, and llvm::LegalizeActions::UseLegacyRules.

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

◆ getAction() [2/2]

LegalizeActionStep LegalizerInfo::getAction ( const MachineInstr MI,
const MachineRegisterInfo MRI 
) const

◆ getActionDefinitions()

const LegalizeRuleSet & LegalizerInfo::getActionDefinitions ( unsigned  Opcode) const

Get the action definitions for the given opcode.

Use this to run a LegalityQuery through the definitions.

Definition at line 286 of file LegalizerInfo.cpp.

References getActionDefinitionsIdx().

Referenced by getAction(), and verify().

◆ getActionDefinitionsBuilder() [1/2]

LegalizeRuleSet & LegalizerInfo::getActionDefinitionsBuilder ( unsigned  Opcode)

Get the action definition builder for the given opcode.

Use this to define the action definitions.

It is an error to request an opcode that has already been requested by the multiple-opcode variant.

Definition at line 291 of file LegalizerInfo.cpp.

References assert(), and getActionDefinitionsIdx().

Referenced by getActionDefinitionsBuilder(), llvm::MipsLegalizerInfo::MipsLegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().

◆ getActionDefinitionsBuilder() [2/2]

LegalizeRuleSet & LegalizerInfo::getActionDefinitionsBuilder ( std::initializer_list< unsigned Opcodes)

Get the action definition builder for the given set of opcodes.

Use this to define the action definitions for multiple opcodes at once. The first opcode given will be considered the representative opcode and will hold the definitions whereas the other opcodes will be configured to refer to the representative opcode. This lowers memory requirements and very slightly improves performance.

It would be very easy to introduce unexpected side-effects as a result of this aliasing if it were permitted to request different but intersecting sets of opcodes but that is difficult to keep track of. It is therefore an error to request the same opcode twice using this API, to request an opcode that already has definitions, or to use the single-opcode API on an opcode that has already been requested by this API.

Definition at line 298 of file LegalizerInfo.cpp.

References aliasActionDefinitions(), assert(), E, llvm::empty(), getActionDefinitionsBuilder(), I, and llvm::MCID::Return.

◆ getActionDefinitionsIdx()

unsigned LegalizerInfo::getActionDefinitionsIdx ( unsigned  Opcode) const

◆ getOpcodeIdxForOpcode()

unsigned LegalizerInfo::getOpcodeIdxForOpcode ( unsigned  Opcode) const

◆ increaseToLargerTypesAndDecreaseToLargest()

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

Helper function to implement many typical SizeChangeStrategy functions.

Definition at line 385 of file LegalizerInfo.cpp.

◆ isLegal()

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

◆ legalizeCustom()

bool LegalizerInfo::legalizeCustom ( MachineInstr MI,
MachineRegisterInfo MRI,
MachineIRBuilder MIRBuilder,
GISelChangeObserver Observer 
) 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 907 of file LegalizerInfo.h.

References assert(), llvm::sys::path::end(), llvm::LegalizeActions::FewerElements, llvm::find(), first, llvm::machineFunctionIsIllegal(), MI, llvm::LegalizeActions::MoreElements, MRI, llvm::LegalizeActions::NarrowScalar, Query(), llvm::SmallVectorImpl< T >::resize(), second, Size, llvm::SmallVectorBase::size(), llvm::LegalizeActions::Unsupported, and llvm::LegalizeActions::WidenScalar.

Referenced by computeTables().

◆ narrowToSmallerAndUnsupportedIfTooSmall()

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

◆ narrowToSmallerAndWidenToSmallest()

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

◆ needsLegalizingToDifferentSize()

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

◆ 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 789 of file LegalizerInfo.h.

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

Referenced by 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 814 of file LegalizerInfo.h.

References llvm::size().

Referenced by 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 825 of file LegalizerInfo.h.

References llvm::size().

◆ 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 844 of file LegalizerInfo.h.

References llvm::LegalizeActions::Unsupported.

Referenced by computeTables().

◆ verify()

void LegalizerInfo::verify ( const MCInstrInfo MII) const

◆ 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 855 of file LegalizerInfo.h.

References assert(), llvm::LegalizeActions::NarrowScalar, and llvm::LegalizeActions::WidenScalar.

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: