Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
LegalizerHelper.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "legalizer"
#define RTLIBCASE_INT(LibcallPrefix)
#define RTLIBCASE(LibcallPrefix)
#define LCALLS(A, B)
#define LCALL5(A)
#define RTLIBCASE_CMP(LibcallPrefix, ICmpPred)

Functions

static std::pair< int, int > getNarrowTypeBreakDown (LLT OrigTy, LLT NarrowTy, LLT &LeftoverTy)
 Try to break down OrigTy into NarrowTy sized pieces.
static TypegetFloatTypeForLLT (LLVMContext &Ctx, LLT Ty)
static void getUnmergeResults (SmallVectorImpl< Register > &Regs, const MachineInstr &MI)
 Append the result registers of G_UNMERGE_VALUES MI to Regs.
static RTLIB::Libcall getRTLibDesc (unsigned Opcode, unsigned Size)
static bool isLibCallInTailPosition (const CallLowering::ArgInfo &Result, MachineInstr &MI, const TargetInstrInfo &TII, MachineRegisterInfo &MRI)
 True if an instruction is in tail position in its caller.
static LegalizerHelper::LegalizeResult simpleLibcall (MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size, Type *OpType, LostDebugLocObserver &LocObserver)
static RTLIB::Libcall getOutlineAtomicLibcall (MachineInstr &MI)
static LegalizerHelper::LegalizeResult createAtomicLibcall (MachineIRBuilder &MIRBuilder, MachineInstr &MI)
static RTLIB::Libcall getConvRTLibDesc (unsigned Opcode, Type *ToType, Type *FromType)
static LegalizerHelper::LegalizeResult conversionLibcall (MachineInstr &MI, MachineIRBuilder &MIRBuilder, Type *ToType, Type *FromType, LostDebugLocObserver &LocObserver, const TargetLowering &TLI, bool IsSigned=false)
static RTLIB::Libcall getStateLibraryFunctionFor (MachineInstr &MI, const TargetLowering &TLI)
static std::pair< RTLIB::Libcall, CmpInst::PredicategetFCMPLibcallDesc (const CmpInst::Predicate Pred, unsigned Size)
 Returns the corresponding libcall for the given Pred and the ICMP predicate that should be generated to compare with #0 after the libcall.
static void getUnmergePieces (SmallVectorImpl< Register > &Pieces, MachineIRBuilder &B, Register Src, LLT Ty)
static void emitLoadFromConstantPool (Register DstReg, const Constant *ConstVal, MachineIRBuilder &MIRBuilder)
static Register getBitcastWiderVectorElementOffset (MachineIRBuilder &B, Register Idx, unsigned NewEltSize, unsigned OldEltSize)
 Figure out the bit offset into a register when coercing a vector index for the wide element type.
static Register buildBitFieldInsert (MachineIRBuilder &B, Register TargetReg, Register InsertReg, Register OffsetBits)
 Emit code to insert InsertReg into TargetRet at OffsetBits in TargetReg, while preserving other bits in TargetReg.
static Register clampVectorIndex (MachineIRBuilder &B, Register IdxReg, LLT VecTy)
static bool hasSameNumEltsOnAllVectorOperands (GenericMachineInstr &MI, MachineRegisterInfo &MRI, std::initializer_list< unsigned > NonVecOpIndices)
 Check that all vector operands have same number of elements.
static void makeDstOps (SmallVectorImpl< DstOp > &DstOps, LLT Ty, unsigned NumElts)
 Fill DstOps with DstOps that have same number of elements combined as the Ty.
static void broadcastSrcOp (SmallVectorImpl< SrcOp > &Ops, unsigned N, MachineOperand &Op)
 Operand Op is used on N sub-instructions.
static bool isNonZeroModBitWidthOrUndef (const MachineRegisterInfo &MRI, Register Reg, unsigned BW)
static LegalizerHelper::LegalizeResult loweri64tof16ITOFP (MachineInstr &MI, Register Dst, LLT DstTy, Register Src, LLT SrcTy, MachineIRBuilder &MIRBuilder)
 i64->fp16 itofp can be lowered to i64->f64,f64->f32,f32->f16.
static CmpInst::Predicate minMaxToCompare (unsigned Opc)
static MachineInstrBuilder SwapN (unsigned N, DstOp Dst, MachineIRBuilder &B, MachineInstrBuilder Src, const APInt &Mask)
static bool shouldLowerMemFuncForSize (const MachineFunction &MF)
static bool findGISelOptimalMemOpLowering (std::vector< LLT > &MemOps, unsigned Limit, const MemOp &Op, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes, const TargetLowering &TLI)
static Register getMemsetValue (Register Val, LLT Ty, MachineIRBuilder &MIB)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "legalizer"

Definition at line 43 of file LegalizerHelper.cpp.

◆ LCALL5

#define LCALL5 ( A)
Value:
LCALLS(A, 1), LCALLS(A, 2), LCALLS(A, 4), LCALLS(A, 8), LCALLS(A, 16)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LCALLS(A, B)

Referenced by getOutlineAtomicLibcall().

◆ LCALLS

#define LCALLS ( A,
B )
Value:
{A##B##_RELAX, A##B##_ACQ, A##B##_REL, A##B##_ACQ_REL}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

◆ RTLIBCASE

#define RTLIBCASE ( LibcallPrefix)
Value:
do { \
switch (Size) { \
case 32: \
return RTLIB::LibcallPrefix##32; \
case 64: \
return RTLIB::LibcallPrefix##64; \
case 80: \
return RTLIB::LibcallPrefix##80; \
case 128: \
return RTLIB::LibcallPrefix##128; \
default: \
llvm_unreachable("unexpected size"); \
} \
} while (0)

Referenced by getRTLibDesc().

◆ RTLIBCASE_CMP

#define RTLIBCASE_CMP ( LibcallPrefix,
ICmpPred )
Value:
do { \
switch (Size) { \
case 32: \
return {RTLIB::LibcallPrefix##32, ICmpPred}; \
case 64: \
return {RTLIB::LibcallPrefix##64, ICmpPred}; \
case 128: \
return {RTLIB::LibcallPrefix##128, ICmpPred}; \
default: \
llvm_unreachable("unexpected size"); \
} \
} while (0)

Referenced by getFCMPLibcallDesc().

◆ RTLIBCASE_INT

#define RTLIBCASE_INT ( LibcallPrefix)
Value:
do { \
switch (Size) { \
case 32: \
return RTLIB::LibcallPrefix##32; \
case 64: \
return RTLIB::LibcallPrefix##64; \
case 128: \
return RTLIB::LibcallPrefix##128; \
default: \
llvm_unreachable("unexpected size"); \
} \
} while (0)

Referenced by getRTLibDesc().

Function Documentation

◆ broadcastSrcOp()

void broadcastSrcOp ( SmallVectorImpl< SrcOp > & Ops,
unsigned N,
MachineOperand & Op )
static

Operand Op is used on N sub-instructions.

Fill Ops with N SrcOps made from Op depending on operand type.

Definition at line 4960 of file LegalizerHelper.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, llvm_unreachable, and N.

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

◆ buildBitFieldInsert()

Register buildBitFieldInsert ( MachineIRBuilder & B,
Register TargetReg,
Register InsertReg,
Register OffsetBits )
static

Emit code to insert InsertReg into TargetRet at OffsetBits in TargetReg, while preserving other bits in TargetReg.

(InsertReg << Offset) | (TargetReg & ~(-1 >> InsertReg.size()) << Offset)

Definition at line 3752 of file LegalizerHelper.cpp.

References B(), llvm::APInt::getLowBitsSet(), and llvm::LLT::getSizeInBits().

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

◆ clampVectorIndex()

◆ conversionLibcall()

◆ createAtomicLibcall()

◆ emitLoadFromConstantPool()

◆ findGISelOptimalMemOpLowering()

◆ getBitcastWiderVectorElementOffset()

Register getBitcastWiderVectorElementOffset ( MachineIRBuilder & B,
Register Idx,
unsigned NewEltSize,
unsigned OldEltSize )
static

Figure out the bit offset into a register when coercing a vector index for the wide element type.

This is only for the case when promoting vector to one with larger elements. offset_idx = G_AND idx, ~(-1 << Log2(DstEltSize / SrcEltSize)) offset_bits = G_SHL offset_idx, Log2(SrcEltSize)

Definition at line 3624 of file LegalizerHelper.cpp.

References B(), llvm::APInt::getAllOnes(), llvm::LLT::getSizeInBits(), and llvm::Log2_32().

Referenced by llvm::LegalizerHelper::bitcastExtractVectorElt(), and llvm::LegalizerHelper::bitcastInsertVectorElt().

◆ getConvRTLibDesc()

◆ getFCMPLibcallDesc()

std::pair< RTLIB::Libcall, CmpInst::Predicate > getFCMPLibcallDesc ( const CmpInst::Predicate Pred,
unsigned Size )
static

◆ getFloatTypeForLLT()

◆ getMemsetValue()

◆ getNarrowTypeBreakDown()

std::pair< int, int > getNarrowTypeBreakDown ( LLT OrigTy,
LLT NarrowTy,
LLT & LeftoverTy )
static

Try to break down OrigTy into NarrowTy sized pieces.

Returns the number of NarrowTy elements needed to reconstruct OrigTy, with any leftover piece as type LeftoverTy

Returns -1 in the first element of the pair if the breakdown is not satisfiable.

Definition at line 57 of file LegalizerHelper.cpp.

References assert(), llvm::LLT::getElementType(), llvm::ElementCount::getFixed(), llvm::LLT::getScalarSizeInBits(), llvm::LLT::getSizeInBits(), llvm::LLT::isValid(), llvm::LLT::isVector(), llvm::LLT::scalar(), llvm::LLT::scalarOrVector(), and Size.

Referenced by makeDstOps(), and llvm::LegalizerHelper::reduceLoadStoreWidth().

◆ getOutlineAtomicLibcall()

RTLIB::Libcall getOutlineAtomicLibcall ( MachineInstr & MI)
static

◆ getRTLibDesc()

RTLIB::Libcall getRTLibDesc ( unsigned Opcode,
unsigned Size )
static

Definition at line 382 of file LegalizerHelper.cpp.

References llvm_unreachable, RTLIBCASE, RTLIBCASE_INT, and Size.

Referenced by llvm::LegalizerHelper::libcall(), and simpleLibcall().

◆ getStateLibraryFunctionFor()

RTLIB::Libcall getStateLibraryFunctionFor ( MachineInstr & MI,
const TargetLowering & TLI )
static

Definition at line 964 of file LegalizerHelper.cpp.

References llvm_unreachable, and MI.

◆ getUnmergePieces()

void getUnmergePieces ( SmallVectorImpl< Register > & Pieces,
MachineIRBuilder & B,
Register Src,
LLT Ty )
static

◆ getUnmergeResults()

void getUnmergeResults ( SmallVectorImpl< Register > & Regs,
const MachineInstr & MI )
static

Append the result registers of G_UNMERGE_VALUES MI to Regs.

Definition at line 225 of file LegalizerHelper.cpp.

References assert(), I, MI, llvm::SmallVectorImpl< T >::resize(), and llvm::SmallVectorTemplateCommon< T, typename >::size().

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

◆ hasSameNumEltsOnAllVectorOperands()

bool hasSameNumEltsOnAllVectorOperands ( GenericMachineInstr & MI,
MachineRegisterInfo & MRI,
std::initializer_list< unsigned > NonVecOpIndices )
static

Check that all vector operands have same number of elements.

Other operands should be listed in NonVecOp.

Definition at line 4899 of file LegalizerHelper.cpp.

References llvm::LLT::getNumElements(), llvm::is_contained(), llvm::LLT::isVector(), MI, MRI, and OpIdx.

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

◆ isLibCallInTailPosition()

bool isLibCallInTailPosition ( const CallLowering::ArgInfo & Result,
MachineInstr & MI,
const TargetInstrInfo & TII,
MachineRegisterInfo & MRI )
static

True if an instruction is in tail position in its caller.

Intended for legalizing libcalls as tail calls when possible.

Definition at line 518 of file LegalizerHelper.cpp.

References F, llvm::Register::isPhysical(), llvm::Register::isVirtual(), MBB, MI, MRI, llvm::Next, llvm::next_nodbg(), and TII.

Referenced by llvm::createLibcall(), and llvm::createMemLibcall().

◆ isNonZeroModBitWidthOrUndef()

◆ loweri64tof16ITOFP()

LegalizerHelper::LegalizeResult loweri64tof16ITOFP ( MachineInstr & MI,
Register Dst,
LLT DstTy,
Register Src,
LLT SrcTy,
MachineIRBuilder & MIRBuilder )
static

i64->fp16 itofp can be lowered to i64->f64,f64->f32,f32->f16.

We cannot convert fpround f64->f16 without double-rounding, so we manually perform the lowering here where we know it is valid.

Definition at line 8119 of file LegalizerHelper.cpp.

References llvm::MachineIRBuilder::buildFPTrunc(), llvm::MachineIRBuilder::buildSITOFP(), llvm::MachineIRBuilder::buildUITOFP(), llvm::LLT::changeElementSize(), llvm::LegalizerHelper::Legalized, llvm::M1(), and MI.

Referenced by llvm::LegalizerHelper::lowerSITOFP(), and llvm::LegalizerHelper::lowerUITOFP().

◆ makeDstOps()

void makeDstOps ( SmallVectorImpl< DstOp > & DstOps,
LLT Ty,
unsigned NumElts )
static

Fill DstOps with DstOps that have same number of elements combined as the Ty.

These DstOps have either scalar type when NumElts = 1 or are vectors with NumElts elements. When Ty.getNumElements() is not multiple of NumElts last DstOp (leftover) has fewer then NumElts elements.

Definition at line 4937 of file LegalizerHelper.cpp.

References assert(), llvm::LLT::fixed_vector(), llvm::LLT::getElementType(), getNarrowTypeBreakDown(), llvm::LLT::isValid(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by llvm::LegalizerHelper::fewerElementsVectorMultiEltType(), and llvm::LegalizerHelper::fewerElementsVectorPhi().

◆ minMaxToCompare()

◆ shouldLowerMemFuncForSize()

◆ simpleLibcall()

LegalizerHelper::LegalizeResult simpleLibcall ( MachineInstr & MI,
MachineIRBuilder & MIRBuilder,
unsigned Size,
Type * OpType,
LostDebugLocObserver & LocObserver )
static

◆ SwapN()

Definition at line 9563 of file LegalizerHelper.cpp.

References B(), LHS, N, and RHS.

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