16 #ifndef LLVM_CODEGEN_BASICTTIIMPL_H 17 #define LLVM_CODEGEN_BASICTTIIMPL_H 61 class ScalarEvolution;
84 unsigned getBroadcastShuffleOverhead(
Type *Ty) {
90 Instruction::ExtractElement, Ty, 0);
94 Instruction::InsertElement, Ty, i);
101 unsigned getPermuteShuffleOverhead(
Type *Ty) {
112 Cost +=
static_cast<T *
>(
this)
114 Cost +=
static_cast<T *
>(
this)
122 unsigned getExtractSubvectorOverhead(
Type *Ty,
int Index,
Type *SubTy) {
124 "Can only extract subvectors from vectors");
127 "SK_ExtractSubvector index out of range");
133 for (
int i = 0; i != NumSubElts; ++i) {
135 Instruction::ExtractElement, Ty, i + Index);
137 Instruction::InsertElement, SubTy, i);
144 unsigned getInsertSubvectorOverhead(
Type *Ty,
int Index,
Type *SubTy) {
146 "Can only insert subvectors into vectors");
149 "SK_InsertSubvector index out of range");
155 for (
int i = 0; i != NumSubElts; ++i) {
157 Instruction::ExtractElement, SubTy, i);
159 Instruction::InsertElement, Ty, i + Index);
166 return static_cast<const T *
>(
this)->getST();
171 return static_cast<const T *
>(
this)->getTLI();
238 bool HasBaseReg, int64_t Scale,
265 bool HasBaseReg, int64_t Scale,
unsigned AddrSpace) {
295 if (getTLI()->isExtFree(I))
298 if (isa<ZExtInst>(I) || isa<SExtInst>(I))
299 if (
const LoadInst *LI = dyn_cast<LoadInst>(Src))
300 if (getTLI()->isExtLoad(LI, I,
DL))
313 if (IID == Intrinsic::cttz) {
314 if (getTLI()->isCheapToSpeculateCttz())
319 if (IID == Intrinsic::ctlz) {
320 if (getTLI()->isCheapToSpeculateCtlz())
329 unsigned &JumpTableSize,
351 APInt MinCaseVal = MaxCaseVal;
352 for (
auto CI : SI.
cases()) {
353 const APInt &CaseVal = CI.getCaseValue()->getValue();
354 if (CaseVal.
sgt(MaxCaseVal))
355 MaxCaseVal = CaseVal;
356 if (CaseVal.
slt(MinCaseVal))
357 MinCaseVal = CaseVal;
364 Dests.
insert(
I.getCaseSuccessor());
373 if (N < 2 || N < TLI->getMinimumJumpTableEntries())
376 (MaxCaseVal - MinCaseVal)
380 JumpTableSize = Range;
418 case Instruction::Trunc:
422 case Instruction::ZExt:
427 case Instruction::AddrSpaceCast:
468 if (PartialUnrollingThreshold.getNumOccurrences() > 0)
469 MaxOps = PartialUnrollingThreshold;
481 if (isa<CallInst>(J) || isa<InvokeInst>(J)) {
484 if (!static_cast<T *>(
this)->isLoweredToCall(
F))
521 if (isa<LoadInst>(I))
575 Cost +=
static_cast<T *
>(
this)
578 Cost +=
static_cast<T *
>(
this)
592 for (
const Value *A : Args) {
593 if (!isa<Constant>(A) && UniqueOperands.
insert(A).second) {
594 Type *VecTy =
nullptr;
595 if (A->getType()->isVectorTy()) {
596 VecTy = A->getType();
599 "Vector argument does not match VF");
631 unsigned Opcode,
Type *Ty,
641 assert(ISD &&
"Invalid opcode");
648 unsigned OpCost = (IsFloat ? 2 : 1);
653 return LT.first * OpCost;
659 return LT.first * 2 * OpCost;
667 unsigned Cost =
static_cast<T *
>(
this)
682 return getBroadcastShuffleOverhead(Tp);
688 return getPermuteShuffleOverhead(Tp);
690 return getExtractSubvectorOverhead(Tp, Index, SubTp);
692 return getInsertSubvectorOverhead(Tp, Index, SubTp);
701 assert(ISD &&
"Invalid opcode");
706 if (SrcLT.first == DstLT.first &&
707 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
710 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
714 if (Opcode == Instruction::Trunc &&
718 if (Opcode == Instruction::ZExt &&
722 if (Opcode == Instruction::AddrSpaceCast &&
729 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
730 I && isa<LoadInst>(
I->getOperand(0))) {
740 if (SrcLT.first == DstLT.first &&
747 if (Opcode == Instruction::BitCast)
762 if (SrcLT.first == DstLT.first &&
763 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
766 if (Opcode == Instruction::ZExt)
770 if (Opcode == Instruction::SExt)
777 return SrcLT.first * 1;
793 T *
TTI =
static_cast<T *
>(
this);
794 return TTI->getVectorSplitCost() +
795 (2 * TTI->getCastInstrCost(Opcode, SplitDst, SplitSrc,
I));
813 if (Opcode == Instruction::BitCast)
826 Instruction::ExtractElement, VecTy, Index) +
840 assert(ISD &&
"Invalid opcode");
844 assert(CondTy &&
"CondTy must exist");
850 if (!(ValTy->
isVectorTy() && !LT.second.isVector()) &&
877 std::pair<unsigned, MVT>
LT =
890 unsigned Cost = LT.first;
919 bool UseMaskForCond =
false,
920 bool UseMaskForGaps =
false) {
922 assert(VT &&
"Expect a vector type for interleaved memory op");
925 assert(Factor > 1 && NumElts % Factor == 0 &&
"Invalid interleave factor");
927 unsigned NumSubElts = NumElts / Factor;
932 if (UseMaskForCond || UseMaskForGaps)
934 Opcode, VecTy, Alignment, AddressSpace);
947 auto ceil = [](
unsigned A,
unsigned B) {
return (A +
B - 1) /
B; };
966 unsigned NumLegalInsts = ceil(VecTySize, VecTyLTSize);
970 unsigned NumEltsPerLegalInst = ceil(NumElts, NumLegalInsts);
973 BitVector UsedInsts(NumLegalInsts,
false);
974 for (
unsigned Index : Indices)
975 for (
unsigned Elt = 0; Elt < NumSubElts; ++Elt)
976 UsedInsts.
set((Index + Elt * Factor) / NumEltsPerLegalInst);
980 Cost *= UsedInsts.
count() / NumLegalInsts;
995 "Interleaved memory op has too many members");
997 for (
unsigned Index : Indices) {
998 assert(Index < Factor &&
"Invalid index for interleaved memory op");
1001 for (
unsigned i = 0; i < NumSubElts; i++)
1002 Cost += static_cast<T *>(
this)->getVectorInstrCost(
1003 Instruction::ExtractElement, VT, Index + i * Factor);
1006 unsigned InsSubCost = 0;
1007 for (
unsigned i = 0; i < NumSubElts; i++)
1008 InsSubCost += static_cast<T *>(
this)->getVectorInstrCost(
1009 Instruction::InsertElement, SubVT, i);
1011 Cost += Indices.size() * InsSubCost;
1022 unsigned ExtSubCost = 0;
1023 for (
unsigned i = 0; i < NumSubElts; i++)
1024 ExtSubCost += static_cast<T *>(
this)->getVectorInstrCost(
1025 Instruction::ExtractElement, SubVT, i);
1026 Cost += ExtSubCost * Factor;
1028 for (
unsigned i = 0; i < NumElts; i++)
1029 Cost += static_cast<T *>(
this)
1030 ->getVectorInstrCost(Instruction::InsertElement, VT, i);
1033 if (!UseMaskForCond)
1050 for (
unsigned i = 0; i < NumSubElts; i++)
1051 Cost += static_cast<T *>(
this)->getVectorInstrCost(
1052 Instruction::ExtractElement, SubVT, i);
1054 for (
unsigned i = 0; i < NumElts; i++)
1055 Cost += static_cast<T *>(
this)->getVectorInstrCost(
1056 Instruction::InsertElement, MaskVT, i);
1065 BinaryOperator::And, MaskVT);
1075 assert((RetVF == 1 || VF == 1) &&
"VF > 1 and RetVF is a vector type");
1076 auto *ConcreteTTI =
static_cast<T *
>(
this);
1083 Type *OpTy =
Op->getType();
1095 if (RetVF > 1 || VF > 1) {
1096 ScalarizationCost = 0;
1102 return ConcreteTTI->getIntrinsicInstrCost(IID, RetTy, Types, FMF,
1105 case Intrinsic::masked_scatter: {
1106 assert(VF == 1 &&
"Can't vectorize types here.");
1108 bool VarMask = !isa<Constant>(
Mask);
1109 unsigned Alignment = cast<ConstantInt>(Args[2])->getZExtValue();
1110 return ConcreteTTI->getGatherScatterOpCost(
1113 case Intrinsic::masked_gather: {
1114 assert(VF == 1 &&
"Can't vectorize types here.");
1116 bool VarMask = !isa<Constant>(
Mask);
1117 unsigned Alignment = cast<ConstantInt>(Args[1])->getZExtValue();
1119 Args[0], VarMask, Alignment);
1121 case Intrinsic::experimental_vector_reduce_add:
1122 case Intrinsic::experimental_vector_reduce_mul:
1123 case Intrinsic::experimental_vector_reduce_and:
1124 case Intrinsic::experimental_vector_reduce_or:
1125 case Intrinsic::experimental_vector_reduce_xor:
1126 case Intrinsic::experimental_vector_reduce_v2_fadd:
1127 case Intrinsic::experimental_vector_reduce_v2_fmul:
1128 case Intrinsic::experimental_vector_reduce_smax:
1129 case Intrinsic::experimental_vector_reduce_smin:
1130 case Intrinsic::experimental_vector_reduce_fmax:
1131 case Intrinsic::experimental_vector_reduce_fmin:
1132 case Intrinsic::experimental_vector_reduce_umax:
1133 case Intrinsic::experimental_vector_reduce_umin:
1135 case Intrinsic::fshl:
1136 case Intrinsic::fshr: {
1150 Cost += ConcreteTTI->getArithmeticInstrCost(BinaryOperator::Or, RetTy);
1151 Cost += ConcreteTTI->getArithmeticInstrCost(BinaryOperator::Sub, RetTy);
1152 Cost += ConcreteTTI->getArithmeticInstrCost(BinaryOperator::Shl, RetTy,
1153 OpKindX, OpKindZ, OpPropsX);
1154 Cost += ConcreteTTI->getArithmeticInstrCost(BinaryOperator::LShr, RetTy,
1155 OpKindY, OpKindZ, OpPropsY);
1159 Cost += ConcreteTTI->getArithmeticInstrCost(BinaryOperator::URem, RetTy,
1160 OpKindZ, OpKindBW, OpPropsZ,
1165 Cost += ConcreteTTI->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy,
1182 auto *ConcreteTTI =
static_cast<T *
>(
this);
1185 unsigned SingleCallCost = 10;
1189 unsigned ScalarizationCost = ScalarizationCostPassed;
1190 unsigned ScalarCalls = 1;
1191 Type *ScalarRetTy = RetTy;
1199 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
1209 if (ScalarCalls == 1)
1212 unsigned ScalarCost =
1213 ConcreteTTI->getIntrinsicInstrCost(IID, ScalarRetTy, ScalarTys, FMF);
1215 return ScalarCalls * ScalarCost + ScalarizationCost;
1219 case Intrinsic::sqrt:
1222 case Intrinsic::sin:
1225 case Intrinsic::cos:
1228 case Intrinsic::exp:
1231 case Intrinsic::exp2:
1234 case Intrinsic::log:
1237 case Intrinsic::log10:
1243 case Intrinsic::fabs:
1246 case Intrinsic::canonicalize:
1259 case Intrinsic::copysign:
1262 case Intrinsic::floor:
1265 case Intrinsic::ceil:
1268 case Intrinsic::trunc:
1271 case Intrinsic::nearbyint:
1274 case Intrinsic::rint:
1280 case Intrinsic::pow:
1283 case Intrinsic::fma:
1286 case Intrinsic::fmuladd:
1290 case Intrinsic::lifetime_start:
1291 case Intrinsic::lifetime_end:
1292 case Intrinsic::sideeffect:
1294 case Intrinsic::masked_store:
1297 case Intrinsic::masked_load:
1299 case Intrinsic::experimental_vector_reduce_add:
1302 case Intrinsic::experimental_vector_reduce_mul:
1303 return ConcreteTTI->getArithmeticReductionCost(Instruction::Mul, Tys[0],
1305 case Intrinsic::experimental_vector_reduce_and:
1306 return ConcreteTTI->getArithmeticReductionCost(Instruction::And, Tys[0],
1308 case Intrinsic::experimental_vector_reduce_or:
1309 return ConcreteTTI->getArithmeticReductionCost(Instruction::Or, Tys[0],
1311 case Intrinsic::experimental_vector_reduce_xor:
1312 return ConcreteTTI->getArithmeticReductionCost(Instruction::Xor, Tys[0],
1314 case Intrinsic::experimental_vector_reduce_v2_fadd:
1315 return ConcreteTTI->getArithmeticReductionCost(
1316 Instruction::FAdd, Tys[0],
1319 case Intrinsic::experimental_vector_reduce_v2_fmul:
1320 return ConcreteTTI->getArithmeticReductionCost(
1321 Instruction::FMul, Tys[0],
1324 case Intrinsic::experimental_vector_reduce_smax:
1325 case Intrinsic::experimental_vector_reduce_smin:
1326 case Intrinsic::experimental_vector_reduce_fmax:
1327 case Intrinsic::experimental_vector_reduce_fmin:
1328 return ConcreteTTI->getMinMaxReductionCost(
1331 case Intrinsic::experimental_vector_reduce_umax:
1332 case Intrinsic::experimental_vector_reduce_umin:
1333 return ConcreteTTI->getMinMaxReductionCost(
1336 case Intrinsic::sadd_sat:
1337 case Intrinsic::ssub_sat: {
1342 ? Intrinsic::sadd_with_overflow
1343 : Intrinsic::ssub_with_overflow;
1348 Cost += ConcreteTTI->getIntrinsicInstrCost(
1349 OverflowOp, OpTy, {RetTy, RetTy}, FMF, ScalarizationCostPassed);
1350 Cost += ConcreteTTI->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy,
1356 case Intrinsic::uadd_sat:
1357 case Intrinsic::usub_sat: {
1362 ? Intrinsic::uadd_with_overflow
1363 : Intrinsic::usub_with_overflow;
1366 Cost += ConcreteTTI->getIntrinsicInstrCost(
1367 OverflowOp, OpTy, {RetTy, RetTy}, FMF, ScalarizationCostPassed);
1372 case Intrinsic::smul_fix:
1373 case Intrinsic::umul_fix: {
1378 IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
1381 Cost += 2 * ConcreteTTI->getCastInstrCost(ExtOp, ExtTy, RetTy);
1382 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::Mul, ExtTy);
1384 2 * ConcreteTTI->getCastInstrCost(Instruction::Trunc, RetTy, ExtTy);
1385 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::LShr, RetTy,
1388 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::Shl, RetTy,
1391 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::Or, RetTy);
1394 case Intrinsic::sadd_with_overflow:
1395 case Intrinsic::ssub_with_overflow: {
1398 unsigned Opcode = IID == Intrinsic::sadd_with_overflow
1400 : BinaryOperator::Sub;
1411 Cost += ConcreteTTI->getArithmeticInstrCost(Opcode, SumTy);
1412 Cost += 3 * ConcreteTTI->getCmpSelInstrCost(BinaryOperator::ICmp, SumTy,
1413 OverflowTy,
nullptr);
1414 Cost += 2 * ConcreteTTI->getCmpSelInstrCost(
1415 BinaryOperator::ICmp, OverflowTy, OverflowTy,
nullptr);
1417 ConcreteTTI->getArithmeticInstrCost(BinaryOperator::And, OverflowTy);
1420 case Intrinsic::uadd_with_overflow:
1421 case Intrinsic::usub_with_overflow: {
1424 unsigned Opcode = IID == Intrinsic::uadd_with_overflow
1426 : BinaryOperator::Sub;
1429 Cost += ConcreteTTI->getArithmeticInstrCost(Opcode, SumTy);
1430 Cost += ConcreteTTI->getCmpSelInstrCost(BinaryOperator::ICmp, SumTy,
1431 OverflowTy,
nullptr);
1434 case Intrinsic::smul_with_overflow:
1435 case Intrinsic::umul_with_overflow: {
1442 IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
1445 Cost += 2 * ConcreteTTI->getCastInstrCost(ExtOp, ExtTy, MulTy);
1446 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::Mul, ExtTy);
1448 2 * ConcreteTTI->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy);
1449 Cost += ConcreteTTI->getArithmeticInstrCost(Instruction::LShr, MulTy,
1453 if (IID == Intrinsic::smul_with_overflow)
1454 Cost += ConcreteTTI->getArithmeticInstrCost(
1458 Cost += ConcreteTTI->getCmpSelInstrCost(BinaryOperator::ICmp, MulTy,
1459 OverflowTy,
nullptr);
1462 case Intrinsic::ctpop:
1476 for (
unsigned ISD : ISDs) {
1478 if (IID == Intrinsic::fabs && LT.second.isFloatingPoint() &&
1498 auto MinLegalCostI = std::min_element(LegalCost.
begin(), LegalCost.
end());
1499 if (MinLegalCostI != LegalCost.
end())
1500 return *MinLegalCostI;
1502 auto MinCustomCostI =
1503 std::min_element(CustomCost.
begin(), CustomCost.
end());
1504 if (MinCustomCostI != CustomCost.
end())
1505 return *MinCustomCostI;
1509 if (IID == Intrinsic::fmuladd)
1510 return ConcreteTTI->getArithmeticInstrCost(BinaryOperator::FMul, RetTy) +
1511 ConcreteTTI->getArithmeticInstrCost(BinaryOperator::FAdd, RetTy);
1517 unsigned ScalarizationCost =
1519 ? ScalarizationCostPassed
1523 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
1529 unsigned ScalarCost = ConcreteTTI->getIntrinsicInstrCost(
1531 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
1532 if (Tys[i]->isVectorTy()) {
1535 ScalarCalls =
std::max(ScalarCalls, Tys[i]->getVectorNumElements());
1539 return ScalarCalls * ScalarCost + ScalarizationCost;
1543 return SingleCallCost;
1611 unsigned NumReduxLevels =
Log2_32(NumVecElts);
1612 unsigned ArithCost = 0;
1613 unsigned ShuffleCost = 0;
1614 auto *ConcreteTTI =
static_cast<T *
>(
this);
1615 std::pair<unsigned, MVT>
LT =
1616 ConcreteTTI->getTLI()->getTypeLegalizationCost(
DL, Ty);
1617 unsigned LongVectorCount = 0;
1619 LT.second.isVector() ? LT.second.getVectorNumElements() : 1;
1620 while (NumVecElts > MVTLen) {
1624 ShuffleCost += (IsPairwise + 1) *
1627 ArithCost += ConcreteTTI->getArithmeticInstrCost(Opcode, SubTy);
1632 NumReduxLevels -= LongVectorCount;
1642 unsigned NumShuffles = NumReduxLevels;
1643 if (IsPairwise && NumReduxLevels >= 1)
1644 NumShuffles += NumReduxLevels - 1;
1645 ShuffleCost += NumShuffles *
1648 ArithCost += NumReduxLevels *
1649 ConcreteTTI->getArithmeticInstrCost(Opcode, Ty);
1650 return ShuffleCost + ArithCost +
1651 ConcreteTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, 0);
1662 unsigned NumReduxLevels =
Log2_32(NumVecElts);
1665 CmpOpcode = Instruction::FCmp;
1668 "expecting floating point or integer type for min/max reduction");
1669 CmpOpcode = Instruction::ICmp;
1671 unsigned MinMaxCost = 0;
1672 unsigned ShuffleCost = 0;
1673 auto *ConcreteTTI =
static_cast<T *
>(
this);
1674 std::pair<unsigned, MVT>
LT =
1675 ConcreteTTI->getTLI()->getTypeLegalizationCost(
DL, Ty);
1676 unsigned LongVectorCount = 0;
1678 LT.second.isVector() ? LT.second.getVectorNumElements() : 1;
1679 while (NumVecElts > MVTLen) {
1685 ShuffleCost += (IsPairwise + 1) *
1689 ConcreteTTI->getCmpSelInstrCost(CmpOpcode, SubTy, CondTy,
nullptr) +
1696 NumReduxLevels -= LongVectorCount;
1706 unsigned NumShuffles = NumReduxLevels;
1707 if (IsPairwise && NumReduxLevels >= 1)
1708 NumShuffles += NumReduxLevels - 1;
1709 ShuffleCost += NumShuffles *
1714 (ConcreteTTI->getCmpSelInstrCost(CmpOpcode, Ty, CondTy,
nullptr) +
1719 return ShuffleCost + MinMaxCost +
1720 ConcreteTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, 0);
1747 #endif // LLVM_CODEGEN_BASICTTIIMPL_H TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return how this load with extension should be treated: either it is legal, needs to be promoted to a ...
Type * getVectorElementType() const
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< const Value *> Arguments, const User *U)
A parsed version of the target data layout string in and methods for querying it. ...
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
This class represents lattice values for constants.
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
virtual unsigned getCacheLineSize() const
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0...
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract)
Estimate the overhead of scalarizing an instruction.
void push_back(const T &Elt)
Analysis providing profile information.
The main scalar evolution driver.
bool slt(const APInt &RHS) const
Signed less than comparison.
int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value *> Operands)
static uint64_t round(uint64_t Acc, uint64_t Input)
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
A cache of @llvm.assume calls within a function.
bool isSuitableForBitTests(unsigned NumDests, unsigned NumCmps, const APInt &Low, const APInt &High, const DataLayout &DL) const
Return true if lowering to a bit test is suitable for a set of case clusters which contains NumDests ...
bool sgt(const APInt &RHS) const
Signed greater than comparison.
BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL)
int getExtCost(const Instruction *I, const Value *Src)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool isProfitableToHoist(Instruction *I)
bool isVectorTy() const
True if this is an instance of VectorType.
Base class which can be used to help build a TTI implementation.
virtual bool isZExtFree(Type *FromTy, Type *ToTy) const
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
unsigned getMaxInterleaveFactor(unsigned VF)
bool rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
virtual bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const
Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g.
iterator begin()
Instruction iterator methods.
virtual Optional< unsigned > getCacheLineSize(unsigned Level) const
Return the target cache line size in bytes at a given level.
virtual Optional< unsigned > getCacheSize(unsigned Level) const
Return the cache size in bytes for the given level of cache.
virtual bool isSuitableForJumpTable(const SwitchInst *SI, uint64_t NumCases, uint64_t Range, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
Return true if lowering to a jump table is suitable for a set of case clusters which may contain NumC...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value *> Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
unsigned getAddressComputationCost(Type *Ty, ScalarEvolution *, const SCEV *)
unsigned getOperandsScalarizationOverhead(ArrayRef< const Value *> Args, unsigned VF)
Estimate the overhead of scalarizing an instructions unique non-constant operands.
virtual unsigned getMaxPrefetchIterationsAhead() const
Return the maximum prefetch distance in terms of loop iterations.
unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index)
int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)
unsigned getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Try to calculate arithmetic and shuffle op costs for reduction operations.
virtual unsigned getPrefetchDistance() const
mir Rename Register Operands
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace, unsigned Alignment, bool *Fast) const
This file implements a class to represent arbitrary precision integral constant values and operations...
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
unsigned getRegisterBitWidth(bool Vector) const
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
virtual unsigned getMinPrefetchStride() const
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace, Instruction *I=nullptr) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isIndexedStoreLegal(TTI::MemIndexedMode M, Type *Ty, const DataLayout &DL) const
unsigned getFPOpCost(Type *Ty)
bool isTruncateFree(Type *Ty1, Type *Ty2)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
virtual ~BasicTTIImplBase()=default
bool isVoidTy() const
Return true if this is 'void'.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Concrete BasicTTIImpl that can be used if no further customization is needed.
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Simple binary floating point operators.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwise, bool)
Try to calculate op costs for min/max reduction operations.
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, unsigned Align=1, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, bool *=nullptr) const
Determine if the target supports unaligned memory accesses.
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type *> Tys, FastMathFlags FMF, unsigned ScalarizationCostPassed=std::numeric_limits< unsigned >::max())
Get intrinsic cost based on argument types.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
AMDGPU Lower Kernel Arguments
virtual Optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const
virtual bool areJTsAllowed(const Function *Fn) const
Return true if lowering to a jump table is allowed.
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
unsigned getNumberOfParts(Type *Tp)
bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
Attributes of a target dependent hardware loop.
static double log2(double V)
int getInlinerVectorBonusPercent()
virtual bool isProfitableToHoist(Instruction *I) const
static wasm::ValType getType(const TargetRegisterClass *RC)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
bool isLegalAddImmediate(int64_t imm)
Type * getWithNewBitWidth(unsigned NewBitWidth) const
Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old numb...
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
virtual unsigned getMaxPrefetchIterationsAhead() const
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
unsigned getCFInstrCost(unsigned Opcode)
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Returns platform specific canonical encoding of a floating point number.
size_type count() const
count - Returns the number of bits which are set.
Align max(MaybeAlign Lhs, Align Rhs)
int getInstructionLatency(const Instruction *I)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
unsigned getVectorSplitCost()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
cl::opt< unsigned > PartialUnrollingThreshold
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
static const unsigned DefaultLoadLatency
Drive the analysis of memory accesses in the loop.
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo)
LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const
Return how this store with truncation should be treated: either it is legal, needs to be promoted to ...
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
unsigned getVectorNumElements() const
Class to represent vector types.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Class for arbitrary precision integers.
Select(COND, TRUEVAL, FALSEVAL).
virtual Optional< unsigned > getCacheAssociativity(unsigned Level) const
Return the cache associatvity for the given level of cache.
InstListType::iterator iterator
Instruction iterators...
unsigned LoopMicroOpBufferSize
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
bool isAlwaysUniform(const Value *V)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
unsigned getFlatAddressSpace()
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual bool isLegalICmpImmediate(int64_t) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
BR_JT - Jumptable branch.
unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy)
This class represents an analyzed expression in the program.
bool hasBranchDivergence()
Represents a single loop in the control flow graph.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
bool shouldBuildLookupTables()
Establish a view to a call site for examination.
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getInliningThresholdMultiplier()
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
block_iterator block_end() const
bool preferPredicateOverEpilogue(Loop *L, LoopInfo *LI, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *TLI, DominatorTree *DT, const LoopAccessInfo *LAI)
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
bool isLSRCostLess(TTI::LSRCost C1, TTI::LSRCost C2)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
unsigned getScalarizationOverhead(Type *VecTy, ArrayRef< const Value *> Args)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual Optional< unsigned > getCacheAssociativity(TargetTransformInfo::CacheLevel Level) const
bool isSourceOfDivergence(const Value *V)
LLVM Value Representation.
FMA - Perform a * b + c with no intermediate rounding step.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isOperationLegalOrPromote(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal using promotion...
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal on this target.
Primary interface to the complete machine description for the target machine.
virtual unsigned getPrefetchDistance() const
Return the preferred prefetch distance in terms of instructions.
bool isTypeLegal(Type *Ty)
Type * getElementType() const
virtual int getScalingFactorCost(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS=0) const
Return the cost of the scaling factor used in the addressing mode represented by AM for this target...
virtual bool useAA() const
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine, etc.).
bool isIndexedLoadLegal(TTI::MemIndexedMode M, Type *Ty, const DataLayout &DL) const
Convenience struct for specifying and reasoning about fast-math flags.
unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type *> Tys)
Compute a cost of the given call instruction.
bool haveFastSqrt(Type *Ty)
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I=nullptr)
bool isLegalICmpImmediate(int64_t imm)
virtual unsigned getMinPrefetchStride() const
Return the minimum stride necessary to trigger software prefetching.
block_iterator block_begin() const
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
static IntegerType * getInt8Ty(LLVMContext &C)
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool isOperationExpand(unsigned Op, EVT VT) const
Return true if the specified operation is illegal on this target or unlikely to be made legal with cu...
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
bool empty() const
empty - Check if the array is empty.
unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JumpTableSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
A wrapper class for inspecting calls to intrinsic functions.
virtual bool isFAbsFree(EVT VT) const
Return true if an fabs operation is free to the point where it is never worthwhile to replace it with...
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type *> ParamTys, const User *U)