22#ifndef LLVM_CODEGEN_TARGETLOWERING_H
23#define LLVM_CODEGEN_TARGETLOWERING_H
73class FunctionLoweringInfo;
81class MachineBasicBlock;
84class MachineJumpTableInfo;
86class MachineRegisterInfo;
90class ProfileSummaryInfo;
91class TargetLibraryInfo;
93class TargetRegisterClass;
94class TargetRegisterInfo;
95class TargetTransformInfo;
119 bool DstAlignCanChange;
134 Align SrcAlign,
bool IsVolatile,
135 bool MemcpyStrSrc =
false) {
138 Op.DstAlignCanChange = DstAlignCanChange;
139 Op.DstAlign = DstAlign;
140 Op.AllowOverlap = !IsVolatile;
142 Op.ZeroMemset =
false;
143 Op.MemcpyStrSrc = MemcpyStrSrc;
144 Op.SrcAlign = SrcAlign;
149 bool IsZeroMemset,
bool IsVolatile) {
152 Op.DstAlignCanChange = DstAlignCanChange;
153 Op.DstAlign = DstAlign;
154 Op.AllowOverlap = !IsVolatile;
156 Op.ZeroMemset = IsZeroMemset;
157 Op.MemcpyStrSrc =
false;
163 assert(!DstAlignCanChange);
171 return isMemcpy() && !DstAlignCanChange;
463 bool IsScalable)
const {
493 return HasMultipleConditionRegisters;
535 unsigned DefinedValues)
const {
536 return DefinedValues < 3;
593 return BypassSlowDivWidths;
634 const Value *)
const {
673 unsigned AddrSpace)
const {
827 unsigned KeptBits)
const {
841 unsigned OldShiftOpcode,
unsigned NewShiftOpcode,
849 if (OldShiftOpcode ==
ISD::SHL &&
CC->isOne())
853 if (XC && NewShiftOpcode ==
ISD::SHL && XC->isOne())
894 EVT VT,
unsigned ShiftOpc,
bool MayTransformRotate,
895 const APInt &ShiftOrRotateAmt,
896 const std::optional<APInt> &AndMask)
const {
936 unsigned &
Cost)
const {
945 Type *VectorTy,
unsigned ElemSizeInBits,
unsigned &
Index)
const {
990 return BooleanVectorContents;
991 return isFloat ? BooleanFloatContents : BooleanContents;
1014 return SchedPreferenceInfo;
1029 assert(RC &&
"This value type is not natively supported!");
1037 const Value *)
const {
1056 return RepRegClassCostForVT[VT.
SimpleTy];
1068 unsigned ExpansionFactor)
const {
1069 if (ExpansionFactor == 1)
1090 std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions),
1095 return ValueTypeActions[VT.
SimpleTy];
1099 ValueTypeActions[VT.
SimpleTy] = Action;
1104 return ValueTypeActions;
1172 EVT &IntermediateVT,
1173 unsigned &NumIntermediates,
1174 MVT &RegisterVT)
const;
1181 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1220 bool ForCodeSize =
false)
const {
1257 if (
Op >= std::size(OpActions[0]))
1268 unsigned Scale)
const {
1277 unsigned Scale)
const {
1279 if (Action !=
Legal)
1300 return Supported ? Action :
Expand;
1309#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1310 case ISD::STRICT_##DAGN: EqOpc = ISD::DAGN; break;
1311#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1312 case ISD::STRICT_##DAGN: EqOpc = ISD::SETCC; break;
1313#include "llvm/IR/ConstrainedOps.def"
1324 bool LegalOnly =
false)
const {
1338 bool LegalOnly =
false)
const {
1352 bool LegalOnly =
false)
const {
1394 EVT ConditionVT)
const;
1419 return (NumDests == 1 && NumCmps >= 3) || (NumDests == 2 && NumCmps >= 5) ||
1420 (NumDests == 3 && NumCmps >= 6);
1446 unsigned Shift = 4 * ExtType;
1447 return (
LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf);
1470 unsigned Shift = 4 * ExtType;
1472 (
LegalizeAction)((AtomicLoadExtActions[ValI][MemI] >> Shift) & 0xf);
1474 "Unsupported atomic load extension action.");
1492 "Table isn't big enough!");
1493 return TruncStoreActions[ValI][MemI];
1511 bool LegalOnly)
const {
1522 return getIndexedModeAction(IdxMode, VT, IMAB_Load);
1536 return getIndexedModeAction(IdxMode, VT, IMAB_Store);
1550 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad);
1564 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedStore);
1591 if (Scale != ElemSize && Scale != 1)
1601 assert((
unsigned)
CC < std::size(CondCodeActions) &&
1602 ((
unsigned)VT.
SimpleTy >> 3) < std::size(CondCodeActions[0]) &&
1603 "Table isn't big enough!");
1608 assert(Action !=
Promote &&
"Can't promote condition code!");
1628 "This operation isn't promoted!");
1631 std::map<std::pair<unsigned, MVT::SimpleValueType>,
1633 PromoteToType.find(std::make_pair(
Op, VT.
SimpleTy));
1634 if (PTTI != PromoteToType.end())
return PTTI->second;
1637 "Cannot autopromote this type, add it with AddPromotedToType.");
1645 "Didn't find type to promote to!");
1652 bool AllowUnknown =
false)
const {
1661 bool AllowUnknown =
false)
const {
1663 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1666 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1667 Type *EltTy = VTy->getElementType();
1669 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1674 VTy->getElementCount());
1681 bool AllowUnknown =
false)
const {
1683 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1686 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1687 Type *EltTy = VTy->getElementType();
1688 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1693 VTy->getElementCount());
1702 bool AllowUnknown =
false)
const {
1714 return RegisterTypeForVT[VT.
SimpleTy];
1724 unsigned NumIntermediates;
1726 NumIntermediates, RegisterVT);
1748 std::optional<MVT> RegisterVT = std::nullopt)
const {
1751 std::size(NumRegistersForVT));
1757 unsigned NumIntermediates;
1763 return (
BitWidth + RegWidth - 1) / RegWidth;
1789 return DL.getABITypeAlign(ArgTy);
1803 if (NewVT.
isVector() && !Load->hasOneUse())
1824 return DL.isBigEndian() || VT == MVT::ppcf128;
1830 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
1831 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
1905 unsigned * =
nullptr)
const {
1913 unsigned * =
nullptr)
const {
1923 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1925 unsigned *
Fast =
nullptr)
const;
1934 unsigned *
Fast =
nullptr)
const;
1942 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1944 unsigned *
Fast =
nullptr)
const;
1952 unsigned *
Fast =
nullptr)
const;
1957 unsigned *
Fast =
nullptr)
const;
2000 return StackPointerRegisterToSaveRestore;
2023 return MinStackArgumentAlignment;
2121 return MaxAtomicSizeInBitsSupported;
2127 return MaxDivRemBitWidthSupported;
2133 return MaxLargeFPConvertBitWidthSupported;
2187 llvm_unreachable(
"Masked atomicrmw expansion unimplemented on this target");
2195 "Generic atomicrmw expansion unimplemented on this target");
2203 "Bit test atomicrmw expansion unimplemented on this target");
2211 "Compare arith atomicrmw expansion unimplemented on this target");
2307 if (SI->getValueOperand()->getType()->isFloatingPointTy())
2431 bool IsSigned)
const {
2455 BooleanContents = Ty;
2456 BooleanFloatContents = Ty;
2462 BooleanContents = IntTy;
2463 BooleanFloatContents = FloatTy;
2469 BooleanVectorContents = Ty;
2474 SchedPreferenceInfo = Pref;
2487 StackPointerRegisterToSaveRestore = R;
2496 HasMultipleConditionRegisters = hasManyRegs;
2504 HasExtractBitsInsn = hasExtractInsn;
2514 BypassSlowDivWidths[SlowBitWidth] = FastBitWidth;
2527 virtual std::pair<const TargetRegisterClass *, uint8_t>
2538 assert(
Op < std::size(OpActions[0]) &&
"Table isn't big enough!");
2557 MemVT.
isValid() &&
"Table isn't big enough!");
2558 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2559 unsigned Shift = 4 * ExtType;
2565 for (
auto ExtType : ExtTypes)
2570 for (
auto MemVT : MemVTs)
2579 MemVT.
isValid() &&
"Table isn't big enough!");
2580 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2581 unsigned Shift = 4 * ExtType;
2589 for (
auto ExtType : ExtTypes)
2594 for (
auto MemVT : MemVTs)
2612 for (
auto IdxMode : IdxModes)
2613 setIndexedModeAction(IdxMode, VT, IMAB_Load, Action);
2629 for (
auto IdxMode : IdxModes)
2630 setIndexedModeAction(IdxMode, VT, IMAB_Store, Action);
2646 setIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad, Action);
2656 setIndexedModeAction(IdxMode, VT, IMAB_MaskedStore, Action);
2663 for (
auto CC : CCs) {
2665 "Table isn't big enough!");
2666 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2697 for (
auto Op : Ops) {
2707 for (
auto NT : NTs) {
2708 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
2709 TargetDAGCombineArray[NT >> 3] |= 1 << (NT & 7);
2715 MinFunctionAlignment = Alignment;
2721 PrefFunctionAlignment = Alignment;
2729 MaxBytesForAlignment = MaxBytes;
2734 MinStackArgumentAlignment = Alignment;
2742 MaxAtomicSizeInBitsSupported = SizeInBits;
2748 MaxDivRemBitWidthSupported = SizeInBits;
2754 MaxLargeFPConvertBitWidthSupported = SizeInBits;
2759 MinCmpXchgSizeInBits = SizeInBits;
2764 SupportsUnalignedAtomics = UnalignedSupported;
2811 Type *Ty,
unsigned AddrSpace,
2822 int64_t MaxOffset)
const {
2876 return (
From->isIntegerTy() ||
From->isFloatingPointTy()) &&
2920 default:
return false;
2994 switch (
I->getOpcode()) {
2995 case Instruction::FPExt:
3000 case Instruction::ZExt:
3001 if (
isZExtFree(
I->getOperand(0)->getType(),
I->getType()))
3004 case Instruction::SExt:
3031 if (isa<ZExtInst>(Ext))
3034 assert(isa<SExtInst>(Ext) &&
"Unexpected ext type!");
3140 unsigned Factor)
const {
3151 unsigned Factor)
const {
3188 "invalid fpext types");
3196 LLT DestTy,
LLT SrcTy)
const {
3204 EVT DestVT,
EVT SrcVT)
const {
3206 "invalid fpext types");
3264 assert((
MI.getOpcode() == TargetOpcode::G_FADD ||
3265 MI.getOpcode() == TargetOpcode::G_FSUB ||
3266 MI.getOpcode() == TargetOpcode::G_FMUL) &&
3267 "unexpected node in FMAD forming combine");
3288 "unexpected node in FMAD forming combine");
3329 unsigned Index)
const {
3352 bool MathUsed)
const {
3388 const APInt &AndMask)
const {
3445 CmpLibcallCCs[Call] =
CC;
3453 return CmpLibcallCCs[Call];
3488 bool HasMultipleConditionRegisters;
3494 bool HasExtractBitsInsn;
3500 DenseMap <unsigned int, unsigned int> BypassSlowDivWidths;
3505 bool JumpIsExpensive;
3524 Align MinStackArgumentAlignment;
3528 Align MinFunctionAlignment;
3532 Align PrefFunctionAlignment;
3535 Align PrefLoopAlignment;
3537 unsigned MaxBytesForAlignment;
3541 unsigned MaxAtomicSizeInBitsSupported;
3545 unsigned MaxDivRemBitWidthSupported;
3549 unsigned MaxLargeFPConvertBitWidthSupported;
3553 unsigned MinCmpXchgSizeInBits;
3556 bool SupportsUnalignedAtomics;
3560 Register StackPointerRegisterToSaveRestore;
3625 ValueTypeActionImpl ValueTypeActions;
3644 RTLIB::RuntimeLibcallsInfo Libcalls;
3652 enum IndexedModeActionsBits {
3655 IMAB_MaskedStore = 8,
3656 IMAB_MaskedLoad = 12
3659 void setIndexedModeAction(
unsigned IdxMode, MVT VT,
unsigned Shift,
3662 (
unsigned)Action < 0xf &&
"Table isn't big enough!");
3663 unsigned Ty = (
unsigned)VT.SimpleTy;
3664 IndexedModeActions[Ty][IdxMode] &= ~(0xf << Shift);
3665 IndexedModeActions[Ty][IdxMode] |= ((
uint16_t)Action) << Shift;
3669 unsigned Shift)
const {
3671 "Table isn't big enough!");
3672 unsigned Ty = (
unsigned)VT.SimpleTy;
3673 return (
LegalizeAction)((IndexedModeActions[Ty][IdxMode] >> Shift) & 0xf);
3814 return MRI.hasOneNonDBGUse(N0);
3888 unsigned OpNo)
const {
3904 bool IsSignaling =
false)
const;
3924 MakeLibCallOptions CallOptions,
3932 const uint32_t *CallerPreservedMask,
3971 const MemOp &
Op,
unsigned DstAS,
unsigned SrcAS,
3979 const APInt &DemandedElts,
3980 TargetLoweringOpt &TLO)
const;
3984 TargetLoweringOpt &TLO)
const;
3991 const APInt &DemandedElts,
4002 TargetLoweringOpt &TLO)
const;
4019 TargetLoweringOpt &TLO,
unsigned Depth = 0,
4020 bool AssumeSingleUse =
false)
const;
4025 KnownBits &Known, TargetLoweringOpt &TLO,
4027 bool AssumeSingleUse =
false)
const;
4032 DAGCombinerInfo &DCI)
const;
4037 const APInt &DemandedElts,
4038 DAGCombinerInfo &DCI)
const;
4044 const APInt &DemandedElts,
4046 unsigned Depth = 0)
const;
4052 unsigned Depth = 0)
const;
4057 const APInt &DemandedElts,
4059 unsigned Depth = 0)
const;
4077 TargetLoweringOpt &TLO,
unsigned Depth = 0,
4078 bool AssumeSingleUse =
false)
const;
4083 DAGCombinerInfo &DCI)
const;
4099 const APInt &DemandedElts,
4101 unsigned Depth = 0)
const;
4109 const APInt &DemandedElts,
4111 unsigned Depth = 0)
const;
4120 unsigned Depth = 0)
const;
4134 const APInt &DemandedElts,
4136 unsigned Depth = 0)
const;
4144 const APInt &DemandedElts,
4146 unsigned Depth = 0)
const;
4155 APInt &KnownZero, TargetLoweringOpt &TLO,
unsigned Depth = 0)
const;
4164 const APInt &DemandedElts,
4166 TargetLoweringOpt &TLO,
4167 unsigned Depth = 0)
const;
4189 bool ConsiderFlags,
unsigned Depth)
const;
4209 unsigned Depth = 0)
const;
4216 unsigned Depth = 0)
const;
4266 bool foldBooleans, DAGCombinerInfo &DCI,
4267 const SDLoc &dl)
const;
4314 bool IsAfterLegal)
const {