27 #define DEBUG_TYPE "tti" 31 cl::desc(
"Recognize reduction patterns."));
45 : TTIImpl(new
Model<NoTTIImpl>(NoTTIImpl(DL))) {}
50 : TTIImpl(
std::move(
Arg.TTIImpl)) {}
53 TTIImpl = std::move(RHS.TTIImpl);
59 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
60 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
65 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
66 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
72 int Cost = TTIImpl->getCallCost(F, Arguments);
73 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
78 return TTIImpl->getInliningThresholdMultiplier();
83 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
87 const Value *Src)
const {
88 return TTIImpl->getExtCost(I, Src);
93 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
94 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
100 unsigned &JTSize)
const {
101 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
106 int Cost = TTIImpl->getUserCost(U, Operands);
107 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
112 return TTIImpl->hasBranchDivergence();
116 return TTIImpl->isSourceOfDivergence(V);
120 return TTIImpl->isAlwaysUniform(V);
124 return TTIImpl->getFlatAddressSpace();
128 return TTIImpl->isLoweredToCall(F);
133 return TTIImpl->getUnrollingPreferences(L, SE, UP);
137 return TTIImpl->isLegalAddImmediate(Imm);
141 return TTIImpl->isLegalICmpImmediate(Imm);
150 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
151 Scale, AddrSpace, I);
155 return TTIImpl->isLSRCostLess(C1, C2);
159 return TTIImpl->canMacroFuseCmp();
163 return TTIImpl->shouldFavorPostInc();
167 return TTIImpl->isLegalMaskedStore(DataType);
171 return TTIImpl->isLegalMaskedLoad(DataType);
175 return TTIImpl->isLegalMaskedGather(DataType);
179 return TTIImpl->isLegalMaskedScatter(DataType);
183 return TTIImpl->hasDivRemOp(DataType, IsSigned);
187 unsigned AddrSpace)
const {
188 return TTIImpl->hasVolatileVariant(I, AddrSpace);
192 return TTIImpl->prefersVectorizedAddressing();
199 unsigned AddrSpace)
const {
200 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
202 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
207 return TTIImpl->LSRWithInstrQueries();
211 return TTIImpl->isTruncateFree(Ty1, Ty2);
215 return TTIImpl->isProfitableToHoist(I);
221 return TTIImpl->isTypeLegal(Ty);
225 return TTIImpl->getJumpBufAlignment();
229 return TTIImpl->getJumpBufSize();
233 return TTIImpl->shouldBuildLookupTables();
236 return TTIImpl->shouldBuildLookupTablesForConstant(C);
240 return TTIImpl->useColdCCForColdCall(F);
245 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
251 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
255 return TTIImpl->supportsEfficientVectorElementLoadStore();
259 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
264 return TTIImpl->enableMemCmpExpansion(IsZeroCmp);
268 return TTIImpl->enableInterleavedAccessVectorization();
272 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
280 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
286 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
290 return TTIImpl->haveFastSqrt(Ty);
294 return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
298 int Cost = TTIImpl->getFPOpCost(Ty);
299 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
306 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
307 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
312 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
313 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
319 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
320 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
326 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
327 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
332 return TTIImpl->getNumberOfRegisters(Vector);
336 return TTIImpl->getRegisterBitWidth(Vector);
340 return TTIImpl->getMinVectorRegisterBitWidth();
344 return TTIImpl->shouldMaximizeVectorBandwidth(OptSize);
348 return TTIImpl->getMinimumVF(ElemWidth);
352 const Instruction &
I,
bool &AllowPromotionWithoutCommonHeader)
const {
353 return TTIImpl->shouldConsiderAddressTypePromotion(
354 I, AllowPromotionWithoutCommonHeader);
358 return TTIImpl->getCacheLineSize();
363 return TTIImpl->getCacheSize(Level);
368 return TTIImpl->getCacheAssociativity(Level);
372 return TTIImpl->getPrefetchDistance();
376 return TTIImpl->getMinPrefetchStride();
380 return TTIImpl->getMaxPrefetchIterationsAhead();
384 return TTIImpl->getMaxInterleaveFactor(VF);
392 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
393 Opd1PropInfo, Opd2PropInfo, Args);
394 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
400 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
401 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
408 "Opcode should reflect passed instruction.");
409 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
410 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
416 unsigned Index)
const {
417 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
418 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
423 int Cost = TTIImpl->getCFInstrCost(Opcode);
424 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
431 "Opcode should reflect passed instruction.");
432 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
433 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
438 unsigned Index)
const {
439 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
440 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
449 "Opcode should reflect passed instruction.");
450 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
451 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
459 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
460 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
465 Value *Ptr,
bool VariableMask,
466 unsigned Alignment)
const {
467 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
469 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
476 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
477 Alignment, AddressSpace);
478 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
484 unsigned ScalarizationCostPassed)
const {
485 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
486 ScalarizationCostPassed);
487 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
493 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
494 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
500 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
501 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
506 return TTIImpl->getNumberOfParts(Tp);
511 const SCEV *Ptr)
const {
512 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
513 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
518 bool IsPairwiseForm)
const {
519 int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm);
520 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
526 bool IsUnsigned)
const {
528 TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned);
529 assert(Cost >= 0 &&
"TTI should not produce negative costs!");
535 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
540 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
544 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
549 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
555 unsigned DestAlign)
const {
556 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
562 unsigned RemainingBytes,
unsigned SrcAlign,
unsigned DestAlign)
const {
563 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
564 SrcAlign, DestAlign);
569 return TTIImpl->areInlineCompatible(Caller, Callee);
574 return TTIImpl->isIndexedLoadLegal(Mode, Ty);
579 return TTIImpl->isIndexedStoreLegal(Mode, Ty);
583 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
587 return TTIImpl->isLegalToVectorizeLoad(LI);
591 return TTIImpl->isLegalToVectorizeStore(SI);
595 unsigned ChainSizeInBytes,
unsigned Alignment,
unsigned AddrSpace)
const {
596 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
601 unsigned ChainSizeInBytes,
unsigned Alignment,
unsigned AddrSpace)
const {
602 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
608 unsigned ChainSizeInBytes,
610 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
615 unsigned ChainSizeInBytes,
617 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
622 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
626 return TTIImpl->shouldExpandReduction(II);
629 int TargetTransformInfo::getInstructionLatency(
const Instruction *
I)
const {
630 return TTIImpl->getInstructionLatency(I);
639 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
640 if (CI->getValue().isPowerOf2())
649 if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
653 if (
auto *CI = dyn_cast<ConstantInt>(Splat))
654 if (CI->getValue().isPowerOf2())
656 }
else if (
auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
658 for (
unsigned I = 0,
E = CDS->getNumElements(); I !=
E; ++
I) {
659 if (
auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
660 if (CI->getValue().isPowerOf2())
670 if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
680 if (!SI && Level == 0 && IsLeft)
689 for (
unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2)
693 return Mask == ActualMask;
705 struct ReductionData {
706 ReductionData() =
delete;
708 : Opcode(Opcode), LHS(LHS), RHS(RHS),
Kind(Kind) {
709 assert(Kind != RK_None &&
"expected binary or min/max reduction only.");
712 Value *LHS =
nullptr;
713 Value *RHS =
nullptr;
715 bool hasSameData(ReductionData &RD)
const {
716 return Kind == RD.Kind && Opcode == RD.Opcode;
724 return ReductionData(RK_Arithmetic, I->
getOpcode(), L, R);
725 if (
auto *
SI = dyn_cast<SelectInst>(I)) {
732 auto *CI = cast<CmpInst>(
SI->getCondition());
733 return ReductionData(RK_MinMax, CI->getOpcode(), L, R);
737 auto *CI = cast<CmpInst>(
SI->getCondition());
738 return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R);
746 unsigned NumLevels) {
770 if (!Level && !RS && !LS)
776 Value *NextLevelOp =
nullptr;
777 if (NextLevelOpR && NextLevelOpL) {
779 if (NextLevelOpL != NextLevelOpR)
782 NextLevelOp = NextLevelOpL;
783 }
else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) {
790 if (NextLevelOpL && NextLevelOpL != RD->RHS)
792 else if (NextLevelOpR && NextLevelOpR != RD->LHS)
795 NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS;
801 if (Level + 1 != NumLevels) {
804 if (!NextLevelRD || !RD->hasSameData(*NextLevelRD))
819 if (++Level == NumLevels)
828 unsigned &Opcode,
Type *&Ty) {
847 Type *VecTy = RdxStart->getType();
880 static std::pair<Value *, ShuffleVectorInst *>
884 if ((S = dyn_cast<ShuffleVectorInst>(L)))
885 return std::make_pair(R, S);
888 return std::make_pair(L, S);
893 unsigned &Opcode,
Type *&Ty) {
928 unsigned MaskStart = 1;
931 unsigned NumVecElemsRemain = NumVecElems;
932 while (NumVecElemsRemain - 1) {
937 if (!RDLevel || !RDLevel->hasSameData(*RD))
942 std::tie(NextRdxOp, Shuffle) =
946 if (Shuffle ==
nullptr)
952 for (
unsigned j = 0; j != MaskStart; ++j)
953 ShuffleMask[j] = MaskStart + j;
955 std::fill(&ShuffleMask[MaskStart], ShuffleMask.
end(), -1);
958 if (ShuffleMask != Mask)
962 NumVecElemsRemain /= 2;
971 int TargetTransformInfo::getInstructionThroughput(
const Instruction *I)
const {
973 case Instruction::GetElementPtr:
977 case Instruction::PHI:
978 case Instruction::Br: {
982 case Instruction::FAdd:
983 case Instruction::Sub:
984 case Instruction::FSub:
985 case Instruction::Mul:
986 case Instruction::FMul:
987 case Instruction::UDiv:
988 case Instruction::SDiv:
989 case Instruction::FDiv:
990 case Instruction::URem:
991 case Instruction::SRem:
992 case Instruction::FRem:
993 case Instruction::Shl:
994 case Instruction::LShr:
995 case Instruction::AShr:
996 case Instruction::And:
997 case Instruction::Or:
998 case Instruction::Xor: {
1005 Op1VP, Op2VP, Operands);
1012 case Instruction::ICmp:
1013 case Instruction::FCmp: {
1030 case Instruction::ZExt:
1031 case Instruction::SExt:
1032 case Instruction::FPToUI:
1033 case Instruction::FPToSI:
1034 case Instruction::FPExt:
1035 case Instruction::PtrToInt:
1036 case Instruction::IntToPtr:
1037 case Instruction::SIToFP:
1038 case Instruction::UIToFP:
1039 case Instruction::Trunc:
1040 case Instruction::FPTrunc:
1041 case Instruction::BitCast:
1042 case Instruction::AddrSpaceCast: {
1046 case Instruction::ExtractElement: {
1055 unsigned ReduxOpCode;
1066 case RK_UnsignedMinMax:
1082 case RK_UnsignedMinMax:
1093 case Instruction::InsertElement: {
1102 case Instruction::ShuffleVector: {
1113 return TTIImpl->getShuffleCost(
SK_Reverse, Ty, 0,
nullptr);
1116 return TTIImpl->getShuffleCost(
SK_Select, Ty, 0,
nullptr);
1119 return TTIImpl->getShuffleCost(
SK_Transpose, Ty, 0,
nullptr);
1122 return TTIImpl->getShuffleCost(
SK_Broadcast, Ty, 0,
nullptr);
1134 if (
auto *FPMO = dyn_cast<FPMathOperator>(II))
1135 FMF = FPMO->getFastMathFlags();
1153 : TTICallback(
std::move(TTICallback)) {}
1157 return TTICallback(F);
1168 "Target Transform Information",
false,
true)
1171 void TargetTransformInfoWrapperPass::anchor() {}
1188 TTI = TIRA.
run(F, DummyFAM);
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
Value * getValueOperand()
A parsed version of the target data layout string in and methods for querying it. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Compute iterated dominance frontiers using a linear time algorithm.
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
The main scalar evolution driver.
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
Analysis pass providing the TargetTransformInfo.
This instruction constructs a fixed permutation of two input vectors.
An instruction for reading from memory.
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
bool match(Val *V, const Pattern &P)
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Class to represent function types.
Type * getType() const
All values are typed, get the type of this value.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
An instruction for storing to memory.
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
VectorType * getType() const
Overload to return most specific vector type.
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
initializer< Ty > init(const Ty &Val)
This instruction inserts a single (scalar) element into a VectorType value.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
bool isIdentity() const
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
AMDGPU Lower Kernel Arguments
TargetIRAnalysis()
Default construct a target IR analysis.
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
const Value * getCondition() const
Fast - This calling convention attempts to make calls as fast as possible (e.g.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This is the shared class of boolean and integer constants.
ImmutablePass class - This class is used to provide information that does not need to be run...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source elem...
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
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
Class to represent vector types.
Class for arbitrary precision integers.
Result run(const Function &F, FunctionAnalysisManager &)
amdgpu Simplify well known AMD library false Value Value * Arg
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
unsigned getAlignment() const
Return the alignment of the access that is being performed.
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
iterator_range< value_op_iterator > operand_values()
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 getAlignment() const
Return the alignment of the access that is being performed.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
TargetTransformInfo Result
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
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.
print Print MemDeps of function
Convenience struct for specifying and reasoning about fast-math flags.
A container for analyses that lazily runs them and caches their results.
VectorType * getType() const
Overload to return most specific vector type.
Information about a load/store intrinsic defined by the target.
A special type used by analysis passes to provide an address that identifies that particular analysis...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
A wrapper class for inspecting calls to intrinsic functions.