18 #define DEBUG_TYPE "basictti"
33 unsigned getScalarizationOverhead(
Type *Ty,
bool Insert,
bool Extract)
const;
46 virtual void initializePass() {
50 virtual void finalizePass() {
62 virtual void *getAdjustedAnalysisPointer(
const void *
ID) {
68 virtual bool hasBranchDivergence()
const;
73 virtual bool isLegalAddImmediate(int64_t imm)
const;
74 virtual bool isLegalICmpImmediate(int64_t imm)
const;
76 int64_t BaseOffset,
bool HasBaseReg,
79 int64_t BaseOffset,
bool HasBaseReg,
81 virtual bool isTruncateFree(
Type *Ty1,
Type *Ty2)
const;
82 virtual bool isTypeLegal(
Type *Ty)
const;
83 virtual unsigned getJumpBufAlignment()
const;
84 virtual unsigned getJumpBufSize()
const;
85 virtual bool shouldBuildLookupTables()
const;
86 virtual bool haveFastSqrt(
Type *Ty)
const;
87 virtual void getUnrollingPreferences(
Loop *L, UnrollingPreferences &UP)
const;
94 virtual unsigned getNumberOfRegisters(
bool Vector)
const;
95 virtual unsigned getMaximumUnrollFactor()
const;
96 virtual unsigned getRegisterBitWidth(
bool Vector)
const;
97 virtual unsigned getArithmeticInstrCost(
unsigned Opcode,
Type *Ty,
99 OperandValueKind)
const;
100 virtual unsigned getShuffleCost(ShuffleKind
Kind,
Type *Tp,
101 int Index,
Type *SubTp)
const;
102 virtual unsigned getCastInstrCost(
unsigned Opcode,
Type *Dst,
104 virtual unsigned getCFInstrCost(
unsigned Opcode)
const;
105 virtual unsigned getCmpSelInstrCost(
unsigned Opcode,
Type *ValTy,
107 virtual unsigned getVectorInstrCost(
unsigned Opcode,
Type *Val,
108 unsigned Index)
const;
109 virtual unsigned getMemoryOpCost(
unsigned Opcode,
Type *Src,
114 virtual unsigned getNumberOfParts(
Type *Tp)
const;
115 virtual unsigned getAddressComputationCost(
Type *Ty,
bool IsComplex)
const;
116 virtual unsigned getReductionCost(
unsigned Opcode,
Type *Ty,
bool IsPairwise)
const;
124 "Target independent code generator's TTI",
true,
true,
false)
125 char BasicTTI::
ID = 0;
129 return new BasicTTI(TM);
132 bool BasicTTI::hasBranchDivergence()
const {
return false; }
134 bool BasicTTI::isLegalAddImmediate(int64_t imm)
const {
135 return getTLI()->isLegalAddImmediate(imm);
138 bool BasicTTI::isLegalICmpImmediate(int64_t imm)
const {
139 return getTLI()->isLegalICmpImmediate(imm);
143 int64_t BaseOffset,
bool HasBaseReg,
144 int64_t Scale)
const {
150 return getTLI()->isLegalAddressingMode(AM, Ty);
154 int64_t BaseOffset,
bool HasBaseReg,
155 int64_t Scale)
const {
161 return getTLI()->getScalingFactorCost(AM, Ty);
164 bool BasicTTI::isTruncateFree(
Type *Ty1,
Type *Ty2)
const {
165 return getTLI()->isTruncateFree(Ty1, Ty2);
168 bool BasicTTI::isTypeLegal(
Type *Ty)
const {
169 EVT T = getTLI()->getValueType(Ty);
170 return getTLI()->isTypeLegal(T);
173 unsigned BasicTTI::getJumpBufAlignment()
const {
174 return getTLI()->getJumpBufAlignment();
177 unsigned BasicTTI::getJumpBufSize()
const {
178 return getTLI()->getJumpBufSize();
181 bool BasicTTI::shouldBuildLookupTables()
const {
188 bool BasicTTI::haveFastSqrt(
Type *Ty)
const {
194 void BasicTTI::getUnrollingPreferences(
Loop *, UnrollingPreferences &)
const { }
202 unsigned BasicTTI::getScalarizationOverhead(
Type *Ty,
bool Insert,
203 bool Extract)
const {
204 assert (Ty->
isVectorTy() &&
"Can only scalarize vectors");
209 Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
217 unsigned BasicTTI::getNumberOfRegisters(
bool Vector)
const {
221 unsigned BasicTTI::getRegisterBitWidth(
bool Vector)
const {
225 unsigned BasicTTI::getMaximumUnrollFactor()
const {
229 unsigned BasicTTI::getArithmeticInstrCost(
unsigned Opcode,
Type *Ty,
231 OperandValueKind)
const {
235 assert(ISD &&
"Invalid opcode");
242 unsigned OpCost = (IsFloat ? 2 : 1);
250 return LT.first * 2 * OpCost;
251 return LT.first * 1 * OpCost;
257 return LT.first * 2 * OpCost;
263 unsigned Cost = TopTTI->getArithmeticInstrCost(Opcode, Ty->
getScalarType());
266 return getScalarizationOverhead(Ty,
true,
true) + Num * Cost;
273 unsigned BasicTTI::getShuffleCost(ShuffleKind
Kind,
Type *Tp,
int Index,
278 unsigned BasicTTI::getCastInstrCost(
unsigned Opcode,
Type *Dst,
282 assert(ISD &&
"Invalid opcode");
288 if (SrcLT.first == DstLT.first &&
289 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
292 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
296 if (Opcode == Instruction::Trunc &&
300 if (Opcode == Instruction::ZExt &&
312 if (Opcode == Instruction::BitCast)
327 if (SrcLT.first == DstLT.first &&
328 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
331 if (Opcode == Instruction::ZExt)
335 if (Opcode == Instruction::SExt)
341 return SrcLT.first * 1;
348 unsigned Cost = TopTTI->getCastInstrCost(Opcode, Dst->
getScalarType(),
353 return getScalarizationOverhead(Dst,
true,
true) + Num * Cost;
359 if (Opcode == Instruction::BitCast)
361 return (Src->
isVectorTy()? getScalarizationOverhead(Src,
false,
true):0) +
362 (Dst->isVectorTy()? getScalarizationOverhead(Dst,
true,
false):0);
367 unsigned BasicTTI::getCFInstrCost(
unsigned Opcode)
const {
372 unsigned BasicTTI::getCmpSelInstrCost(
unsigned Opcode,
Type *ValTy,
373 Type *CondTy)
const {
376 assert(ISD &&
"Invalid opcode");
380 assert(CondTy &&
"CondTy must exist");
398 unsigned Cost = TopTTI->getCmpSelInstrCost(Opcode, ValTy->
getScalarType(),
403 return getScalarizationOverhead(ValTy,
true,
false) + Num * Cost;
410 unsigned BasicTTI::getVectorInstrCost(
unsigned Opcode,
Type *Val,
411 unsigned Index)
const {
415 unsigned BasicTTI::getMemoryOpCost(
unsigned Opcode,
Type *Src,
418 assert(!Src->
isVoidTy() &&
"Invalid type");
419 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Src);
431 unsigned ScalarizationCost = 0;
432 unsigned ScalarCalls = 1;
434 ScalarizationCost = getScalarizationOverhead(RetTy,
true,
false);
437 for (
unsigned i = 0, ie = Tys.
size(); i != ie; ++i) {
438 if (Tys[i]->isVectorTy()) {
439 ScalarizationCost += getScalarizationOverhead(Tys[i],
false,
true);
444 return ScalarCalls + ScalarizationCost;
497 unsigned Cost = TopTTI->getIntrinsicInstrCost(IID, RetTy->
getScalarType(),
499 return 10 * Cost * Num;
506 unsigned BasicTTI::getNumberOfParts(
Type *Tp)
const {
507 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Tp);
511 unsigned BasicTTI::getAddressComputationCost(
Type *Ty,
bool IsComplex)
const {
515 unsigned BasicTTI::getReductionCost(
unsigned Opcode,
Type *Ty,
516 bool IsPairwise)
const {
517 assert(Ty->
isVectorTy() &&
"Expect a vector type");
519 unsigned NumReduxLevels =
Log2_32(NumVecElts);
520 unsigned ArithCost = NumReduxLevels *
521 TopTTI->getArithmeticInstrCost(Opcode, Ty);
523 unsigned ShuffleCost =
524 NumReduxLevels * (IsPairwise + 1) *
525 TopTTI->getShuffleCost(SK_ExtractSubvector, Ty, NumVecElts / 2, Ty);
526 return ShuffleCost + ArithCost + getScalarizationOverhead(Ty,
false,
true);
static PassRegistry * getPassRegistry()
ImmutablePass * createBasicTargetTransformInfoPass(const TargetMachine *TM)
Create a basic TargetTransformInfo analysis pass.
virtual bool isZExtFree(Type *, Type *) const
bool supportJumpTables() const
Return whether the target can generate code for jump tables.
EVT getValueType(Type *Ty, bool AllowUnknown=false) const
#define llvm_unreachable(msg)
void initializeBasicTTIPass(PassRegistry &)
static unsigned getScalingFactorCost(const TargetTransformInfo &TTI, const LSRUse &LU, const Formula &F)
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
ID
LLVM Calling Convention Representation.
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
bool isFloatingPointTy() const
bool isOperationLegalOrPromote(unsigned Op, EVT VT) const
size_t size() const
size - Get the array size.
bool isTypeLegal(EVT VT) const
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
virtual bool isTruncateFree(Type *, Type *) const
#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def)
unsigned getVectorNumElements() const
unsigned Log2_32(uint32_t Value)
const Type * getScalarType() const
bool isOperationExpand(unsigned Op, EVT VT) const
std::pair< unsigned, MVT > getTypeLegalizationCost(Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.