22#ifndef LLVM_CODEGEN_TARGETLOWERING_H
23#define LLVM_CODEGEN_TARGETLOWERING_H
71class FunctionLoweringInfo;
79class MachineBasicBlock;
82class MachineJumpTableInfo;
84class MachineRegisterInfo;
88class ProfileSummaryInfo;
89class TargetLibraryInfo;
91class TargetRegisterClass;
92class TargetRegisterInfo;
93class TargetTransformInfo;
116 bool DstAlignCanChange;
131 Align SrcAlign,
bool IsVolatile,
132 bool MemcpyStrSrc =
false) {
135 Op.DstAlignCanChange = DstAlignCanChange;
136 Op.DstAlign = DstAlign;
137 Op.AllowOverlap = !IsVolatile;
139 Op.ZeroMemset =
false;
140 Op.MemcpyStrSrc = MemcpyStrSrc;
141 Op.SrcAlign = SrcAlign;
146 bool IsZeroMemset,
bool IsVolatile) {
149 Op.DstAlignCanChange = DstAlignCanChange;
150 Op.DstAlign = DstAlign;
151 Op.AllowOverlap = !IsVolatile;
153 Op.ZeroMemset = IsZeroMemset;
154 Op.MemcpyStrSrc =
false;
160 assert(!DstAlignCanChange);
168 return isMemcpy() && !DstAlignCanChange;
408 bool LegalTypes =
true)
const;
464 bool IsScalable)
const {
484 return HasMultipleConditionRegisters;
520 unsigned DefinedValues)
const {
521 return DefinedValues < 3;
578 return BypassSlowDivWidths;
622 unsigned AddrSpace)
const {
776 unsigned KeptBits)
const {
790 unsigned OldShiftOpcode,
unsigned NewShiftOpcode,
798 if (OldShiftOpcode ==
ISD::SHL &&
CC->isOne())
802 if (XC && NewShiftOpcode ==
ISD::SHL && XC->isOne())
867 unsigned &
Cost)
const {
876 Type *VectorTy,
unsigned ElemSizeInBits,
unsigned &
Index)
const {
921 return BooleanVectorContents;
922 return isFloat ? BooleanFloatContents : BooleanContents;
945 return SchedPreferenceInfo;
960 assert(RC &&
"This value type is not natively supported!");
968 const Value *)
const {
987 return RepRegClassCostForVT[VT.
SimpleTy];
999 unsigned ExpansionFactor)
const {
1000 if (ExpansionFactor == 1)
1021 std::fill(std::begin(ValueTypeActions), std::end(ValueTypeActions),
1026 return ValueTypeActions[VT.
SimpleTy];
1030 ValueTypeActions[VT.
SimpleTy] = Action;
1035 return ValueTypeActions;
1103 EVT &IntermediateVT,
1104 unsigned &NumIntermediates,
1105 MVT &RegisterVT)
const;
1112 unsigned &NumIntermediates,
MVT &RegisterVT)
const {
1151 bool ForCodeSize =
false)
const {
1189 if (
Op >= std::size(OpActions[0]))
1198 unsigned Scale)
const {
1207 unsigned Scale)
const {
1209 if (Action !=
Legal)
1230 return Supported ? Action :
Expand;
1239#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1240 case ISD::STRICT_##DAGN: EqOpc = ISD::DAGN; break;
1241#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1242 case ISD::STRICT_##DAGN: EqOpc = ISD::SETCC; break;
1243#include "llvm/IR/ConstrainedOps.def"
1254 bool LegalOnly =
false)
const {
1268 bool LegalOnly =
false)
const {
1282 bool LegalOnly =
false)
const {
1324 EVT ConditionVT)
const;
1349 return (NumDests == 1 && NumCmps >= 3) || (NumDests == 2 && NumCmps >= 5) ||
1350 (NumDests == 3 && NumCmps >= 6);
1376 unsigned Shift = 4 * ExtType;
1377 return (
LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf);
1400 "Table isn't big enough!");
1401 return TruncStoreActions[ValI][MemI];
1419 bool LegalOnly)
const {
1430 return getIndexedModeAction(IdxMode, VT, IMAB_Load);
1444 return getIndexedModeAction(IdxMode, VT, IMAB_Store);
1458 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad);
1472 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedStore);
1499 if (Scale != ElemSize && Scale != 1)
1509 assert((
unsigned)
CC < std::size(CondCodeActions) &&
1510 ((
unsigned)VT.
SimpleTy >> 3) < std::size(CondCodeActions[0]) &&
1511 "Table isn't big enough!");
1516 assert(Action !=
Promote &&
"Can't promote condition code!");
1536 "This operation isn't promoted!");
1539 std::map<std::pair<unsigned, MVT::SimpleValueType>,
1541 PromoteToType.find(std::make_pair(
Op, VT.
SimpleTy));
1542 if (PTTI != PromoteToType.end())
return PTTI->second;
1545 "Cannot autopromote this type, add it with AddPromotedToType.");
1551 "Didn't find type to promote to!");
1558 bool AllowUnknown =
false)
const {
1567 bool AllowUnknown =
false)
const {
1569 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1572 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1573 Type *EltTy = VTy->getElementType();
1575 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1580 VTy->getElementCount());
1587 bool AllowUnknown =
false)
const {
1589 if (
auto *PTy = dyn_cast<PointerType>(Ty))
1592 if (
auto *VTy = dyn_cast<VectorType>(Ty)) {
1593 Type *EltTy = VTy->getElementType();
1594 if (
auto *PTy = dyn_cast<PointerType>(EltTy)) {
1599 VTy->getElementCount());
1608 bool AllowUnknown =
false)
const {
1620 return RegisterTypeForVT[VT.
SimpleTy];
1630 unsigned NumIntermediates;
1632 NumIntermediates, RegisterVT);
1654 std::optional<MVT> RegisterVT = std::nullopt)
const {
1657 std::size(NumRegistersForVT));
1663 unsigned NumIntermediates;
1669 return (
BitWidth + RegWidth - 1) / RegWidth;
1695 return DL.getABITypeAlign(ArgTy);
1709 if (NewVT.
isVector() && !Load->hasOneUse())
1723 return DL.isBigEndian() || VT == MVT::ppcf128;
1729 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
1730 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
1804 unsigned * =
nullptr)
const {
1812 unsigned * =
nullptr)
const {
1822 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1824 unsigned *
Fast =
nullptr)
const;
1833 unsigned *
Fast =
nullptr)
const;
1841 unsigned AddrSpace = 0,
Align Alignment =
Align(1),
1843 unsigned *
Fast =
nullptr)
const;
1851 unsigned *
Fast =
nullptr)
const;
1856 unsigned *
Fast =
nullptr)
const;
1899 return StackPointerRegisterToSaveRestore;
1922 return MinStackArgumentAlignment;
2026 return MaxAtomicSizeInBitsSupported;
2032 return MaxDivRemBitWidthSupported;
2038 return MaxLargeFPConvertBitWidthSupported;
2092 llvm_unreachable(
"Masked atomicrmw expansion unimplemented on this target");
2100 "Generic atomicrmw expansion unimplemented on this target");
2108 "Bit test atomicrmw expansion unimplemented on this target");
2116 "Compare arith atomicrmw expansion unimplemented on this target");
2226 if (SI->getValueOperand()->getType()->isFloatingPointTy())
2350 bool IsSigned)
const {
2374 BooleanContents = Ty;
2375 BooleanFloatContents = Ty;
2381 BooleanContents = IntTy;
2382 BooleanFloatContents = FloatTy;
2388 BooleanVectorContents = Ty;
2393 SchedPreferenceInfo = Pref;
2406 StackPointerRegisterToSaveRestore = R;
2415 HasMultipleConditionRegisters = hasManyRegs;
2423 HasExtractBitsInsn = hasExtractInsn;
2433 BypassSlowDivWidths[SlowBitWidth] = FastBitWidth;
2446 virtual std::pair<const TargetRegisterClass *, uint8_t>
2457 assert(
Op < std::size(OpActions[0]) &&
"Table isn't big enough!");
2476 MemVT.
isValid() &&
"Table isn't big enough!");
2477 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2478 unsigned Shift = 4 * ExtType;
2484 for (
auto ExtType : ExtTypes)
2489 for (
auto MemVT : MemVTs)
2507 for (
auto IdxMode : IdxModes)
2508 setIndexedModeAction(IdxMode, VT, IMAB_Load, Action);
2524 for (
auto IdxMode : IdxModes)
2525 setIndexedModeAction(IdxMode, VT, IMAB_Store, Action);
2541 setIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad, Action);
2551 setIndexedModeAction(IdxMode, VT, IMAB_MaskedStore, Action);
2558 for (
auto CC : CCs) {
2560 "Table isn't big enough!");
2561 assert((
unsigned)Action < 0x10 &&
"too many bits for bitfield array");
2592 for (
auto Op : Ops) {
2602 for (
auto NT : NTs) {
2603 assert(
unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
2604 TargetDAGCombineArray[NT >> 3] |= 1 << (NT & 7);
2610 MinFunctionAlignment = Alignment;
2616 PrefFunctionAlignment = Alignment;
2624 MaxBytesForAlignment = MaxBytes;
2629 MinStackArgumentAlignment = Alignment;
2637 MaxAtomicSizeInBitsSupported = SizeInBits;
2643 MaxDivRemBitWidthSupported = SizeInBits;
2649 MaxLargeFPConvertBitWidthSupported = SizeInBits;
2654 MinCmpXchgSizeInBits = SizeInBits;
2659 SupportsUnalignedAtomics = UnalignedSupported;
2704 Type *Ty,
unsigned AddrSpace,
2751 return (
From->isIntegerTy() ||
From->isFloatingPointTy()) &&
2793 default:
return false;
2861 switch (
I->getOpcode()) {
2862 case Instruction::FPExt:
2867 case Instruction::ZExt:
2868 if (
isZExtFree(
I->getOperand(0)->getType(),
I->getType()))
2871 case Instruction::SExt:
2898 if (isa<ZExtInst>(Ext))
2901 assert(isa<SExtInst>(Ext) &&
"Unexpected ext type!");
3007 unsigned Factor)
const {
3018 unsigned Factor)
const {
3049 "invalid fpext types");
3057 LLT DestTy,
LLT SrcTy)
const {
3065 EVT DestVT,
EVT SrcVT)
const {
3067 "invalid fpext types");
3125 assert((
MI.getOpcode() == TargetOpcode::G_FADD ||
3126 MI.getOpcode() == TargetOpcode::G_FSUB ||
3127 MI.getOpcode() == TargetOpcode::G_FMUL) &&
3128 "unexpected node in FMAD forming combine");
3149 "unexpected node in FMAD forming combine");
3190 unsigned Index)
const {
3213 bool MathUsed)
const {
3282 LibcallRoutineNames[Call] =
Name;
3285 for (
auto Call : Calls)
3291 return LibcallRoutineNames[Call];
3297 CmpLibcallCCs[Call] =
CC;
3303 return CmpLibcallCCs[Call];
3308 LibcallCallingConvs[Call] =
CC;
3313 return LibcallCallingConvs[Call];
3337 bool HasMultipleConditionRegisters;
3343 bool HasExtractBitsInsn;
3349 DenseMap <unsigned int, unsigned int> BypassSlowDivWidths;
3354 bool JumpIsExpensive;
3373 Align MinStackArgumentAlignment;
3377 Align MinFunctionAlignment;
3381 Align PrefFunctionAlignment;
3384 Align PrefLoopAlignment;
3386 unsigned MaxBytesForAlignment;
3390 unsigned MaxAtomicSizeInBitsSupported;
3394 unsigned MaxDivRemBitWidthSupported;
3398 unsigned MaxLargeFPConvertBitWidthSupported;
3402 unsigned MinCmpXchgSizeInBits;
3405 bool SupportsUnalignedAtomics;
3409 Register StackPointerRegisterToSaveRestore;
3470 ValueTypeActionImpl ValueTypeActions;
3489 const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
3499 void InitLibcalls(
const Triple &TT);
3503 enum IndexedModeActionsBits {
3506 IMAB_MaskedStore = 8,
3507 IMAB_MaskedLoad = 12
3510 void setIndexedModeAction(
unsigned IdxMode, MVT VT,
unsigned Shift,
3513 (
unsigned)Action < 0xf &&
"Table isn't big enough!");
3514 unsigned Ty = (
unsigned)VT.SimpleTy;
3515 IndexedModeActions[Ty][IdxMode] &= ~(0xf << Shift);
3516 IndexedModeActions[Ty][IdxMode] |= ((
uint16_t)Action) << Shift;
3520 unsigned Shift)
const {
3522 "Table isn't big enough!");
3523 unsigned Ty = (
unsigned)VT.SimpleTy;
3524 return (
LegalizeAction)((IndexedModeActions[Ty][IdxMode] >> Shift) & 0xf);
3665 return MRI.hasOneNonDBGUse(N0);
3735 unsigned OpNo)
const {
3751 bool IsSignaling =
false)
const;
3757 MakeLibCallOptions CallOptions,
3765 const uint32_t *CallerPreservedMask,
3804 const MemOp &
Op,
unsigned DstAS,
unsigned SrcAS,
3812 const APInt &DemandedElts,
3813 TargetLoweringOpt &TLO)
const;
3817 TargetLoweringOpt &TLO)
const;
3824 const APInt &DemandedElts,
3834 TargetLoweringOpt &TLO)
const;
3851 TargetLoweringOpt &TLO,
unsigned Depth = 0,
3852 bool AssumeSingleUse =
false)
const;
3857 KnownBits &Known, TargetLoweringOpt &TLO,
3859 bool AssumeSingleUse =
false)
const;
3864 DAGCombinerInfo &DCI)
const;
3869 const APInt &DemandedElts,
3870 DAGCombinerInfo &DCI)
const;
3876 const APInt &DemandedElts,
3878 unsigned Depth = 0)
const;
3884 unsigned Depth = 0)
const;
3889 const APInt &DemandedElts,
3891 unsigned Depth = 0)
const;
3909 TargetLoweringOpt &TLO,
unsigned Depth = 0,
3910 bool AssumeSingleUse =
false)
const;
3915 DAGCombinerInfo &DCI)
const;
3931 const APInt &DemandedElts,
3933 unsigned Depth = 0)
const;
3941 const APInt &DemandedElts,
3943 unsigned Depth = 0)
const;
3952 unsigned Depth = 0)
const;
3966 const APInt &DemandedElts,
3968 unsigned Depth = 0)
const;
3976 const APInt &DemandedElts,
3978 unsigned Depth = 0)
const;
3987 APInt &KnownZero, TargetLoweringOpt &TLO,
unsigned Depth = 0)
const;
3996 const APInt &DemandedElts,
3998 TargetLoweringOpt &TLO,
3999 unsigned Depth = 0)
const;
4013 bool PoisonOnly,
unsigned Depth)
const;
4021 bool ConsiderFlags,
unsigned Depth)
const;
4041 unsigned Depth = 0)
const;
4048 unsigned Depth = 0)
const;
4098 bool foldBooleans, DAGCombinerInfo &DCI,
4099 const SDLoc &dl)
const;
4146 bool IsAfterLegal)
const {
4247 bool LegalOps,
bool OptForSize,
4249 unsigned Depth = 0)
const;
4254 unsigned Depth = 0)
const {
4273 bool LegalOps,
bool OptForSize,
4274 unsigned Depth = 0)
const {
4282 bool OptForSize,
unsigned Depth = 0)
const {
4296 unsigned NumParts,
MVT PartVT, std::optional<CallingConv::ID>
CC)
const {
4313 unsigned &PhysReg,
int &
Cost)
const {
4320 const SDValue *Parts,
unsigned NumParts,
4322 std::optional<CallingConv::ID>
CC)
const {