LLVM  10.0.0
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:
[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 LegalizeRuleSet & getActionDefinitions (unsigned Opcode) const
 Get the action definitions for the given opcode. More...
 
LegalizeRuleSet & getActionDefinitionsBuilder (unsigned Opcode)
 Get the action definition builder for the given opcode. More...
 
LegalizeRuleSet & getActionDefinitionsBuilder (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 LegalityQuery &Query) const
 
bool isLegal (const MachineInstr &MI, const MachineRegisterInfo &MRI) const
 
bool isLegalOrCustom (const MachineInstr &MI, const MachineRegisterInfo &MRI) const
 
virtual bool legalizeCustom (MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder, GISelChangeObserver &Observer) const
 
virtual bool legalizeIntrinsic (MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &MIRBuilder) const
 Return true if MI is either legal or has been legalized and false if not legal. More...
 
virtual unsigned getExtOpcodeForWideningConstant (LLT SmallTy) const
 Return the opcode (SEXT/ZEXT/ANYEXT) that should be performed while widening a constant of type SmallTy which targets can override. More...
 

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

Member Typedef Documentation

◆ SizeAndAction

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

Definition at line 960 of file LegalizerInfo.h.

◆ SizeAndActionsVec

Definition at line 961 of file LegalizerInfo.h.

◆ SizeChangeStrategy

Definition at line 963 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 286 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::AMDGPULegalizerInfo::AMDGPULegalizerInfo(), llvm::RISCVLegalizerInfo::RISCVLegalizerInfo(), 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 458 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(), isLegalOrCustom(), 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 422 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 427 of file LegalizerInfo.cpp.

References assert(), and getActionDefinitionsIdx().

Referenced by llvm::AMDGPULegalizerInfo::AMDGPULegalizerInfo(), getActionDefinitionsBuilder(), and llvm::X86LegalizerInfo::legalizeIntrinsic().

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

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

◆ getActionDefinitionsIdx()

unsigned LegalizerInfo::getActionDefinitionsIdx ( unsigned  Opcode) const

◆ getExtOpcodeForWideningConstant()

unsigned LegalizerInfo::getExtOpcodeForWideningConstant ( LLT  SmallTy) const
virtual

Return the opcode (SEXT/ZEXT/ANYEXT) that should be performed while widening a constant of type SmallTy which targets can override.

For eg, the DAG does (SmallTy.isByteSized() ? G_SEXT : G_ZEXT) which will be the default.

Definition at line 690 of file LegalizerInfo.cpp.

References llvm::LLT::isByteSized().

Referenced by llvm::LegalizerHelper::widenScalar().

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

◆ isLegal() [1/2]

bool llvm::LegalizerInfo::isLegal ( const LegalityQuery &  Query) const
inline

◆ isLegal() [2/2]

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

◆ isLegalOrCustom()

bool LegalizerInfo::isLegalOrCustom ( const MachineInstr &  MI,
const MachineRegisterInfo &  MRI 
) const

◆ legalizeCustom()

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

◆ legalizeIntrinsic()

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

Return true if MI is either legal or has been legalized and false if not legal.

Reimplemented in llvm::AMDGPULegalizerInfo, llvm::X86LegalizerInfo, llvm::AArch64LegalizerInfo, and llvm::MipsLegalizerInfo.

Definition at line 684 of file LegalizerInfo.cpp.

Referenced by llvm::LegalizerHelper::legalizeInstrStep().

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

References llvm::LegalizeActions::FewerElements, MI, llvm::LegalizeActions::MoreElements, and MRI.

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

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

Referenced by llvm::AMDGPULegalizerInfo::AMDGPULegalizerInfo(), and llvm::X86LegalizerInfo::legalizeIntrinsic().

◆ 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 994 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 1005 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 1024 of file LegalizerInfo.h.

References llvm::LegalizeActions::Unsupported.

Referenced by computeTables().

◆ verify()

void LegalizerInfo::verify ( const MCInstrInfo &  MII) const

Perform simple self-diagnostic and assert if there is anything obviously wrong with the actions set up.

Precondition
Type indices of every opcode form a dense set starting from 0.

Definition at line 695 of file LegalizerInfo.cpp.

References llvm::dbgs(), llvm::errs(), llvm::MCInstrInfo::get(), getActionDefinitions(), llvm::MCInstrInfo::getName(), llvm::MCOperandInfo::isGenericImm(), llvm::MCOperandInfo::isGenericType(), LLVM_DEBUG, llvm::max(), llvm::MCInstrDesc::opInfo_begin(), llvm::MCInstrDesc::opInfo_end(), and llvm::report_fatal_error().

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

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