LLVM
8.0.1
|
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
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 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... | |
Definition at line 749 of file LegalizerInfo.h.
using llvm::LegalizerInfo::SizeAndAction = std::pair<uint16_t, LegalizeAction> |
Definition at line 780 of file LegalizerInfo.h.
using llvm::LegalizerInfo::SizeAndActionsVec = std::vector<SizeAndAction> |
Definition at line 781 of file LegalizerInfo.h.
using llvm::LegalizerInfo::SizeChangeStrategy = std::function<SizeAndActionsVec(const SizeAndActionsVec &v)> |
Definition at line 783 of file LegalizerInfo.h.
LegalizerInfo::LegalizerInfo | ( | ) |
Definition at line 110 of file LegalizerInfo.cpp.
References llvm::LegalizeActions::Legal, llvm::Lower, narrowToSmallerAndUnsupportedIfTooSmall(), setLegalizeScalarToDifferentSizeStrategy(), widenToLargerTypesAndNarrowToLargest(), and widenToLargerTypesUnsupportedOtherwise().
|
virtualdefault |
Definition at line 313 of file LegalizerInfo.cpp.
References llvm::LegalizeRuleSet::aliasTo(), assert(), and getOpcodeIdxForOpcode().
Referenced by getActionDefinitionsBuilder().
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().
|
static |
Helper function to implement many typical SizeChangeStrategy functions.
Definition at line 405 of file LegalizerInfo.cpp.
References assert(), llvm::LegalizeActions::Custom, llvm::sys::path::end(), llvm::LegalizeActions::FewerElements, llvm::LLT::getAddressSpace(), llvm::LLT::getNumElements(), getOpcodeIdxForOpcode(), llvm::LLT::getScalarSizeInBits(), llvm::LLT::getSizeInBits(), llvm::InstrAspect::Idx, llvm::LLT::isPointer(), llvm::LLT::isScalar(), llvm::LLT::isVector(), llvm::LegalizeActions::Legal, LLVM_FALLTHROUGH, llvm_unreachable, llvm::Lower, llvm::LegalizeActions::MoreElements, llvm::LegalizeActions::NarrowScalar, needsLegalizingToDifferentSize(), llvm::LegalizeActions::NotFound, llvm::InstrAspect::Opcode, llvm::LLT::pointer(), llvm::LLT::scalar(), second, Size, llvm::SmallVectorBase::size(), llvm::size(), llvm::InstrAspect::Type, llvm::LegalizeActions::Unsupported, llvm::upper_bound(), llvm::LegalizeActions::UseLegacyRules, llvm::LLT::vector(), and llvm::LegalizeActions::WidenScalar.
LegalizeActionStep LegalizerInfo::getAction | ( | const LegalityQuery & | Query | ) | const |
Determine what action should be taken to legalize the described instruction.
Requires computeTables to have been called.
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().
LegalizeActionStep LegalizerInfo::getAction | ( | const MachineInstr & | MI, |
const MachineRegisterInfo & | MRI | ||
) | const |
Determine what action should be taken to legalize the given generic instruction.
Definition at line 343 of file LegalizerInfo.cpp.
References getAction(), llvm::MachineInstr::getDesc(), llvm::MCOperandInfo::getGenericTypeIndex(), llvm::MCInstrDesc::getNumOperands(), llvm::MachineInstr::getOpcode(), getTypeFromTypeIdx(), llvm::MachineInstr::memoperands(), llvm::MCInstrDesc::OpInfo, llvm::SmallVectorTemplateBase< T >::push_back(), and llvm::SmallBitVector::set().
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().
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().
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.
Definition at line 271 of file LegalizerInfo.cpp.
References assert(), llvm::dbgs(), getOpcodeIdxForOpcode(), and LLVM_DEBUG.
Referenced by getActionDefinitions(), and getActionDefinitionsBuilder().
Definition at line 266 of file LegalizerInfo.cpp.
References assert().
Referenced by aliasActionDefinitions(), decreaseToSmallerTypesAndIncreaseToSmallest(), and getActionDefinitionsIdx().
|
static |
Helper function to implement many typical SizeChangeStrategy functions.
Definition at line 385 of file LegalizerInfo.cpp.
bool LegalizerInfo::isLegal | ( | const MachineInstr & | MI, |
const MachineRegisterInfo & | MRI | ||
) | const |
Definition at line 373 of file LegalizerInfo.cpp.
References llvm::LegalizeActionStep::Action, getAction(), and llvm::LegalizeActions::Legal.
|
virtual |
Reimplemented in llvm::ARMLegalizerInfo, llvm::AArch64LegalizerInfo, and llvm::MipsLegalizerInfo.
Definition at line 378 of file LegalizerInfo.cpp.
Referenced by llvm::LegalizerHelper::legalizeInstrStep().
|
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:
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().
|
inlinestatic |
Definition at line 872 of file LegalizerInfo.h.
References llvm::LegalizeActions::NarrowScalar, and llvm::LegalizeActions::Unsupported.
Referenced by LegalizerInfo().
|
inlinestatic |
Definition at line 879 of file LegalizerInfo.h.
References assert(), llvm::LegalizeActions::NarrowScalar, and llvm::LegalizeActions::WidenScalar.
Referenced by llvm::X86LegalizerInfo::X86LegalizerInfo().
|
inlinestatic |
Definition at line 766 of file LegalizerInfo.h.
References llvm::LegalizeActions::FewerElements, llvm::LegalizeActions::MoreElements, llvm::LegalizeActions::NarrowScalar, llvm::LegalizeActions::Unsupported, and llvm::LegalizeActions::WidenScalar.
Referenced by decreaseToSmallerTypesAndIncreaseToSmallest().
|
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().
|
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().
|
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().
|
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().
void LegalizerInfo::verify | ( | const MCInstrInfo & | MII | ) | const |
Perform simple self-diagnostic and assert if there is anything obviously wrong with the actions set up.
Definition at line 545 of file LegalizerInfo.cpp.
References llvm::dbgs(), llvm::errs(), llvm::MCInstrInfo::get(), getActionDefinitions(), llvm::MCInstrInfo::getName(), llvm::MCOperandInfo::isGenericType(), LLVM_DEBUG, llvm::max(), llvm::MCInstrDesc::opInfo_begin(), llvm::MCInstrDesc::opInfo_end(), llvm::report_fatal_error(), and llvm::LegalizeRuleSet::verifyTypeIdxsCoverage().
Referenced by llvm::MipsLegalizerInfo::MipsLegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().
|
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().
|
inlinestatic |
Definition at line 865 of file LegalizerInfo.h.
References llvm::LegalizeActions::Unsupported, and llvm::LegalizeActions::WidenScalar.
Referenced by LegalizerInfo(), and llvm::X86LegalizerInfo::X86LegalizerInfo().