LLVM 17.0.0git
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | List of all members
llvm::InstructionSelector Class Referenceabstract

Provides the logic to select generic machine instructions. More...

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

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

Classes

struct  ISelInfoTy
 
struct  MatcherState
 

Public Member Functions

virtual ~InstructionSelector ()=default
 
virtual bool select (MachineInstr &I)=0
 Select the (possibly generic) instruction I to only use target-specific opcodes.
 
virtual void setupGeneratedPerFunctionState (MachineFunction &MF)
 
virtual void setupMF (MachineFunction &mf, GISelKnownBits *KB, CodeGenCoverage &covinfo, ProfileSummaryInfo *psi, BlockFrequencyInfo *bfi)
 Setup per-MF selector state.
 

Public Attributes

CodeGenCoverageCoverageInfo = nullptr
 
GISelKnownBitsKnownBits = nullptr
 
MachineFunctionMF = nullptr
 
ProfileSummaryInfoPSI = nullptr
 
BlockFrequencyInfoBFI = nullptr
 
MachineBasicBlockCurMBB = nullptr
 

Protected Types

using ComplexRendererFns = std::optional< SmallVector< std::function< void(MachineInstrBuilder &)>, 4 > >
 
using RecordedMIVector = SmallVector< MachineInstr *, 4 >
 
using NewMIVector = SmallVector< MachineInstrBuilder, 4 >
 

Protected Member Functions

bool shouldOptForSize (const MachineFunction *MF) const
 
 InstructionSelector ()
 
template<class TgtInstructionSelector , class PredicateBitset , class ComplexMatcherMemFn , class CustomRendererFn >
bool executeMatchTable (TgtInstructionSelector &ISel, NewMIVector &OutMIs, MatcherState &State, const ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn > &ISelInfo, const int64_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 int64_t * getMatchTable () 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 std::array< const MachineOperand *, 3 > &Operands) const
 
bool isOperandImmEqual (const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
 
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.
 
bool isObviouslySafeToFold (MachineInstr &MI, MachineInstr &IntoMI) const
 Return true if MI can obviously be folded into IntoMI.
 

Detailed Description

Provides the logic to select generic machine instructions.

Definition at line 442 of file InstructionSelector.h.

Member Typedef Documentation

◆ ComplexRendererFns

using llvm::InstructionSelector::ComplexRendererFns = std::optional<SmallVector<std::function<void(MachineInstrBuilder &)>, 4> >
protected

Definition at line 484 of file InstructionSelector.h.

◆ NewMIVector

Definition at line 487 of file InstructionSelector.h.

◆ RecordedMIVector

Definition at line 486 of file InstructionSelector.h.

Constructor & Destructor Documentation

◆ ~InstructionSelector()

virtual llvm::InstructionSelector::~InstructionSelector ( )
virtualdefault

◆ InstructionSelector()

InstructionSelector::InstructionSelector ( )
protecteddefault

Member Function Documentation

◆ executeMatchTable()

template<class TgtInstructionSelector , class PredicateBitset , class ComplexMatcherMemFn , class CustomRendererFn >
bool llvm::InstructionSelector::executeMatchTable ( TgtInstructionSelector &  ISel,
NewMIVector OutMIs,
MatcherState State,
const ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn > &  ISelInfo,
const int64_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 50 of file InstructionSelectorImpl.h.

References assert(), llvm::BuildMI(), llvm::InstructionSelector::ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::ComplexPredicates, llvm::constrainOperandRegClass(), llvm::constrainSelectedInstRegOperands(), CoverageInfo, llvm::InstructionSelector::ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::CustomRenderers, llvm::dbgs(), DEBUG_WITH_TYPE, llvm::Default, llvm::SmallVectorBase< Size_T >::empty(), llvm::ConstantInt::equalsInt(), llvm::InstructionSelector::ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::FeatureBitsets, Flags, llvm::LLT::getAddressSpace(), llvm::MachineMemOperand::getAddrSpace(), llvm::MachineMemOperand::getAlign(), llvm::MachineOperand::getCImm(), llvm::MachineFunction::getDataLayout(), llvm::getDefIgnoringCopies(), llvm::MachineOperand::getImm(), llvm::MachineOperand::getIntrinsicID(), llvm::DataLayout::getPointerSizeInBits(), llvm::MachineOperand::getPredicate(), llvm::MachineOperand::getReg(), llvm::RegisterBankInfo::getRegBank(), llvm::RegisterBankInfo::getRegBankFromRegClass(), llvm::MachineFunction::getRegInfo(), llvm::MachineMemOperand::getSize(), llvm::LLT::getSizeInBits(), llvm::MachineMemOperand::getSizeInBits(), llvm::GIM_CheckAPFloatImmPredicate, llvm::GIM_CheckAPIntImmPredicate, llvm::GIM_CheckAtomicOrdering, llvm::GIM_CheckAtomicOrderingOrStrongerThan, llvm::GIM_CheckAtomicOrderingWeakerThan, llvm::GIM_CheckCmpPredicate, llvm::GIM_CheckComplexPattern, llvm::GIM_CheckConstantInt, llvm::GIM_CheckCxxInsnPredicate, llvm::GIM_CheckFeatures, llvm::GIM_CheckHasNoUse, 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_CheckLiteralInt, llvm::GIM_CheckMemoryAddressSpace, llvm::GIM_CheckMemoryAlignment, llvm::GIM_CheckMemorySizeEqualTo, llvm::GIM_CheckMemorySizeEqualToLLT, llvm::GIM_CheckMemorySizeGreaterThanLLT, llvm::GIM_CheckMemorySizeLessThanLLT, llvm::GIM_CheckNumOperands, llvm::GIM_CheckOpcode, llvm::GIM_CheckOpcodeIsEither, llvm::GIM_CheckPointerToAny, llvm::GIM_CheckRegBankForClass, llvm::GIM_CheckType, llvm::GIM_RecordInsn, llvm::GIM_RecordInsnIgnoreCopies, llvm::GIM_RecordNamedOperand, llvm::GIM_Reject, llvm::GIM_SwitchOpcode, llvm::GIM_SwitchType, llvm::GIM_Try, llvm::GIPFP_APFloat_Invalid, llvm::GIPFP_APInt_Invalid, llvm::GIPFP_I64_Invalid, llvm::GIPFP_MI_Invalid, llvm::GIR_AddImm, llvm::GIR_AddImplicitDef, llvm::GIR_AddImplicitUse, llvm::GIR_AddRegister, llvm::GIR_AddTempRegister, llvm::GIR_AddTempSubRegister, llvm::GIR_BuildMI, 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_CopyOrAddZeroReg, llvm::GIR_CopySubReg, llvm::GIR_Coverage, llvm::GIR_CustomOperandRenderer, llvm::GIR_CustomRenderer, llvm::GIR_Done, llvm::GIR_EraseFromParent, llvm::GIR_MakeTempReg, llvm::GIR_MergeMemOperands, llvm::GIR_MutateOpcode, llvm::GIU_MergeMemOperands_EndOfList, I, llvm::RegState::Implicit, llvm::isAtLeastOrStrongerThan(), llvm::isBuildVectorAllOnes(), llvm::isBuildVectorAllZeros(), llvm::MachineOperand::isCImm(), llvm::MachineOperand::isImm(), llvm::MachineOperand::isIntrinsicID(), isObviouslySafeToFold(), isOperandImmEqual(), llvm::Register::isPhysical(), llvm::LLT::isPointer(), llvm::MachineOperand::isPredicate(), llvm::MachineOperand::isReg(), llvm::isStrongerThan(), llvm_unreachable, MF, MI, llvm::MinAlign(), llvm::InstructionSelector::MatcherState::MIs, MRI, llvm::MachineInstr::NoFPExcept, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstructionSelector::MatcherState::RecordedOperands, llvm::InstructionSelector::MatcherState::Renderers, llvm::SmallVectorImpl< T >::resize(), llvm::CodeGenCoverage::setCovered(), llvm::SignExtend64(), llvm::SmallVectorBase< Size_T >::size(), Size, SubReg, Success, llvm::InstructionSelector::MatcherState::TempRegisters, testImmPredicate_APFloat(), testImmPredicate_APInt(), testImmPredicate_I64(), testMIPredicate_MI(), TII, TRI, llvm::InstructionSelector::ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::TypeIDMap, and llvm::InstructionSelector::ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn >::TypeObjects.

◆ getMatchTable()

virtual const int64_t * llvm::InstructionSelector::getMatchTable ( ) const
inlineprotectedvirtual

Definition at line 548 of file InstructionSelector.h.

References llvm_unreachable.

◆ isBaseWithConstantOffset()

bool InstructionSelector::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 38 of file InstructionSelector.cpp.

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

◆ isObviouslySafeToFold()

bool InstructionSelector::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 55 of file InstructionSelector.cpp.

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

Referenced by executeMatchTable().

◆ isOperandImmEqual()

bool InstructionSelector::isOperandImmEqual ( const MachineOperand MO,
int64_t  Value,
const MachineRegisterInfo MRI 
) const
protected

◆ select()

virtual bool llvm::InstructionSelector::select ( MachineInstr I)
pure virtual

Select the (possibly generic) instruction I to only use target-specific opcodes.

It is OK to insert multiple instructions, but they cannot be generic pre-isel instructions.

Returns
whether selection succeeded.
Precondition
I.getParent() && I.getParent()->getParent()
Postcondition
if returns true: for I in all mutated/inserted instructions: !isPreISelGenericOpcode(I.getOpcode())

Implemented in llvm::AMDGPUInstructionSelector.

Referenced by llvm::InstructionSelect::runOnMachineFunction().

◆ setupGeneratedPerFunctionState()

virtual void llvm::InstructionSelector::setupGeneratedPerFunctionState ( MachineFunction MF)
inlinevirtual

Definition at line 466 of file InstructionSelector.h.

References llvm_unreachable.

Referenced by setupMF().

◆ setupMF()

virtual void llvm::InstructionSelector::setupMF ( MachineFunction mf,
GISelKnownBits KB,
CodeGenCoverage covinfo,
ProfileSummaryInfo psi,
BlockFrequencyInfo bfi 
)
inlinevirtual

◆ shouldOptForSize()

bool llvm::InstructionSelector::shouldOptForSize ( const MachineFunction MF) const
inlineprotected

◆ testImmPredicate_APFloat()

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

Definition at line 560 of file InstructionSelector.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testImmPredicate_APInt()

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

Definition at line 556 of file InstructionSelector.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testImmPredicate_I64()

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

Definition at line 552 of file InstructionSelector.h.

References llvm_unreachable.

Referenced by executeMatchTable().

◆ testMIPredicate_MI()

virtual bool llvm::InstructionSelector::testMIPredicate_MI ( unsigned  ,
const MachineInstr ,
const std::array< const MachineOperand *, 3 > &  Operands 
) const
inlineprotectedvirtual

Definition at line 564 of file InstructionSelector.h.

References llvm_unreachable.

Referenced by executeMatchTable().

Member Data Documentation

◆ BFI

BlockFrequencyInfo* llvm::InstructionSelector::BFI = nullptr

◆ CoverageInfo

CodeGenCoverage* llvm::InstructionSelector::CoverageInfo = nullptr

◆ CurMBB

MachineBasicBlock* llvm::InstructionSelector::CurMBB = nullptr

◆ KnownBits

GISelKnownBits* llvm::InstructionSelector::KnownBits = nullptr

Definition at line 459 of file InstructionSelector.h.

◆ MF

MachineFunction* llvm::InstructionSelector::MF = nullptr

◆ PSI

ProfileSummaryInfo* llvm::InstructionSelector::PSI = nullptr

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