LLVM  4.0.0
TargetTransformInfoImpl.h
Go to the documentation of this file.
1 //===- TargetTransformInfoImpl.h --------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This file provides helpers for the implementation of
11 /// a TargetTransformInfo-conforming class.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
16 #define LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
17 
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/Function.h"
24 #include "llvm/IR/Operator.h"
25 #include "llvm/IR/Type.h"
27 
28 namespace llvm {
29 
30 /// \brief Base class for use as a mix-in that aids implementing
31 /// a TargetTransformInfo-compatible class.
33 protected:
35 
36  const DataLayout &DL;
37 
38  explicit TargetTransformInfoImplBase(const DataLayout &DL) : DL(DL) {}
39 
40 public:
41  // Provide value semantics. MSVC requires that we spell all of these out.
43  : DL(Arg.DL) {}
45 
46  const DataLayout &getDataLayout() const { return DL; }
47 
48  unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) {
49  switch (Opcode) {
50  default:
51  // By default, just classify everything as 'basic'.
52  return TTI::TCC_Basic;
53 
54  case Instruction::GetElementPtr:
55  llvm_unreachable("Use getGEPCost for GEP operations!");
56 
57  case Instruction::BitCast:
58  assert(OpTy && "Cast instructions must provide the operand type");
59  if (Ty == OpTy || (Ty->isPointerTy() && OpTy->isPointerTy()))
60  // Identity and pointer-to-pointer casts are free.
61  return TTI::TCC_Free;
62 
63  // Otherwise, the default basic cost is used.
64  return TTI::TCC_Basic;
65 
66  case Instruction::FDiv:
67  case Instruction::FRem:
68  case Instruction::SDiv:
69  case Instruction::SRem:
70  case Instruction::UDiv:
71  case Instruction::URem:
72  return TTI::TCC_Expensive;
73 
74  case Instruction::IntToPtr: {
75  // An inttoptr cast is free so long as the input is a legal integer type
76  // which doesn't contain values outside the range of a pointer.
77  unsigned OpSize = OpTy->getScalarSizeInBits();
78  if (DL.isLegalInteger(OpSize) &&
79  OpSize <= DL.getPointerTypeSizeInBits(Ty))
80  return TTI::TCC_Free;
81 
82  // Otherwise it's not a no-op.
83  return TTI::TCC_Basic;
84  }
85  case Instruction::PtrToInt: {
86  // A ptrtoint cast is free so long as the result is large enough to store
87  // the pointer, and a legal integer type.
88  unsigned DestSize = Ty->getScalarSizeInBits();
89  if (DL.isLegalInteger(DestSize) &&
90  DestSize >= DL.getPointerTypeSizeInBits(OpTy))
91  return TTI::TCC_Free;
92 
93  // Otherwise it's not a no-op.
94  return TTI::TCC_Basic;
95  }
96  case Instruction::Trunc:
97  // trunc to a native type is free (assuming the target has compare and
98  // shift-right of the same width).
100  return TTI::TCC_Free;
101 
102  return TTI::TCC_Basic;
103  }
104  }
105 
106  int getGEPCost(Type *PointeeType, const Value *Ptr,
107  ArrayRef<const Value *> Operands) {
108  // In the basic model, we just assume that all-constant GEPs will be folded
109  // into their uses via addressing modes.
110  for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
111  if (!isa<Constant>(Operands[Idx]))
112  return TTI::TCC_Basic;
113 
114  return TTI::TCC_Free;
115  }
116 
117  unsigned getCallCost(FunctionType *FTy, int NumArgs) {
118  assert(FTy && "FunctionType must be provided to this routine.");
119 
120  // The target-independent implementation just measures the size of the
121  // function by approximating that each argument will take on average one
122  // instruction to prepare.
123 
124  if (NumArgs < 0)
125  // Set the argument number to the number of explicit arguments in the
126  // function.
127  NumArgs = FTy->getNumParams();
128 
129  return TTI::TCC_Basic * (NumArgs + 1);
130  }
131 
132  unsigned getInliningThresholdMultiplier() { return 1; }
133 
134  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
135  ArrayRef<Type *> ParamTys) {
136  switch (IID) {
137  default:
138  // Intrinsics rarely (if ever) have normal argument setup constraints.
139  // Model them as having a basic instruction cost.
140  // FIXME: This is wrong for libc intrinsics.
141  return TTI::TCC_Basic;
142 
143  case Intrinsic::annotation:
144  case Intrinsic::assume:
145  case Intrinsic::dbg_declare:
146  case Intrinsic::dbg_value:
147  case Intrinsic::invariant_start:
148  case Intrinsic::invariant_end:
149  case Intrinsic::lifetime_start:
150  case Intrinsic::lifetime_end:
151  case Intrinsic::objectsize:
152  case Intrinsic::ptr_annotation:
153  case Intrinsic::var_annotation:
154  case Intrinsic::experimental_gc_result:
155  case Intrinsic::experimental_gc_relocate:
156  case Intrinsic::coro_alloc:
157  case Intrinsic::coro_begin:
158  case Intrinsic::coro_free:
159  case Intrinsic::coro_end:
160  case Intrinsic::coro_frame:
161  case Intrinsic::coro_size:
162  case Intrinsic::coro_suspend:
163  case Intrinsic::coro_param:
164  case Intrinsic::coro_subfn_addr:
165  // These intrinsics don't actually represent code after lowering.
166  return TTI::TCC_Free;
167  }
168  }
169 
170  bool hasBranchDivergence() { return false; }
171 
172  bool isSourceOfDivergence(const Value *V) { return false; }
173 
174  bool isLoweredToCall(const Function *F) {
175  // FIXME: These should almost certainly not be handled here, and instead
176  // handled with the help of TLI or the target itself. This was largely
177  // ported from existing analysis heuristics here so that such refactorings
178  // can take place in the future.
179 
180  if (F->isIntrinsic())
181  return false;
182 
183  if (F->hasLocalLinkage() || !F->hasName())
184  return true;
185 
186  StringRef Name = F->getName();
187 
188  // These will all likely lower to a single selection DAG node.
189  if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
190  Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" ||
191  Name == "fmin" || Name == "fminf" || Name == "fminl" ||
192  Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
193  Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" ||
194  Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl")
195  return false;
196 
197  // These are all likely to be optimized into something smaller.
198  if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
199  Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
200  Name == "floorf" || Name == "ceil" || Name == "round" ||
201  Name == "ffs" || Name == "ffsl" || Name == "abs" || Name == "labs" ||
202  Name == "llabs")
203  return false;
204 
205  return true;
206  }
207 
209 
210  bool isLegalAddImmediate(int64_t Imm) { return false; }
211 
212  bool isLegalICmpImmediate(int64_t Imm) { return false; }
213 
214  bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
215  bool HasBaseReg, int64_t Scale,
216  unsigned AddrSpace) {
217  // Guess that only reg and reg+reg addressing is allowed. This heuristic is
218  // taken from the implementation of LSR.
219  return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
220  }
221 
222  bool isLegalMaskedStore(Type *DataType) { return false; }
223 
224  bool isLegalMaskedLoad(Type *DataType) { return false; }
225 
226  bool isLegalMaskedScatter(Type *DataType) { return false; }
227 
228  bool isLegalMaskedGather(Type *DataType) { return false; }
229 
230  int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
231  bool HasBaseReg, int64_t Scale, unsigned AddrSpace) {
232  // Guess that all legal addressing mode are free.
233  if (isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
234  Scale, AddrSpace))
235  return 0;
236  return -1;
237  }
238 
239  bool isFoldableMemAccessOffset(Instruction *I, int64_t Offset) { return true; }
240 
241  bool isTruncateFree(Type *Ty1, Type *Ty2) { return false; }
242 
243  bool isProfitableToHoist(Instruction *I) { return true; }
244 
245  bool isTypeLegal(Type *Ty) { return false; }
246 
247  unsigned getJumpBufAlignment() { return 0; }
248 
249  unsigned getJumpBufSize() { return 0; }
250 
251  bool shouldBuildLookupTables() { return true; }
253 
254  bool enableAggressiveInterleaving(bool LoopHasReductions) { return false; }
255 
256  bool enableInterleavedAccessVectorization() { return false; }
257 
258  bool isFPVectorizationPotentiallyUnsafe() { return false; }
259 
261  unsigned BitWidth,
262  unsigned AddressSpace,
263  unsigned Alignment,
264  bool *Fast) { return false; }
265 
266  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) {
267  return TTI::PSK_Software;
268  }
269 
270  bool haveFastSqrt(Type *Ty) { return false; }
271 
273 
274  int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
275  Type *Ty) {
276  return 0;
277  }
278 
279  unsigned getIntImmCost(const APInt &Imm, Type *Ty) { return TTI::TCC_Basic; }
280 
281  unsigned getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
282  Type *Ty) {
283  return TTI::TCC_Free;
284  }
285 
286  unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
287  Type *Ty) {
288  return TTI::TCC_Free;
289  }
290 
291  unsigned getNumberOfRegisters(bool Vector) { return 8; }
292 
293  unsigned getRegisterBitWidth(bool Vector) { return 32; }
294 
295  unsigned getCacheLineSize() { return 0; }
296 
297  unsigned getPrefetchDistance() { return 0; }
298 
299  unsigned getMinPrefetchStride() { return 1; }
300 
301  unsigned getMaxPrefetchIterationsAhead() { return UINT_MAX; }
302 
303  unsigned getMaxInterleaveFactor(unsigned VF) { return 1; }
304 
305  unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
306  TTI::OperandValueKind Opd1Info,
307  TTI::OperandValueKind Opd2Info,
308  TTI::OperandValueProperties Opd1PropInfo,
309  TTI::OperandValueProperties Opd2PropInfo,
311  return 1;
312  }
313 
314  unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Ty, int Index,
315  Type *SubTp) {
316  return 1;
317  }
318 
319  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) { return 1; }
320 
321  unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst,
322  VectorType *VecTy, unsigned Index) {
323  return 1;
324  }
325 
326  unsigned getCFInstrCost(unsigned Opcode) { return 1; }
327 
328  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) {
329  return 1;
330  }
331 
332  unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {
333  return 1;
334  }
335 
336  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
337  unsigned AddressSpace) {
338  return 1;
339  }
340 
341  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
342  unsigned AddressSpace) {
343  return 1;
344  }
345 
346  unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
347  bool VariableMask,
348  unsigned Alignment) {
349  return 1;
350  }
351 
352  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
353  unsigned Factor,
354  ArrayRef<unsigned> Indices,
355  unsigned Alignment,
356  unsigned AddressSpace) {
357  return 1;
358  }
359 
361  ArrayRef<Type *> Tys, FastMathFlags FMF) {
362  return 1;
363  }
366  return 1;
367  }
368 
369  unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef<Type *> Tys) {
370  return 1;
371  }
372 
373  unsigned getNumberOfParts(Type *Tp) { return 0; }
374 
376  const SCEV *) {
377  return 0;
378  }
379 
380  unsigned getReductionCost(unsigned, Type *, bool) { return 1; }
381 
382  unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) { return 0; }
383 
385  return false;
386  }
387 
389  Type *ExpectedType) {
390  return nullptr;
391  }
392 
393  bool areInlineCompatible(const Function *Caller,
394  const Function *Callee) const {
395  return (Caller->getFnAttribute("target-cpu") ==
396  Callee->getFnAttribute("target-cpu")) &&
397  (Caller->getFnAttribute("target-features") ==
398  Callee->getFnAttribute("target-features"));
399  }
400 
401  unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const { return 128; }
402 
403  bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
404 
405  bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
406 
407  bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
408  unsigned Alignment,
409  unsigned AddrSpace) const {
410  return true;
411  }
412 
413  bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
414  unsigned Alignment,
415  unsigned AddrSpace) const {
416  return true;
417  }
418 
419  unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
420  unsigned ChainSizeInBytes,
421  VectorType *VecTy) const {
422  return VF;
423  }
424 
425  unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
426  unsigned ChainSizeInBytes,
427  VectorType *VecTy) const {
428  return VF;
429  }
430 protected:
431  // Obtain the minimum required size to hold the value (without the sign)
432  // In case of a vector it returns the min required size for one element.
433  unsigned minRequiredElementSize(const Value* Val, bool &isSigned) {
434  if (isa<ConstantDataVector>(Val) || isa<ConstantVector>(Val)) {
435  const auto* VectorValue = cast<Constant>(Val);
436 
437  // In case of a vector need to pick the max between the min
438  // required size for each element
439  auto *VT = cast<VectorType>(Val->getType());
440 
441  // Assume unsigned elements
442  isSigned = false;
443 
444  // The max required size is the total vector width divided by num
445  // of elements in the vector
446  unsigned MaxRequiredSize = VT->getBitWidth() / VT->getNumElements();
447 
448  unsigned MinRequiredSize = 0;
449  for(unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
450  if (auto* IntElement =
451  dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
452  bool signedElement = IntElement->getValue().isNegative();
453  // Get the element min required size.
454  unsigned ElementMinRequiredSize =
455  IntElement->getValue().getMinSignedBits() - 1;
456  // In case one element is signed then all the vector is signed.
457  isSigned |= signedElement;
458  // Save the max required bit size between all the elements.
459  MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
460  }
461  else {
462  // not an int constant element
463  return MaxRequiredSize;
464  }
465  }
466  return MinRequiredSize;
467  }
468 
469  if (const auto* CI = dyn_cast<ConstantInt>(Val)) {
470  isSigned = CI->getValue().isNegative();
471  return CI->getValue().getMinSignedBits() - 1;
472  }
473 
474  if (const auto* Cast = dyn_cast<SExtInst>(Val)) {
475  isSigned = true;
476  return Cast->getSrcTy()->getScalarSizeInBits() - 1;
477  }
478 
479  if (const auto* Cast = dyn_cast<ZExtInst>(Val)) {
480  isSigned = false;
481  return Cast->getSrcTy()->getScalarSizeInBits();
482  }
483 
484  isSigned = false;
485  return Val->getType()->getScalarSizeInBits();
486  }
487 
488  bool isStridedAccess(const SCEV *Ptr) {
489  return Ptr && isa<SCEVAddRecExpr>(Ptr);
490  }
491 
493  const SCEV *Ptr) {
494  if (!isStridedAccess(Ptr))
495  return nullptr;
496  const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
497  return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
498  }
499 
501  int64_t MergeDistance) {
502  const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
503  if (!Step)
504  return false;
505  APInt StrideVal = Step->getAPInt();
506  if (StrideVal.getBitWidth() > 64)
507  return false;
508  // FIXME: need to take absolute value for negtive stride case
509  return StrideVal.getSExtValue() < MergeDistance;
510  }
511 };
512 
513 /// \brief CRTP base class for use as a mix-in that aids implementing
514 /// a TargetTransformInfo-compatible class.
515 template <typename T>
517 private:
519 
520 protected:
522 
523 public:
524  using BaseT::getCallCost;
525 
526  unsigned getCallCost(const Function *F, int NumArgs) {
527  assert(F && "A concrete function must be provided to this routine.");
528 
529  if (NumArgs < 0)
530  // Set the argument number to the number of explicit arguments in the
531  // function.
532  NumArgs = F->arg_size();
533 
534  if (Intrinsic::ID IID = F->getIntrinsicID()) {
535  FunctionType *FTy = F->getFunctionType();
536  SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
537  return static_cast<T *>(this)
538  ->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
539  }
540 
541  if (!static_cast<T *>(this)->isLoweredToCall(F))
542  return TTI::TCC_Basic; // Give a basic cost if it will be lowered
543  // directly.
544 
545  return static_cast<T *>(this)->getCallCost(F->getFunctionType(), NumArgs);
546  }
547 
548  unsigned getCallCost(const Function *F, ArrayRef<const Value *> Arguments) {
549  // Simply delegate to generic handling of the call.
550  // FIXME: We should use instsimplify or something else to catch calls which
551  // will constant fold with these arguments.
552  return static_cast<T *>(this)->getCallCost(F, Arguments.size());
553  }
554 
555  using BaseT::getGEPCost;
556 
557  int getGEPCost(Type *PointeeType, const Value *Ptr,
558  ArrayRef<const Value *> Operands) {
559  const GlobalValue *BaseGV = nullptr;
560  if (Ptr != nullptr) {
561  // TODO: will remove this when pointers have an opaque type.
563  PointeeType &&
564  "explicit pointee type doesn't match operand's pointee type");
565  BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
566  }
567  bool HasBaseReg = (BaseGV == nullptr);
568  int64_t BaseOffset = 0;
569  int64_t Scale = 0;
570 
571  auto GTI = gep_type_begin(PointeeType, Operands);
572  Type *TargetType;
573  for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
574  TargetType = GTI.getIndexedType();
575  // We assume that the cost of Scalar GEP with constant index and the
576  // cost of Vector GEP with splat constant index are the same.
577  const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
578  if (!ConstIdx)
579  if (auto Splat = getSplatValue(*I))
580  ConstIdx = dyn_cast<ConstantInt>(Splat);
581  if (StructType *STy = GTI.getStructTypeOrNull()) {
582  // For structures the index is always splat or scalar constant
583  assert(ConstIdx && "Unexpected GEP index");
584  uint64_t Field = ConstIdx->getZExtValue();
585  BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
586  } else {
587  int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
588  if (ConstIdx)
589  BaseOffset += ConstIdx->getSExtValue() * ElementSize;
590  else {
591  // Needs scale register.
592  if (Scale != 0)
593  // No addressing mode takes two scale registers.
594  return TTI::TCC_Basic;
595  Scale = ElementSize;
596  }
597  }
598  }
599 
600  // Assumes the address space is 0 when Ptr is nullptr.
601  unsigned AS =
602  (Ptr == nullptr ? 0 : Ptr->getType()->getPointerAddressSpace());
603  if (static_cast<T *>(this)->isLegalAddressingMode(
604  TargetType, const_cast<GlobalValue *>(BaseGV), BaseOffset,
605  HasBaseReg, Scale, AS))
606  return TTI::TCC_Free;
607  return TTI::TCC_Basic;
608  }
609 
611 
612  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
613  ArrayRef<const Value *> Arguments) {
614  // Delegate to the generic intrinsic handling code. This mostly provides an
615  // opportunity for targets to (for example) special case the cost of
616  // certain intrinsics based on constants used as arguments.
617  SmallVector<Type *, 8> ParamTys;
618  ParamTys.reserve(Arguments.size());
619  for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx)
620  ParamTys.push_back(Arguments[Idx]->getType());
621  return static_cast<T *>(this)->getIntrinsicCost(IID, RetTy, ParamTys);
622  }
623 
624  unsigned getUserCost(const User *U) {
625  if (isa<PHINode>(U))
626  return TTI::TCC_Free; // Model all PHI nodes as free.
627 
628  if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
629  SmallVector<Value *, 4> Indices(GEP->idx_begin(), GEP->idx_end());
630  return static_cast<T *>(this)->getGEPCost(
631  GEP->getSourceElementType(), GEP->getPointerOperand(), Indices);
632  }
633 
634  if (auto CS = ImmutableCallSite(U)) {
635  const Function *F = CS.getCalledFunction();
636  if (!F) {
637  // Just use the called value type.
638  Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
639  return static_cast<T *>(this)
640  ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
641  }
642 
643  SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
644  return static_cast<T *>(this)->getCallCost(F, Arguments);
645  }
646 
647  if (const CastInst *CI = dyn_cast<CastInst>(U)) {
648  // Result of a cmp instruction is often extended (to be used by other
649  // cmp instructions, logical or return instructions). These are usually
650  // nop on most sane targets.
651  if (isa<CmpInst>(CI->getOperand(0)))
652  return TTI::TCC_Free;
653  }
654 
655  return static_cast<T *>(this)->getOperationCost(
656  Operator::getOpcode(U), U->getType(),
657  U->getNumOperands() == 1 ? U->getOperand(0)->getType() : nullptr);
658  }
659 };
660 }
661 
662 #endif
Base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class...
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
bool isConstantStridedAccessLessThan(ScalarEvolution *SE, const SCEV *Ptr, int64_t MergeDistance)
LLVMContext & Context
unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, bool VariableMask, unsigned Alignment)
bool hasName() const
Definition: Value.h:236
size_t i
unsigned minRequiredElementSize(const Value *Val, bool &isSigned)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:137
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
unsigned getNumOperands() const
Definition: User.h:167
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:617
unsigned getCallCost(const Function *F, ArrayRef< const Value * > Arguments)
The main scalar evolution driver.
iterator end() const
Definition: ArrayRef.h:130
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:151
unsigned getCallCost(const Function *F, int NumArgs)
unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy)
bool isFoldableMemAccessOffset(Instruction *I, int64_t Offset)
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)
unsigned getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:234
An instruction for reading from memory.
Definition: Instructions.h:164
Hexagon Common GEP
void reserve(size_type N)
Definition: SmallVector.h:377
unsigned getIntImmCost(const APInt &Imm, Type *Ty)
Type * getPointerElementType() const
Definition: Type.h:358
size_t arg_size() const
Definition: Function.cpp:327
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
CRTP base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class...
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info)
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:566
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:578
Class to represent struct types.
Definition: DerivedTypes.h:199
param_iterator param_end() const
Definition: DerivedTypes.h:127
int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef< const Value * > Args)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:154
bool isTruncateFree(Type *Ty1, Type *Ty2)
bool enableAggressiveInterleaving(bool LoopHasReductions)
Class to represent function types.
Definition: DerivedTypes.h:102
#define F(x, y, z)
Definition: MD5.cpp:51
This node represents a polynomial recurrence on the trip count of the specified loop.
PopcntSupportKind
Flags indicating the kind of support for population count.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF)
An instruction for storing to memory.
Definition: Instructions.h:300
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index)
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.cpp:44
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Type * > Tys, FastMathFlags FMF)
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:517
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Ty, int Index, Type *SubTp)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
TargetTransformInfoImplBase(const TargetTransformInfoImplBase &Arg)
This is an important base class in LLVM.
Definition: Constant.h:42
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1321
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
param_iterator param_begin() const
Definition: DerivedTypes.h:126
unsigned getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
Expected to fold away in lowering.
uint32_t Offset
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1255
iterator begin() const
Definition: ArrayRef.h:129
Value * getOperand(unsigned i) const
Definition: User.h:145
const APInt & getAPInt() const
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:213
unsigned getCallCost(FunctionType *FTy, int NumArgs)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const SCEVConstant * getConstantStrideStep(ScalarEvolution *SE, const SCEV *Ptr)
OperandValueProperties
Additional properties of an operand's values.
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< const Value * > Arguments)
int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:408
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:123
TargetTransformInfoImplBase(const DataLayout &DL)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
AddressSpace
Definition: NVPTXBaseInfo.h:22
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace, unsigned Alignment, bool *Fast)
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:490
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:146
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)
Class to represent vector types.
Definition: DerivedTypes.h:369
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type * > ParamTys)
Class for arbitrary precision integers.
Definition: APInt.h:77
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src)
const DataLayout & getDataLayout() const
bool isLegalToVectorizeLoad(LoadInst *LI) const
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:49
unsigned getReductionCost(unsigned, Type *, bool)
unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)
bool isLegalToVectorizeStore(StoreInst *SI) const
void getUnrollingPreferences(Loop *, TTI::UnrollingPreferences &)
unsigned getCFInstrCost(unsigned Opcode)
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
Parameters that control the generic loop unrolling transformation.
ImmutableCallSite - establish a view to a call site for examination.
Definition: CallSite.h:665
#define I(x, y, z)
Definition: MD5.cpp:54
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.cpp:230
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
unsigned getAddressComputationCost(Type *Tp, ScalarEvolution *, const SCEV *)
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)
bool hasLocalLinkage() const
Definition: GlobalValue.h:415
const unsigned Kind
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
TargetTransformInfoImplBase(TargetTransformInfoImplBase &&Arg)
Type * getReturnType() const
Definition: DerivedTypes.h:123
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
The cost of a typical 'add' instruction.
LLVM Value Representation.
Definition: Value.h:71
unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty)
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:533
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:168
OperandValueKind
Additional information about an operand's possible values.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy)
This pass exposes codegen information to IR-level passes.
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU...
Definition: DataLayout.h:242
int * Ptr
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition: Constants.h:162
unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:479
Information about a load/store intrinsic defined by the target.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
The cost of a 'div' instruction on x86.
int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands)
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit)
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType)
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
This class represents a constant integer value.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
gep_type_iterator gep_type_begin(const User *GEP)