16 #ifndef LLVM_CODEGEN_BASICTTIIMPL_H
17 #define LLVM_CODEGEN_BASICTTIIMPL_H
47 unsigned getScalarizationOverhead(
Type *Ty,
bool Insert,
bool Extract) {
48 assert(Ty->
isVectorTy() &&
"Can only scalarize vectors");
53 Cost +=
static_cast<T *
>(
this)
56 Cost +=
static_cast<T *
>(
this)
64 unsigned getAltShuffleOverhead(
Type *Ty) {
65 assert(Ty->
isVectorTy() &&
"Can only shuffle vectors");
75 Cost +=
static_cast<T *
>(
this)
77 Cost +=
static_cast<T *
>(
this)
85 return static_cast<const T *
>(
this)->getST();
90 return static_cast<const T *
>(
this)->getTLI();
104 :
BaseT(std::move(static_cast<
BaseT &>(Arg))) {}
122 bool HasBaseReg, int64_t Scale,
123 unsigned AddrSpace) {
133 bool HasBaseReg, int64_t Scale,
unsigned AddrSpace) {
162 if (IID == Intrinsic::cttz) {
163 if (getTLI()->isCheapToSpeculateCttz())
168 if (IID == Intrinsic::ctlz) {
169 if (getTLI()->isCheapToSpeculateCtlz())
204 case Instruction::Trunc: {
209 case Instruction::ZExt: {
258 if (isa<CallInst>(J) || isa<InvokeInst>(J)) {
261 if (!static_cast<T *>(
this)->isLoweredToCall(
F))
286 unsigned Opcode,
Type *Ty,
294 assert(ISD &&
"Invalid opcode");
301 unsigned OpCost = (IsFloat ? 2 : 1);
309 return LT.first * 2 * OpCost;
310 return LT.first * 1 * OpCost;
316 return LT.first * 2 * OpCost;
322 unsigned Cost =
static_cast<T *
>(
this)
327 return getScalarizationOverhead(Ty,
true,
true) + Num * Cost;
337 return getAltShuffleOverhead(Tp);
345 assert(ISD &&
"Invalid opcode");
350 if (SrcLT.first == DstLT.first &&
351 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
354 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
358 if (Opcode == Instruction::Trunc &&
362 if (Opcode == Instruction::ZExt &&
367 if (SrcLT.first == DstLT.first &&
375 if (Opcode == Instruction::BitCast)
391 if (SrcLT.first == DstLT.first &&
392 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
395 if (Opcode == Instruction::ZExt)
399 if (Opcode == Instruction::SExt)
406 return SrcLT.first * 1;
418 return getScalarizationOverhead(Dst,
true,
true) + Num * Cost;
425 if (Opcode == Instruction::BitCast)
427 return (Src->
isVectorTy() ? getScalarizationOverhead(Src,
false,
true)
429 (Dst->
isVectorTy() ? getScalarizationOverhead(Dst,
true,
false)
443 assert(ISD &&
"Invalid opcode");
447 assert(CondTy &&
"CondTy must exist");
453 if (!(ValTy->
isVectorTy() && !LT.second.isVector()) &&
471 return getScalarizationOverhead(ValTy,
true,
false) + Num * Cost;
479 std::pair<unsigned, MVT>
LT =
487 assert(!Src->
isVoidTy() &&
"Invalid type");
491 unsigned Cost = LT.first;
524 assert(VT &&
"Expect a vector type for interleaved memory op");
527 assert(Factor > 1 && NumElts % Factor == 0 &&
"Invalid interleave factor");
529 unsigned NumSubElts = NumElts / Factor;
533 unsigned Cost =
getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace);
546 assert(Indices.
size() <= Factor &&
547 "Interleaved memory op has too many members");
548 for (
unsigned Index : Indices) {
549 assert(Index < Factor &&
"Invalid index for interleaved memory op");
552 for (
unsigned i = 0; i < NumSubElts; i++)
557 unsigned InsSubCost = 0;
558 for (
unsigned i = 0; i < NumSubElts; i++)
561 Cost += Indices.size() * InsSubCost;
572 unsigned ExtSubCost = 0;
573 for (
unsigned i = 0; i < NumSubElts; i++)
576 Cost += Factor * ExtSubCost;
578 for (
unsigned i = 0; i < NumElts; i++)
591 unsigned ScalarizationCost = 0;
592 unsigned ScalarCalls = 1;
593 Type *ScalarRetTy = RetTy;
595 ScalarizationCost = getScalarizationOverhead(RetTy,
true,
false);
600 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
603 ScalarizationCost += getScalarizationOverhead(Ty,
false,
true);
609 if (ScalarCalls == 1)
613 IID, ScalarRetTy, ScalarTys);
615 return ScalarCalls * ScalarCost + ScalarizationCost;
619 case Intrinsic::sqrt:
631 case Intrinsic::exp2:
637 case Intrinsic::log10:
640 case Intrinsic::log2:
643 case Intrinsic::fabs:
652 case Intrinsic::copysign:
655 case Intrinsic::floor:
658 case Intrinsic::ceil:
661 case Intrinsic::trunc:
664 case Intrinsic::nearbyint:
667 case Intrinsic::rint:
670 case Intrinsic::round:
679 case Intrinsic::fmuladd:
683 case Intrinsic::lifetime_start:
684 case Intrinsic::lifetime_end:
686 case Intrinsic::masked_store:
687 return static_cast<T *
>(
this)
689 case Intrinsic::masked_load:
690 return static_cast<T *
>(
this)
715 if (IID == Intrinsic::fmuladd)
716 return static_cast<T *
>(
this)
718 static_cast<T *
>(
this)
725 unsigned ScalarizationCost = getScalarizationOverhead(RetTy,
true,
false);
728 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
736 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
737 if (Tys[i]->isVectorTy()) {
738 ScalarizationCost += getScalarizationOverhead(Tys[i],
false,
true);
739 ScalarCalls = std::max(ScalarCalls, Tys[i]->getVectorNumElements());
743 return ScalarCalls * ScalarCost + ScalarizationCost;
773 assert(Ty->
isVectorTy() &&
"Expect a vector type");
775 unsigned NumReduxLevels =
Log2_32(NumVecElts);
780 unsigned ShuffleCost =
781 NumReduxLevels * (IsPairwise + 1) *
782 static_cast<T *>(
this)
784 return ShuffleCost + ArithCost + getScalarizationOverhead(Ty,
false,
true);
809 :
BaseT(std::move(static_cast<
BaseT &>(Arg))),
ST(std::move(Arg.
ST)),
810 TLI(std::move(Arg.TLI)) {}
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type * > ParamTys)
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type * > Tys)
virtual bool isLegalICmpImmediate(int64_t) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
BasicTTIImpl(const BasicTTIImpl &Arg)
BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL)
virtual bool isZExtFree(Type *, Type *) const
Return true if any actual instruction that defines a value of type Ty1 implicitly zero-extends the va...
bool isProfitableToHoist(Instruction *I)
unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys)
Compute a cost of the given call instruction.
Base class which can be used to help build a TTI implementation.
unsigned getMaxInterleaveFactor(unsigned VF)
iterator begin()
Instruction iterator methods.
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src)
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)
unsigned getJumpBufSize() const
Returns the target's jmp_buf size in bytes (if never set, the default is 200)
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)
unsigned getJumpBufSize()
unsigned getReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
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 ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
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...
unsigned getNumElements() const
Return the number of elements in the Vector type.
Type * getElementType() const
size_t size() const
size - Get the array size.
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 ...
unsigned getFPOpCost(Type *Ty)
bool isTruncateFree(Type *Ty1, Type *Ty2)
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy)
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Concrete BasicTTIImpl that can be used if no further customization is needed.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
unsigned getRegisterBitWidth(bool Vector)
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
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...
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
BasicTTIImpl(BasicTTIImpl &&Arg)
virtual bool isTruncateFree(Type *, Type *) const
Return true if it's free to truncate a value of type Ty1 to type Ty2.
BasicTTIImplBase(BasicTTIImplBase &&Arg)
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)
unsigned getNumberOfParts(Type *Tp)
BasicTTIImplBase(const BasicTTIImplBase &Arg)
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...
EVT - Extended Value Type.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
bool isLegalAddImmediate(int64_t imm)
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
unsigned getCFInstrCost(unsigned Opcode)
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
unsigned getNumberOfRegisters(bool Vector)
unsigned getVectorNumElements() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
cl::opt< unsigned > PartialUnrollingThreshold
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)
virtual bool isProfitableToHoist(Instruction *I) const
unsigned Log2_32(uint32_t Value)
Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
VectorType - Class to represent vector types.
Select(COND, TRUEVAL, FALSEVAL).
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::vector< BlockT * >::const_iterator block_iterator
unsigned LoopMicroOpBufferSize
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
TargetSubtargetInfo - Generic base class for all target subtargets.
block_iterator block_end() const
BR_JT - Jumptable branch.
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< const Value * > Arguments)
unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy)
bool hasBranchDivergence()
unsigned getJumpBufAlignment() const
Returns the target's jmp_buf alignment in bytes (if never set, the default is 0)
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
unsigned getJumpBufAlignment()
bool shouldBuildLookupTables()
ImmutableCallSite - establish a view to a call site for examination.
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
BasicTTIImpl(const TargetMachine *ST, Function &F)
unsigned getAddressComputationCost(Type *Ty, bool IsComplex)
const ARM::ArchExtKind Kind
bool isSimple() const
isSimple - Test if the given EVT is simple (as opposed to being extended).
bool isSourceOfDivergence(const Value *V)
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
FMA - Perform a * b + c with no intermediate rounding step.
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
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...
Primary interface to the complete machine description for the target machine.
bool isTypeLegal(Type *Ty)
block_iterator block_begin() const
bool haveFastSqrt(Type *Ty)
void getUnrollingPreferences(Loop *L, TTI::UnrollingPreferences &UP)
bool isLegalICmpImmediate(int64_t imm)
std::pair< unsigned, 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.
MVT getSimpleVT() const
getSimpleVT - Return the SimpleValueType held in the specified simple EVT.
This file describes how to lower LLVM code to machine code.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.