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;
472 bool IsScalable)
const {
509 return HasMultipleConditionRegisters;
551 unsigned DefinedValues)
const {
552 return DefinedValues < 3;
609 return BypassSlowDivWidths;
650 const Value *)
const {
689 unsigned AddrSpace)
const {
843 unsigned KeptBits)
const {
857 unsigned OldShiftOpcode,
unsigned NewShiftOpcode,
865 if (OldShiftOpcode ==
ISD::SHL &&
CC->isOne())
869 if (XC && NewShiftOpcode ==
ISD::SHL && XC->isOne())
910 EVT VT,
unsigned ShiftOpc,
bool MayTransformRotate,
911 const APInt &ShiftOrRotateAmt,
912 const std::optional<APInt> &AndMask)
const {
952 unsigned &
Cost)
const {
961 Type *VectorTy,
unsigned ElemSizeInBits,
unsigned &
Index)
const {
1006 return BooleanVectorContents;
1007 return isFloat ? BooleanFloatContents : BooleanContents;
1030 return SchedPreferenceInfo;
1045 assert(RC &&
"This value type is not natively supported!");
1053 const Value *)
const {
1072 return RepRegClassCostForVT[VT.
SimpleTy];
1084 unsigned ExpansionFactor)
const {
1085 if (ExpansionFactor == 1)
1106 std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions),
1111 return ValueTypeActions[VT.
SimpleTy];
1115 ValueTypeActions[VT.
SimpleTy] = Action;
1120 return ValueTypeActions;
1188 EVT &IntermediateVT,
1189 unsigned &NumIntermediates,
1190 MVT &RegisterVT)
const;
1197 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1236 bool ForCodeSize =
false)
const {
1273 if (
Op >= std::size(OpActions[0]))
1284 unsigned Scale)
const {
1293 unsigned Scale)
const {
1295 if (Action !=
Legal)
1316 return Supported ? Action :
Expand;
1325#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1326 case ISD::STRICT_##DAGN: EqOpc = ISD::DAGN; break;
1327#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1328 case ISD::STRICT_##DAGN: EqOpc = ISD::SETCC; break;
1329#include "llvm/IR/ConstrainedOps.def"
1340 bool LegalOnly =
false)
const {
1354 bool LegalOnly =
false)
const {
1368 bool LegalOnly =
false)
const {
1410 EVT ConditionVT)
const;
1435 return (NumDests == 1 && NumCmps >= 3) || (NumDests == 2 && NumCmps >= 5) ||
1436 (NumDests == 3 && NumCmps >= 6);
1462 unsigned Shift = 4 * ExtType;
1463 return (
LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf);
1486 unsigned Shift = 4 * ExtType;
1488 (
LegalizeAction)((AtomicLoadExtActions[ValI][MemI] >> Shift) & 0xf);
1490 "Unsupported atomic load extension action.");
1508 "Table isn't big enough!");
1509 return TruncStoreActions[ValI][MemI];
1527 bool LegalOnly)
const {
1538 return getIndexedModeAction(IdxMode, VT, IMAB_Load);
1552 return getIndexedModeAction(IdxMode, VT, IMAB_Store);
1566 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad);
1580 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedStore);
1607 if (Scale != ElemSize && Scale != 1)
1617 assert((
unsigned)
CC < std::size(CondCodeActions) &&
1618 ((
unsigned)VT.
SimpleTy >> 3) < std::size(CondCodeActions[0]) &&
1619 "Table isn't big enough!");
1624 assert(Action !=
Promote &&
"Can't promote condition code!");
1645 "This operation isn't promoted!");
1648 std::map<std::pair<unsigned, MVT::SimpleValueType>,
1650 PromoteToType.find(std::make_pair(
Op, VT.
SimpleTy));
1651 if (PTTI != PromoteToType.end())
return PTTI->second;
1654 "Cannot autopromote this type, add it with AddPromotedToType.");
1662 "Didn't find type to promote to!");
1669 bool AllowUnknown =
false)
const {
1678 bool AllowUnknown =
false)
const {
1680 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1683 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1684 Type *EltTy = VTy->getElementType();
1686 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1691 VTy->getElementCount());
1698 bool AllowUnknown =
false)
const {
1700 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1703 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1704 Type *EltTy = VTy->getElementType();
1705 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1710 VTy->getElementCount());
1719 bool AllowUnknown =
false)
const {
1730 return RegisterTypeForVT[VT.
SimpleTy];
1740 unsigned NumIntermediates;
1742 NumIntermediates, RegisterVT);
1764 std::optional<MVT> RegisterVT = std::nullopt)
const {
1767 std::size(NumRegistersForVT));
1773 unsigned NumIntermediates;
1779 return (
BitWidth + RegWidth - 1) / RegWidth;
1805 return DL.getABITypeAlign(ArgTy);
1819 if (NewVT.
isVector() && !Load->hasOneUse())
1840 return DL.isBigEndian() || VT == MVT::ppcf128;
1846 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
1847 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
1921 unsigned * =
nullptr)
const {
1929 unsigned * =
nullptr)
const {
1939 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1941 unsigned *
Fast =
nullptr)
const;
1950 unsigned *
Fast =
nullptr)
const;
1958 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1960 unsigned *
Fast =
nullptr)
const;
1968 unsigned *
Fast =
nullptr)
const;
1973 unsigned *
Fast =
nullptr)
const;
2016 return StackPointerRegisterToSaveRestore;
2039 return MinStackArgumentAlignment;
2137 return MaxAtomicSizeInBitsSupported;
2143 return MaxDivRemBitWidthSupported;
2149 return MaxLargeFPConvertBitWidthSupported;
2203 llvm_unreachable(
"Masked atomicrmw expansion unimplemented on this target");
2211 "Generic atomicrmw expansion unimplemented on this target");
2216 llvm_unreachable(
"Generic cmpxchg expansion unimplemented on this target");
2224 "Bit test atomicrmw expansion unimplemented on this target");
2232 "Compare arith atomicrmw expansion unimplemented on this target");
2328 if (SI->getValueOperand()->getType()->isFloatingPointTy())
2452 bool IsSigned)
const {
2476 BooleanContents = Ty;
2477 BooleanFloatContents = Ty;
2483 BooleanContents = IntTy;
2484 BooleanFloatContents = FloatTy;
2490 BooleanVectorContents = Ty;
2495 SchedPreferenceInfo = Pref;
2508 StackPointerRegisterToSaveRestore = R;
2517 HasMultipleConditionRegisters = hasManyRegs;
2525 HasExtractBitsInsn = hasExtractInsn;
2535 BypassSlowDivWidths[SlowBitWidth] = FastBitWidth;
2548 virtual std::pair<const TargetRegisterClass *, uint8_t>
2559 assert(
Op < std::size(OpActions[0]) &&
"Table isn't big enough!");
2578 MemVT.
isValid() &&
"Table isn't big enough!");
2579 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2580 unsigned Shift = 4 * ExtType;
2586 for (
auto ExtType : ExtTypes)
2591 for (
auto MemVT : MemVTs)
2600 MemVT.
isValid() &&
"Table isn't big enough!");
2601 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2602 unsigned Shift = 4 * ExtType;
2610 for (
auto ExtType : ExtTypes)
2615 for (
auto MemVT : MemVTs)
2633 for (
auto IdxMode : IdxModes)
2634 setIndexedModeAction(IdxMode, VT, IMAB_Load, Action);
2650 for (
auto IdxMode : IdxModes)
2651 setIndexedModeAction(IdxMode, VT, IMAB_Store, Action);
2667 setIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad, Action);
2677 setIndexedModeAction(IdxMode, VT, IMAB_MaskedStore, Action);
2684 for (
auto CC : CCs) {
2686 "Table isn't big enough!");
2687 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2718 for (
auto Op : Ops) {
2728 for (
auto NT : NTs) {
2729 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
2730 TargetDAGCombineArray[NT >> 3] |= 1 << (NT & 7);
2736 MinFunctionAlignment = Alignment;
2742 PrefFunctionAlignment = Alignment;
2750 MaxBytesForAlignment = MaxBytes;
2755 MinStackArgumentAlignment = Alignment;
2763 MaxAtomicSizeInBitsSupported = SizeInBits;
2769 MaxDivRemBitWidthSupported = SizeInBits;
2775 MaxLargeFPConvertBitWidthSupported = SizeInBits;
2780 MinCmpXchgSizeInBits = SizeInBits;
2785 SupportsUnalignedAtomics = UnalignedSupported;
2832 Type *Ty,
unsigned AddrSpace,
2843 int64_t MaxOffset)
const {
2888 return (
From->isIntegerTy() ||
From->isFloatingPointTy()) &&
2932 default:
return false;
3005 switch (
I->getOpcode()) {
3006 case Instruction::FPExt:
3011 case Instruction::ZExt:
3012 if (
isZExtFree(
I->getOperand(0)->getType(),
I->getType()))
3015 case Instruction::SExt:
3042 if (isa<ZExtInst>(Ext))
3045 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");
3267 assert((
MI.getOpcode() == TargetOpcode::G_FADD ||
3268 MI.getOpcode() == TargetOpcode::G_FSUB ||
3269 MI.getOpcode() == TargetOpcode::G_FMUL) &&
3270 "unexpected node in FMAD forming combine");
3291 "unexpected node in FMAD forming combine");
3332 unsigned Index)
const {
3355 bool MathUsed)
const {
3391 const APInt &AndMask)
const {
3448 CmpLibcallCCs[Call] =
CC;
3456 return CmpLibcallCCs[Call];
3491 bool HasMultipleConditionRegisters;
3497 bool HasExtractBitsInsn;
3503 DenseMap <unsigned int, unsigned int> BypassSlowDivWidths;
3508 bool JumpIsExpensive;
3527 Align MinStackArgumentAlignment;
3531 Align MinFunctionAlignment;
3535 Align PrefFunctionAlignment;
3538 Align PrefLoopAlignment;
3540 unsigned MaxBytesForAlignment;
3544 unsigned MaxAtomicSizeInBitsSupported;
3548 unsigned MaxDivRemBitWidthSupported;
3552 unsigned MaxLargeFPConvertBitWidthSupported;
3556 unsigned MinCmpXchgSizeInBits;
3559 bool SupportsUnalignedAtomics;
3563 Register StackPointerRegisterToSaveRestore;
3628 ValueTypeActionImpl ValueTypeActions;
3647 RTLIB::RuntimeLibcallsInfo Libcalls;
3655 enum IndexedModeActionsBits {
3658 IMAB_MaskedStore = 8,
3659 IMAB_MaskedLoad = 12
3662 void setIndexedModeAction(
unsigned IdxMode, MVT VT,
unsigned Shift,
3665 (
unsigned)Action < 0xf &&
"Table isn't big enough!");
3666 unsigned Ty = (
unsigned)VT.SimpleTy;
3667 IndexedModeActions[Ty][IdxMode] &= ~(0xf << Shift);
3668 IndexedModeActions[Ty][IdxMode] |= ((
uint16_t)Action) << Shift;
3672 unsigned Shift)
const {
3674 "Table isn't big enough!");
3675 unsigned Ty = (
unsigned)VT.SimpleTy;
3676 return (
LegalizeAction)((IndexedModeActions[Ty][IdxMode] >> Shift) & 0xf);
3817 return MRI.hasOneNonDBGUse(N0);
3891 unsigned OpNo)
const {
3907 bool IsSignaling =
false)
const;
3927 MakeLibCallOptions CallOptions,
3935 const uint32_t *CallerPreservedMask,
3974 const MemOp &
Op,
unsigned DstAS,
unsigned SrcAS,
3982 const APInt &DemandedElts,
3983 TargetLoweringOpt &TLO)
const;
3987 TargetLoweringOpt &TLO)
const;
3994 const APInt &DemandedElts,
4005 TargetLoweringOpt &TLO)
const;
4022 TargetLoweringOpt &TLO,
unsigned Depth = 0,
4023 bool AssumeSingleUse =
false)
const;
4028 KnownBits &Known, TargetLoweringOpt &TLO,
4030 bool AssumeSingleUse =
false)
const;
4035 DAGCombinerInfo &DCI)
const;
4040 const APInt &DemandedElts,
4041 DAGCombinerInfo &DCI)
const;
4047 const APInt &DemandedElts,
4049 unsigned Depth = 0)
const;
4055 unsigned Depth = 0)
const;
4060 const APInt &DemandedElts,
4062 unsigned Depth = 0)
const;
4080 TargetLoweringOpt &TLO,
unsigned Depth = 0,
4081 bool AssumeSingleUse =
false)
const;
4086 DAGCombinerInfo &DCI)
const;
4102 const APInt &DemandedElts,
4104 unsigned Depth = 0)
const;
4112 const APInt &DemandedElts,
4114 unsigned Depth = 0)
const;
4123 unsigned Depth = 0)
const;
4137 const APInt &DemandedElts,
4139 unsigned Depth = 0)
const;
4147 const APInt &DemandedElts,
4149 unsigned Depth = 0)
const;
4158 APInt &KnownZero, TargetLoweringOpt &TLO,
unsigned Depth = 0)
const;
4167 const APInt &DemandedElts,
4169 TargetLoweringOpt &TLO,
4170 unsigned Depth = 0)
const;
4192 bool ConsiderFlags,
unsigned Depth)
const;
4212 unsigned Depth = 0)
const;
4219 unsigned Depth = 0)
const;
4269 bool foldBooleans, DAGCombinerInfo &DCI,
4270 const SDLoc &dl)
const;
4305 SDValue ShiftLHS =
N->getOperand(0);
4323 bool IsAfterLegal)
const {