LLVM 22.0.0git
llvm::GIMatchTableExecutor Class Referenceabstract

Provides the logic to execute GlobalISel match tables, which are used by the instruction selector and instruction combiners as their engine to match and apply MIR patterns. More...

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

Inheritance diagram for llvm::GIMatchTableExecutor:
[legend]

Classes

struct  ExecInfoTy
struct  MatcherState

Public Member Functions

virtual ~GIMatchTableExecutor ()=default
virtual void setupGeneratedPerFunctionState (MachineFunction &MF)=0
virtual void setupMF (MachineFunction &mf, GISelValueTracking *vt, CodeGenCoverage *covinfo=nullptr, ProfileSummaryInfo *psi=nullptr, BlockFrequencyInfo *bfi=nullptr)
 Setup per-MF executor state.

Static Public Member Functions

static LLVM_ATTRIBUTE_ALWAYS_INLINE uint64_t fastDecodeULEB128 (const uint8_t *LLVM_ATTRIBUTE_RESTRICT MatchTable, uint64_t &CurrentIdx)

Public Attributes

CodeGenCoverageCoverageInfo = nullptr
GISelValueTrackingVT = nullptr
MachineFunctionMF = nullptr
ProfileSummaryInfoPSI = nullptr
BlockFrequencyInfoBFI = nullptr
MachineBasicBlockCurMBB = nullptr

Protected Types

using ComplexRendererFns
using RecordedMIVector = SmallVector<MachineInstr *, 4>
using NewMIVector = SmallVector<MachineInstrBuilder, 4>

Protected Member Functions

bool shouldOptForSize (const MachineFunction *MF) const
LLVM_ABI GIMatchTableExecutor ()
template<class TgtExecutor, class PredicateBitset, class ComplexMatcherMemFn, class CustomRendererFn>
bool executeMatchTable (TgtExecutor &Exec, MatcherState &State, const ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn > &ExecInfo, MachineIRBuilder &Builder, const uint8_t *MatchTable, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures, CodeGenCoverage *CoverageInfo) const
 Execute a given matcher table and return true if the match was successful and false otherwise.
virtual const uint8_tgetMatchTable () const
virtual bool testImmPredicate_I64 (unsigned, int64_t) const
virtual bool testImmPredicate_APInt (unsigned, const APInt &) const
virtual bool testImmPredicate_APFloat (unsigned, const APFloat &) const
virtual bool testMIPredicate_MI (unsigned, const MachineInstr &, const MatcherState &State) const
virtual bool testMOPredicate_MO (unsigned, const MachineOperand &, const MatcherState &State) const
virtual bool testSimplePredicate (unsigned) const
virtual bool runCustomAction (unsigned, const MatcherState &State, NewMIVector &OutMIs) const
LLVM_ABI bool isOperandImmEqual (const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI, bool Splat=false) const
LLVM_ABI bool isBaseWithConstantOffset (const MachineOperand &Root, const MachineRegisterInfo &MRI) const
 Return true if the specified operand is a G_PTR_ADD with a G_CONSTANT on the right-hand side.
LLVM_ABI bool isObviouslySafeToFold (MachineInstr &MI, MachineInstr &IntoMI) const
 Return true if MI can obviously be folded into IntoMI.

Static Protected Member Functions

template<typename Ty>
static Ty readBytesAs (const uint8_t *MatchTable)
static ArrayRef< MachineOperandgetRemainingOperands (const MachineInstr &MI, unsigned FirstVarOp)

Detailed Description

Provides the logic to execute GlobalISel match tables, which are used by the instruction selector and instruction combiners as their engine to match and apply MIR patterns.

Definition at line 593 of file GIMatchTableExecutor.h.

Member Typedef Documentation

◆ ComplexRendererFns

Initial value:
std::optional<SmallVector<std::function<void(MachineInstrBuilder &)>, 4>>
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Definition at line 622 of file GIMatchTableExecutor.h.

◆ NewMIVector

◆ RecordedMIVector

Constructor & Destructor Documentation

◆ ~GIMatchTableExecutor()

virtual llvm::GIMatchTableExecutor::~GIMatchTableExecutor ( )
virtualdefault

◆ GIMatchTableExecutor()

GIMatchTableExecutor::GIMatchTableExecutor ( )
protecteddefault

References CoverageInfo, LLVM_ABI, MRI, TII, and TRI.

Member Function Documentation

◆ executeMatchTable()

template<class TgtExecutor, class PredicateBitset, class ComplexMatcherMemFn, class CustomRendererFn>
bool llvm::GIMatchTableExecutor::executeMatchTable ( TgtExecutor & Exec,
MatcherState & State,
const ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn > & ExecInfo,
MachineIRBuilder & Builder,
const uint8_t * MatchTable,
const TargetInstrInfo & TII,
MachineRegisterInfo & MRI,
const TargetRegisterInfo & TRI,
const RegisterBankInfo & RBI,
const PredicateBitset & AvailableFeatures,
CodeGenCoverage * CoverageInfo ) const
protected

Execute a given matcher table and return true if the match was successful and false otherwise.

Definition at line 46 of file GIMatchTableExecutorImpl.h.

References AbstractManglingParser< Derived, Alloc >::NumOps, llvm::MachineInstrBuilder::add(), assert(), llvm::canReplaceReg(), llvm::GISelChangeObserver::changedInstr(), llvm::GISelChangeObserver::changingAllUsesOfReg(), llvm::GISelChangeObserver::changingInstr(), llvm::GIMatchTableExecutor::ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::ComplexPredicates, llvm::constrainOperandRegClass(), llvm::constrainSelectedInstRegOperands(), CoverageInfo, llvm::GIMatchTableExecutor::ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::CustomRenderers, llvm::dbgs(), DEBUG_WITH_TYPE, llvm::Default, llvm::drop_begin(), E(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::ConstantInt::equalsInt(), llvm::GISelChangeObserver::erasingInstr(), fastDecodeULEB128(), llvm::GIMatchTableExecutor::ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::FeatureBitsets, llvm::GISelChangeObserver::finishedChangingAllUsesOfReg(), llvm::IntegerType::get(), llvm::MachineMemOperand::getAddrSpace(), llvm::MachineMemOperand::getAlign(), llvm::MachineOperand::getCImm(), llvm::getDefIgnoringCopies(), llvm::MachineOperand::getImm(), llvm::MachineOperand::getIntrinsicID(), llvm::MachineInstr::getMF(), llvm::MachineOperand::getPredicate(), llvm::MachineOperand::getReg(), llvm::RegisterBankInfo::getRegBank(), llvm::RegisterBankInfo::getRegBankFromRegClass(), llvm::LLT::getScalarSizeInBits(), llvm::MachineMemOperand::getSize(), llvm::MachineMemOperand::getSizeInBits(), llvm::getSrcRegIgnoringCopies(), llvm::LocationSize::getValue(), llvm::GICXXCustomAction_Invalid, llvm::GICXXPred_Invalid, llvm::GIM_CheckAPFloatImmPredicate, llvm::GIM_CheckAPIntImmPredicate, llvm::GIM_CheckAtomicOrdering, llvm::GIM_CheckAtomicOrderingOrStrongerThan, llvm::GIM_CheckAtomicOrderingWeakerThan, llvm::GIM_CheckCanReplaceReg, llvm::GIM_CheckCmpPredicate, llvm::GIM_CheckComplexPattern, llvm::GIM_CheckConstantInt, llvm::GIM_CheckConstantInt8, llvm::GIM_CheckCxxInsnPredicate, llvm::GIM_CheckFeatures, llvm::GIM_CheckHasNoUse, llvm::GIM_CheckHasOneUse, llvm::GIM_CheckI64ImmPredicate, llvm::GIM_CheckImmOperandPredicate, llvm::GIM_CheckIntrinsicID, llvm::GIM_CheckIsBuildVectorAllOnes, llvm::GIM_CheckIsBuildVectorAllZeros, llvm::GIM_CheckIsImm, llvm::GIM_CheckIsMBB, llvm::GIM_CheckIsSafeToFold, llvm::GIM_CheckIsSameOperand, llvm::GIM_CheckIsSameOperandIgnoreCopies, llvm::GIM_CheckLeafOperandPredicate, llvm::GIM_CheckLiteralInt, llvm::GIM_CheckMemoryAddressSpace, llvm::GIM_CheckMemoryAlignment, llvm::GIM_CheckMemorySizeEqualTo, llvm::GIM_CheckMemorySizeEqualToLLT, llvm::GIM_CheckMemorySizeGreaterThanLLT, llvm::GIM_CheckMemorySizeLessThanLLT, llvm::GIM_CheckNumOperands, llvm::GIM_CheckNumOperandsGE, llvm::GIM_CheckNumOperandsLE, llvm::GIM_CheckOpcode, llvm::GIM_CheckOpcodeIsEither, llvm::GIM_CheckPointerToAny, llvm::GIM_CheckRegBankForClass, llvm::GIM_CheckSimplePredicate, llvm::GIM_CheckType, llvm::GIM_MIFlags, llvm::GIM_MIFlagsNot, llvm::GIM_RecordInsn, llvm::GIM_RecordInsnIgnoreCopies, llvm::GIM_RecordNamedOperand, llvm::GIM_RecordRegType, llvm::GIM_Reject, llvm::GIM_RootCheckRegBankForClass, llvm::GIM_RootCheckType, llvm::GIM_SwitchOpcode, llvm::GIM_SwitchType, llvm::GIM_Try, llvm::GIR_AddCImm, llvm::GIR_AddImm, llvm::GIR_AddImm8, llvm::GIR_AddImplicitDef, llvm::GIR_AddImplicitUse, llvm::GIR_AddIntrinsicID, llvm::GIR_AddRegister, llvm::GIR_AddSimpleTempRegister, llvm::GIR_AddTempRegister, llvm::GIR_AddTempSubRegister, llvm::GIR_BuildConstant, llvm::GIR_BuildMI, llvm::GIR_BuildRootMI, llvm::GIR_ComplexRenderer, llvm::GIR_ComplexSubOperandRenderer, llvm::GIR_ComplexSubOperandSubRegRenderer, llvm::GIR_ConstrainOperandRC, llvm::GIR_ConstrainSelectedInstOperands, llvm::GIR_Copy, llvm::GIR_CopyConstantAsSImm, llvm::GIR_CopyFConstantAsFPImm, llvm::GIR_CopyMIFlags, llvm::GIR_CopyOrAddZeroReg, llvm::GIR_CopyRemaining, llvm::GIR_CopySubReg, llvm::GIR_Coverage, llvm::GIR_CustomOperandRenderer, llvm::GIR_CustomRenderer, llvm::GIR_Done, llvm::GIR_DoneWithCustomAction, llvm::GIR_EraseFromParent, llvm::GIR_EraseRootFromParent_Done, llvm::GIR_MakeTempReg, llvm::GIR_MergeMemOperands, llvm::GIR_MutateOpcode, llvm::GIR_ReplaceReg, llvm::GIR_ReplaceRegWithTempReg, llvm::GIR_RootConstrainSelectedInstOperands, llvm::GIR_RootToRootCopy, llvm::GIR_SetImplicitDefDead, llvm::GIR_SetMIFlags, llvm::GIR_UnsetMIFlags, I, llvm::RegState::Implicit, llvm::isAtLeastOrStrongerThan(), llvm::isBuildVectorAllOnes(), llvm::isBuildVectorAllZeros(), llvm::MachineOperand::isCImm(), llvm::MachineOperand::isImm(), llvm::MachineOperand::isIntrinsicID(), llvm::details::FixedOrScalableQuantity< TypeSize, uint64_t >::isKnownGE(), llvm::details::FixedOrScalableQuantity< TypeSize, uint64_t >::isKnownLE(), isObviouslySafeToFold(), isOperandImmEqual(), llvm::Register::isPhysical(), llvm::MachineOperand::isPredicate(), llvm::MachineOperand::isReg(), llvm::isStrongerThan(), llvm_unreachable, MF, MI, llvm::MinAlign(), MRI, llvm::MachineInstr::NoFPExcept, llvm::MachineInstr::operands(), OpIdx, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), readBytesAs(), llvm::SmallVectorImpl< T >::resize(), runCustomAction(), llvm::SignExtend64(), Size, llvm::SmallVectorTemplateCommon< T, typename >::size(), SubReg, llvm::Success, testImmPredicate_APFloat(), testImmPredicate_APInt(), testImmPredicate_I64(), testMIPredicate_MI(), testMOPredicate_MO(), testSimplePredicate(), TII, TRI, llvm::GIMatchTableExecutor::ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::TypeIDMap, and llvm::GIMatchTableExecutor::ExecInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::TypeObjects.

◆ fastDecodeULEB128()

LLVM_ATTRIBUTE_ALWAYS_INLINE uint64_t llvm::GIMatchTableExecutor::fastDecodeULEB128 ( const uint8_t *LLVM_ATTRIBUTE_RESTRICT MatchTable,
uint64_t & CurrentIdx )
inlinestatic

Definition at line 766 of file GIMatchTableExecutor.h.

References LLVM_ATTRIBUTE_RESTRICT, and LLVM_UNLIKELY.

Referenced by executeMatchTable().

◆ getMatchTable()

virtual const uint8_t * llvm::GIMatchTableExecutor::getMatchTable ( ) const
inlineprotectedvirtual

Definition at line 694 of file GIMatchTableExecutor.h.

References llvm_unreachable.

◆ getRemainingOperands()

ArrayRef< MachineOperand > llvm::GIMatchTableExecutor::getRemainingOperands ( const MachineInstr & MI,
unsigned FirstVarOp )
inlinestaticprotected

Definition at line 753 of file GIMatchTableExecutor.h.

References llvm::drop_begin(), MI, and Operands.

◆ isBaseWithConstantOffset()

bool GIMatchTableExecutor::isBaseWithConstantOffset ( const MachineOperand & Root,
const MachineRegisterInfo & MRI ) const
protected

Return true if the specified operand is a G_PTR_ADD with a G_CONSTANT on the right-hand side.

GlobalISel's separation of pointer and integer types means that we don't need to worry about G_OR with equivalent semantics.

Definition at line 45 of file GIMatchTableExecutor.cpp.

References llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getReg(), llvm::MachineOperand::isReg(), and MRI.

◆ isObviouslySafeToFold()

bool GIMatchTableExecutor::isObviouslySafeToFold ( MachineInstr & MI,
MachineInstr & IntoMI ) const
protected

Return true if MI can obviously be folded into IntoMI.

MI and IntoMI do not need to be in the same basic blocks, but MI must preceed IntoMI.

Definition at line 62 of file GIMatchTableExecutor.cpp.

References llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::MachineInstr::getParent(), llvm::instructionsWithoutDebug(), and MI.

Referenced by executeMatchTable().

◆ isOperandImmEqual()

bool GIMatchTableExecutor::isOperandImmEqual ( const MachineOperand & MO,
int64_t Value,
const MachineRegisterInfo & MRI,
bool Splat = false ) const
protected

◆ readBytesAs()

template<typename Ty>
Ty llvm::GIMatchTableExecutor::readBytesAs ( const uint8_t * MatchTable)
inlinestaticprotected

Definition at line 747 of file GIMatchTableExecutor.h.

Referenced by executeMatchTable().

◆ runCustomAction()

virtual bool llvm::GIMatchTableExecutor::runCustomAction ( unsigned ,
const MatcherState & State,
NewMIVector & OutMIs ) const
inlineprotectedvirtual

Definition at line 726 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ setupGeneratedPerFunctionState()

virtual void llvm::GIMatchTableExecutor::setupGeneratedPerFunctionState ( MachineFunction & MF)
pure virtual

References MF.

Referenced by setupMF().

◆ setupMF()

virtual void llvm::GIMatchTableExecutor::setupMF ( MachineFunction & mf,
GISelValueTracking * vt,
CodeGenCoverage * covinfo = nullptr,
ProfileSummaryInfo * psi = nullptr,
BlockFrequencyInfo * bfi = nullptr )
inlinevirtual

◆ shouldOptForSize()

bool llvm::GIMatchTableExecutor::shouldOptForSize ( const MachineFunction * MF) const
inlineprotected

Definition at line 644 of file GIMatchTableExecutor.h.

References BFI, CurMBB, F, MF, PSI, and llvm::shouldOptimizeForSize().

◆ testImmPredicate_APFloat()

virtual bool llvm::GIMatchTableExecutor::testImmPredicate_APFloat ( unsigned ,
const APFloat &  ) const
inlineprotectedvirtual

Definition at line 706 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testImmPredicate_APInt()

virtual bool llvm::GIMatchTableExecutor::testImmPredicate_APInt ( unsigned ,
const APInt &  ) const
inlineprotectedvirtual

Definition at line 702 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testImmPredicate_I64()

virtual bool llvm::GIMatchTableExecutor::testImmPredicate_I64 ( unsigned ,
int64_t  ) const
inlineprotectedvirtual

Definition at line 698 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testMIPredicate_MI()

virtual bool llvm::GIMatchTableExecutor::testMIPredicate_MI ( unsigned ,
const MachineInstr & ,
const MatcherState & State ) const
inlineprotectedvirtual

Definition at line 710 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testMOPredicate_MO()

virtual bool llvm::GIMatchTableExecutor::testMOPredicate_MO ( unsigned ,
const MachineOperand & ,
const MatcherState & State ) const
inlineprotectedvirtual

Definition at line 716 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testSimplePredicate()

virtual bool llvm::GIMatchTableExecutor::testSimplePredicate ( unsigned ) const
inlineprotectedvirtual

Definition at line 722 of file GIMatchTableExecutor.h.

References llvm_unreachable.

Referenced by executeMatchTable().

Member Data Documentation

◆ BFI

◆ CoverageInfo

◆ CurMBB

MachineBasicBlock* llvm::GIMatchTableExecutor::CurMBB = nullptr

Definition at line 603 of file GIMatchTableExecutor.h.

Referenced by setupMF(), and shouldOptForSize().

◆ MF

◆ PSI

◆ VT

GISelValueTracking* llvm::GIMatchTableExecutor::VT = nullptr

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