LLVM  10.0.0
TargetTransformInfo.cpp
Go to the documentation of this file.
1 //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/Analysis/CFG.h"
13 #include "llvm/IR/CFG.h"
14 #include "llvm/IR/CallSite.h"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/Instruction.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/Operator.h"
21 #include "llvm/IR/PatternMatch.h"
22 #include "llvm/InitializePasses.h"
25 #include <utility>
26 
27 using namespace llvm;
28 using namespace PatternMatch;
29 
30 #define DEBUG_TYPE "tti"
31 
32 static cl::opt<bool> EnableReduxCost("costmodel-reduxcost", cl::init(false),
33  cl::Hidden,
34  cl::desc("Recognize reduction patterns."));
35 
36 namespace {
37 /// No-op implementation of the TTI interface using the utility base
38 /// classes.
39 ///
40 /// This is used when no target specific information is available.
41 struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
42  explicit NoTTIImpl(const DataLayout &DL)
43  : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
44 };
45 }
46 
48  // If the loop has irreducible control flow, it can not be converted to
49  // Hardware loop.
50  LoopBlocksRPO RPOT(L);
51  RPOT.perform(&LI);
52  if (containsIrreducibleCFG<const BasicBlock *>(RPOT, LI))
53  return false;
54  return true;
55 }
56 
58  LoopInfo &LI, DominatorTree &DT,
59  bool ForceNestedLoop,
60  bool ForceHardwareLoopPHI) {
61  SmallVector<BasicBlock *, 4> ExitingBlocks;
62  L->getExitingBlocks(ExitingBlocks);
63 
64  for (BasicBlock *BB : ExitingBlocks) {
65  // If we pass the updated counter back through a phi, we need to know
66  // which latch the updated value will be coming from.
67  if (!L->isLoopLatch(BB)) {
68  if (ForceHardwareLoopPHI || CounterInReg)
69  continue;
70  }
71 
72  const SCEV *EC = SE.getExitCount(L, BB);
73  if (isa<SCEVCouldNotCompute>(EC))
74  continue;
75  if (const SCEVConstant *ConstEC = dyn_cast<SCEVConstant>(EC)) {
76  if (ConstEC->getValue()->isZero())
77  continue;
78  } else if (!SE.isLoopInvariant(EC, L))
79  continue;
80 
81  if (SE.getTypeSizeInBits(EC->getType()) > CountType->getBitWidth())
82  continue;
83 
84  // If this exiting block is contained in a nested loop, it is not eligible
85  // for insertion of the branch-and-decrement since the inner loop would
86  // end up messing up the value in the CTR.
87  if (!IsNestingLegal && LI.getLoopFor(BB) != L && !ForceNestedLoop)
88  continue;
89 
90  // We now have a loop-invariant count of loop iterations (which is not the
91  // constant zero) for which we know that this loop will not exit via this
92  // existing block.
93 
94  // We need to make sure that this block will run on every loop iteration.
95  // For this to be true, we must dominate all blocks with backedges. Such
96  // blocks are in-loop predecessors to the header block.
97  bool NotAlways = false;
98  for (BasicBlock *Pred : predecessors(L->getHeader())) {
99  if (!L->contains(Pred))
100  continue;
101 
102  if (!DT.dominates(BB, Pred)) {
103  NotAlways = true;
104  break;
105  }
106  }
107 
108  if (NotAlways)
109  continue;
110 
111  // Make sure this blocks ends with a conditional branch.
112  Instruction *TI = BB->getTerminator();
113  if (!TI)
114  continue;
115 
116  if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
117  if (!BI->isConditional())
118  continue;
119 
120  ExitBranch = BI;
121  } else
122  continue;
123 
124  // Note that this block may not be the loop latch block, even if the loop
125  // has a latch block.
126  ExitBlock = BB;
127  ExitCount = EC;
128  break;
129  }
130 
131  if (!ExitBlock)
132  return false;
133  return true;
134 }
135 
137  : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
138 
140 
142  : TTIImpl(std::move(Arg.TTIImpl)) {}
143 
145  TTIImpl = std::move(RHS.TTIImpl);
146  return *this;
147 }
148 
150  Type *OpTy) const {
151  int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
152  assert(Cost >= 0 && "TTI should not produce negative costs!");
153  return Cost;
154 }
155 
157  const User *U) const {
158  int Cost = TTIImpl->getCallCost(FTy, NumArgs, U);
159  assert(Cost >= 0 && "TTI should not produce negative costs!");
160  return Cost;
161 }
162 
165  const User *U) const {
166  int Cost = TTIImpl->getCallCost(F, Arguments, U);
167  assert(Cost >= 0 && "TTI should not produce negative costs!");
168  return Cost;
169 }
170 
172  return TTIImpl->getInliningThresholdMultiplier();
173 }
174 
176  return TTIImpl->getInlinerVectorBonusPercent();
177 }
178 
179 int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
181  return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
182 }
183 
185  const Value *Src) const {
186  return TTIImpl->getExtCost(I, Src);
187 }
188 
191  const User *U) const {
192  int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments, U);
193  assert(Cost >= 0 && "TTI should not produce negative costs!");
194  return Cost;
195 }
196 
197 unsigned
199  const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI,
200  BlockFrequencyInfo *BFI) const {
201  return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
202 }
203 
206  int Cost = TTIImpl->getUserCost(U, Operands);
207  assert(Cost >= 0 && "TTI should not produce negative costs!");
208  return Cost;
209 }
210 
212  return TTIImpl->hasBranchDivergence();
213 }
214 
216  return TTIImpl->isSourceOfDivergence(V);
217 }
218 
220  return TTIImpl->isAlwaysUniform(V);
221 }
222 
224  return TTIImpl->getFlatAddressSpace();
225 }
226 
228  SmallVectorImpl<int> &OpIndexes, Intrinsic::ID IID) const {
229  return TTIImpl->collectFlatAddressOperands(OpIndexes, IID);
230 }
231 
233  IntrinsicInst *II, Value *OldV, Value *NewV) const {
234  return TTIImpl->rewriteIntrinsicWithAddressSpace(II, OldV, NewV);
235 }
236 
238  return TTIImpl->isLoweredToCall(F);
239 }
240 
242  Loop *L, ScalarEvolution &SE, AssumptionCache &AC,
243  TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const {
244  return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
245 }
246 
249  DominatorTree *DT, const LoopAccessInfo *LAI) const {
250  return TTIImpl->preferPredicateOverEpilogue(L, LI, SE, AC, TLI, DT, LAI);
251 }
252 
254  Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
255  return TTIImpl->getUnrollingPreferences(L, SE, UP);
256 }
257 
259  return TTIImpl->isLegalAddImmediate(Imm);
260 }
261 
263  return TTIImpl->isLegalICmpImmediate(Imm);
264 }
265 
267  int64_t BaseOffset,
268  bool HasBaseReg,
269  int64_t Scale,
270  unsigned AddrSpace,
271  Instruction *I) const {
272  return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
273  Scale, AddrSpace, I);
274 }
275 
277  return TTIImpl->isLSRCostLess(C1, C2);
278 }
279 
281  return TTIImpl->canMacroFuseCmp();
282 }
283 
285  ScalarEvolution *SE, LoopInfo *LI,
287  TargetLibraryInfo *LibInfo) const {
288  return TTIImpl->canSaveCmp(L, BI, SE, LI, DT, AC, LibInfo);
289 }
290 
292  return TTIImpl->shouldFavorPostInc();
293 }
294 
296  return TTIImpl->shouldFavorBackedgeIndex(L);
297 }
298 
300  MaybeAlign Alignment) const {
301  return TTIImpl->isLegalMaskedStore(DataType, Alignment);
302 }
303 
305  MaybeAlign Alignment) const {
306  return TTIImpl->isLegalMaskedLoad(DataType, Alignment);
307 }
308 
310  Align Alignment) const {
311  return TTIImpl->isLegalNTStore(DataType, Alignment);
312 }
313 
315  return TTIImpl->isLegalNTLoad(DataType, Alignment);
316 }
317 
319  MaybeAlign Alignment) const {
320  return TTIImpl->isLegalMaskedGather(DataType, Alignment);
321 }
322 
324  MaybeAlign Alignment) const {
325  return TTIImpl->isLegalMaskedScatter(DataType, Alignment);
326 }
327 
329  return TTIImpl->isLegalMaskedCompressStore(DataType);
330 }
331 
333  return TTIImpl->isLegalMaskedExpandLoad(DataType);
334 }
335 
336 bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const {
337  return TTIImpl->hasDivRemOp(DataType, IsSigned);
338 }
339 
341  unsigned AddrSpace) const {
342  return TTIImpl->hasVolatileVariant(I, AddrSpace);
343 }
344 
346  return TTIImpl->prefersVectorizedAddressing();
347 }
348 
350  int64_t BaseOffset,
351  bool HasBaseReg,
352  int64_t Scale,
353  unsigned AddrSpace) const {
354  int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
355  Scale, AddrSpace);
356  assert(Cost >= 0 && "TTI should not produce negative costs!");
357  return Cost;
358 }
359 
361  return TTIImpl->LSRWithInstrQueries();
362 }
363 
365  return TTIImpl->isTruncateFree(Ty1, Ty2);
366 }
367 
369  return TTIImpl->isProfitableToHoist(I);
370 }
371 
372 bool TargetTransformInfo::useAA() const { return TTIImpl->useAA(); }
373 
375  return TTIImpl->isTypeLegal(Ty);
376 }
377 
379  return TTIImpl->shouldBuildLookupTables();
380 }
382  return TTIImpl->shouldBuildLookupTablesForConstant(C);
383 }
384 
386  return TTIImpl->useColdCCForColdCall(F);
387 }
388 
389 unsigned TargetTransformInfo::
390 getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
391  return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
392 }
393 
394 unsigned TargetTransformInfo::
396  unsigned VF) const {
397  return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
398 }
399 
401  return TTIImpl->supportsEfficientVectorElementLoadStore();
402 }
403 
404 bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
405  return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
406 }
407 
409 TargetTransformInfo::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
410  return TTIImpl->enableMemCmpExpansion(OptSize, IsZeroCmp);
411 }
412 
414  return TTIImpl->enableInterleavedAccessVectorization();
415 }
416 
418  return TTIImpl->enableMaskedInterleavedAccessVectorization();
419 }
420 
422  return TTIImpl->isFPVectorizationPotentiallyUnsafe();
423 }
424 
426  unsigned BitWidth,
427  unsigned AddressSpace,
428  unsigned Alignment,
429  bool *Fast) const {
430  return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
431  Alignment, Fast);
432 }
433 
435 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
436  return TTIImpl->getPopcntSupport(IntTyWidthInBit);
437 }
438 
440  return TTIImpl->haveFastSqrt(Ty);
441 }
442 
444  return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
445 }
446 
448  int Cost = TTIImpl->getFPOpCost(Ty);
449  assert(Cost >= 0 && "TTI should not produce negative costs!");
450  return Cost;
451 }
452 
453 int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
454  const APInt &Imm,
455  Type *Ty) const {
456  int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
457  assert(Cost >= 0 && "TTI should not produce negative costs!");
458  return Cost;
459 }
460 
461 int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
462  int Cost = TTIImpl->getIntImmCost(Imm, Ty);
463  assert(Cost >= 0 && "TTI should not produce negative costs!");
464  return Cost;
465 }
466 
467 int TargetTransformInfo::getIntImmCostInst(unsigned Opcode, unsigned Idx,
468  const APInt &Imm, Type *Ty) const {
469  int Cost = TTIImpl->getIntImmCostInst(Opcode, Idx, Imm, Ty);
470  assert(Cost >= 0 && "TTI should not produce negative costs!");
471  return Cost;
472 }
473 
475  const APInt &Imm, Type *Ty) const {
476  int Cost = TTIImpl->getIntImmCostIntrin(IID, Idx, Imm, Ty);
477  assert(Cost >= 0 && "TTI should not produce negative costs!");
478  return Cost;
479 }
480 
481 unsigned TargetTransformInfo::getNumberOfRegisters(unsigned ClassID) const {
482  return TTIImpl->getNumberOfRegisters(ClassID);
483 }
484 
486  return TTIImpl->getRegisterClassForType(Vector, Ty);
487 }
488 
489 const char* TargetTransformInfo::getRegisterClassName(unsigned ClassID) const {
490  return TTIImpl->getRegisterClassName(ClassID);
491 }
492 
494  return TTIImpl->getRegisterBitWidth(Vector);
495 }
496 
498  return TTIImpl->getMinVectorRegisterBitWidth();
499 }
500 
502  return TTIImpl->shouldMaximizeVectorBandwidth(OptSize);
503 }
504 
505 unsigned TargetTransformInfo::getMinimumVF(unsigned ElemWidth) const {
506  return TTIImpl->getMinimumVF(ElemWidth);
507 }
508 
510  const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
511  return TTIImpl->shouldConsiderAddressTypePromotion(
512  I, AllowPromotionWithoutCommonHeader);
513 }
514 
516  return TTIImpl->getCacheLineSize();
517 }
518 
520  const {
521  return TTIImpl->getCacheSize(Level);
522 }
523 
525  CacheLevel Level) const {
526  return TTIImpl->getCacheAssociativity(Level);
527 }
528 
530  return TTIImpl->getPrefetchDistance();
531 }
532 
534  return TTIImpl->getMinPrefetchStride();
535 }
536 
538  return TTIImpl->getMaxPrefetchIterationsAhead();
539 }
540 
541 unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
542  return TTIImpl->getMaxInterleaveFactor(VF);
543 }
544 
547  OperandValueKind OpInfo = OK_AnyValue;
548  OpProps = OP_None;
549 
550  if (auto *CI = dyn_cast<ConstantInt>(V)) {
551  if (CI->getValue().isPowerOf2())
552  OpProps = OP_PowerOf2;
554  }
555 
556  // A broadcast shuffle creates a uniform value.
557  // TODO: Add support for non-zero index broadcasts.
558  // TODO: Add support for different source vector width.
559  if (auto *ShuffleInst = dyn_cast<ShuffleVectorInst>(V))
560  if (ShuffleInst->isZeroEltSplat())
561  OpInfo = OK_UniformValue;
562 
563  const Value *Splat = getSplatValue(V);
564 
565  // Check for a splat of a constant or for a non uniform vector of constants
566  // and check if the constant(s) are all powers of two.
567  if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
569  if (Splat) {
570  OpInfo = OK_UniformConstantValue;
571  if (auto *CI = dyn_cast<ConstantInt>(Splat))
572  if (CI->getValue().isPowerOf2())
573  OpProps = OP_PowerOf2;
574  } else if (auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
575  OpProps = OP_PowerOf2;
576  for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
577  if (auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
578  if (CI->getValue().isPowerOf2())
579  continue;
580  OpProps = OP_None;
581  break;
582  }
583  }
584  }
585 
586  // Check for a splat of a uniform value. This is not loop aware, so return
587  // true only for the obviously uniform cases (argument, globalvalue)
588  if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
589  OpInfo = OK_UniformValue;
590 
591  return OpInfo;
592 }
593 
595  unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
596  OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
598  const Instruction *CxtI) const {
599  int Cost = TTIImpl->getArithmeticInstrCost(
600  Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo, Args, CxtI);
601  assert(Cost >= 0 && "TTI should not produce negative costs!");
602  return Cost;
603 }
604 
606  Type *SubTp) const {
607  int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
608  assert(Cost >= 0 && "TTI should not produce negative costs!");
609  return Cost;
610 }
611 
612 int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
613  Type *Src, const Instruction *I) const {
614  assert ((I == nullptr || I->getOpcode() == Opcode) &&
615  "Opcode should reflect passed instruction.");
616  int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
617  assert(Cost >= 0 && "TTI should not produce negative costs!");
618  return Cost;
619 }
620 
622  VectorType *VecTy,
623  unsigned Index) const {
624  int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
625  assert(Cost >= 0 && "TTI should not produce negative costs!");
626  return Cost;
627 }
628 
629 int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
630  int Cost = TTIImpl->getCFInstrCost(Opcode);
631  assert(Cost >= 0 && "TTI should not produce negative costs!");
632  return Cost;
633 }
634 
635 int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
636  Type *CondTy, const Instruction *I) const {
637  assert ((I == nullptr || I->getOpcode() == Opcode) &&
638  "Opcode should reflect passed instruction.");
639  int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
640  assert(Cost >= 0 && "TTI should not produce negative costs!");
641  return Cost;
642 }
643 
645  unsigned Index) const {
646  int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
647  assert(Cost >= 0 && "TTI should not produce negative costs!");
648  return Cost;
649 }
650 
651 int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
652  MaybeAlign Alignment,
653  unsigned AddressSpace,
654  const Instruction *I) const {
655  assert ((I == nullptr || I->getOpcode() == Opcode) &&
656  "Opcode should reflect passed instruction.");
657  int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
658  assert(Cost >= 0 && "TTI should not produce negative costs!");
659  return Cost;
660 }
661 
663  unsigned Alignment,
664  unsigned AddressSpace) const {
665  int Cost =
666  TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
667  assert(Cost >= 0 && "TTI should not produce negative costs!");
668  return Cost;
669 }
670 
672  Value *Ptr, bool VariableMask,
673  unsigned Alignment) const {
674  int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
675  Alignment);
676  assert(Cost >= 0 && "TTI should not produce negative costs!");
677  return Cost;
678 }
679 
681  unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
682  unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond,
683  bool UseMaskForGaps) const {
684  int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
685  Alignment, AddressSpace,
686  UseMaskForCond,
687  UseMaskForGaps);
688  assert(Cost >= 0 && "TTI should not produce negative costs!");
689  return Cost;
690 }
691 
694  unsigned ScalarizationCostPassed) const {
695  int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
696  ScalarizationCostPassed);
697  assert(Cost >= 0 && "TTI should not produce negative costs!");
698  return Cost;
699 }
700 
702  ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
703  int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
704  assert(Cost >= 0 && "TTI should not produce negative costs!");
705  return Cost;
706 }
707 
709  ArrayRef<Type *> Tys) const {
710  int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
711  assert(Cost >= 0 && "TTI should not produce negative costs!");
712  return Cost;
713 }
714 
716  return TTIImpl->getNumberOfParts(Tp);
717 }
718 
720  ScalarEvolution *SE,
721  const SCEV *Ptr) const {
722  int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
723  assert(Cost >= 0 && "TTI should not produce negative costs!");
724  return Cost;
725 }
726 
728  int Cost = TTIImpl->getMemcpyCost(I);
729  assert(Cost >= 0 && "TTI should not produce negative costs!");
730  return Cost;
731 }
732 
734  bool IsPairwiseForm) const {
735  int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm);
736  assert(Cost >= 0 && "TTI should not produce negative costs!");
737  return Cost;
738 }
739 
741  bool IsPairwiseForm,
742  bool IsUnsigned) const {
743  int Cost =
744  TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned);
745  assert(Cost >= 0 && "TTI should not produce negative costs!");
746  return Cost;
747 }
748 
749 unsigned
751  return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
752 }
753 
755  MemIntrinsicInfo &Info) const {
756  return TTIImpl->getTgtMemIntrinsic(Inst, Info);
757 }
758 
760  return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
761 }
762 
764  IntrinsicInst *Inst, Type *ExpectedType) const {
765  return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
766 }
767 
769  Value *Length,
770  unsigned SrcAlign,
771  unsigned DestAlign) const {
772  return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
773  DestAlign);
774 }
775 
778  unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
779  TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
780  SrcAlign, DestAlign);
781 }
782 
784  const Function *Callee) const {
785  return TTIImpl->areInlineCompatible(Caller, Callee);
786 }
787 
789  const Function *Caller, const Function *Callee,
791  return TTIImpl->areFunctionArgsABICompatible(Caller, Callee, Args);
792 }
793 
795  Type *Ty) const {
796  return TTIImpl->isIndexedLoadLegal(Mode, Ty);
797 }
798 
800  Type *Ty) const {
801  return TTIImpl->isIndexedStoreLegal(Mode, Ty);
802 }
803 
805  return TTIImpl->getLoadStoreVecRegBitWidth(AS);
806 }
807 
809  return TTIImpl->isLegalToVectorizeLoad(LI);
810 }
811 
813  return TTIImpl->isLegalToVectorizeStore(SI);
814 }
815 
817  unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
818  return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
819  AddrSpace);
820 }
821 
823  unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
824  return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
825  AddrSpace);
826 }
827 
829  unsigned LoadSize,
830  unsigned ChainSizeInBytes,
831  VectorType *VecTy) const {
832  return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
833 }
834 
836  unsigned StoreSize,
837  unsigned ChainSizeInBytes,
838  VectorType *VecTy) const {
839  return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
840 }
841 
843  Type *Ty, ReductionFlags Flags) const {
844  return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
845 }
846 
848  return TTIImpl->shouldExpandReduction(II);
849 }
850 
852  return TTIImpl->getGISelRematGlobalCost();
853 }
854 
855 int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
856  return TTIImpl->getInstructionLatency(I);
857 }
858 
860  unsigned Level) {
861  // We don't need a shuffle if we just want to have element 0 in position 0 of
862  // the vector.
863  if (!SI && Level == 0 && IsLeft)
864  return true;
865  else if (!SI)
866  return false;
867 
869 
870  // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether
871  // we look at the left or right side.
872  for (unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2)
873  Mask[i] = val;
874 
875  SmallVector<int, 16> ActualMask = SI->getShuffleMask();
876  return Mask == ActualMask;
877 }
878 
879 namespace {
880 /// Kind of the reduction data.
882  RK_None, /// Not a reduction.
883  RK_Arithmetic, /// Binary reduction data.
884  RK_MinMax, /// Min/max reduction data.
885  RK_UnsignedMinMax, /// Unsigned min/max reduction data.
886 };
887 /// Contains opcode + LHS/RHS parts of the reduction operations.
888 struct ReductionData {
889  ReductionData() = delete;
890  ReductionData(ReductionKind Kind, unsigned Opcode, Value *LHS, Value *RHS)
891  : Opcode(Opcode), LHS(LHS), RHS(RHS), Kind(Kind) {
892  assert(Kind != RK_None && "expected binary or min/max reduction only.");
893  }
894  unsigned Opcode = 0;
895  Value *LHS = nullptr;
896  Value *RHS = nullptr;
897  ReductionKind Kind = RK_None;
898  bool hasSameData(ReductionData &RD) const {
899  return Kind == RD.Kind && Opcode == RD.Opcode;
900  }
901 };
902 } // namespace
903 
905  Value *L, *R;
906  if (m_BinOp(m_Value(L), m_Value(R)).match(I))
907  return ReductionData(RK_Arithmetic, I->getOpcode(), L, R);
908  if (auto *SI = dyn_cast<SelectInst>(I)) {
909  if (m_SMin(m_Value(L), m_Value(R)).match(SI) ||
910  m_SMax(m_Value(L), m_Value(R)).match(SI) ||
911  m_OrdFMin(m_Value(L), m_Value(R)).match(SI) ||
912  m_OrdFMax(m_Value(L), m_Value(R)).match(SI) ||
913  m_UnordFMin(m_Value(L), m_Value(R)).match(SI) ||
914  m_UnordFMax(m_Value(L), m_Value(R)).match(SI)) {
915  auto *CI = cast<CmpInst>(SI->getCondition());
916  return ReductionData(RK_MinMax, CI->getOpcode(), L, R);
917  }
918  if (m_UMin(m_Value(L), m_Value(R)).match(SI) ||
919  m_UMax(m_Value(L), m_Value(R)).match(SI)) {
920  auto *CI = cast<CmpInst>(SI->getCondition());
921  return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R);
922  }
923  }
924  return llvm::None;
925 }
926 
928  unsigned Level,
929  unsigned NumLevels) {
930  // Match one level of pairwise operations.
931  // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
932  // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
933  // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
934  // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
935  // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
936  if (!I)
937  return RK_None;
938 
939  assert(I->getType()->isVectorTy() && "Expecting a vector type");
940 
942  if (!RD)
943  return RK_None;
944 
946  if (!LS && Level)
947  return RK_None;
949  if (!RS && Level)
950  return RK_None;
951 
952  // On level 0 we can omit one shufflevector instruction.
953  if (!Level && !RS && !LS)
954  return RK_None;
955 
956  // Shuffle inputs must match.
957  Value *NextLevelOpL = LS ? LS->getOperand(0) : nullptr;
958  Value *NextLevelOpR = RS ? RS->getOperand(0) : nullptr;
959  Value *NextLevelOp = nullptr;
960  if (NextLevelOpR && NextLevelOpL) {
961  // If we have two shuffles their operands must match.
962  if (NextLevelOpL != NextLevelOpR)
963  return RK_None;
964 
965  NextLevelOp = NextLevelOpL;
966  } else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) {
967  // On the first level we can omit the shufflevector <0, undef,...>. So the
968  // input to the other shufflevector <1, undef> must match with one of the
969  // inputs to the current binary operation.
970  // Example:
971  // %NextLevelOpL = shufflevector %R, <1, undef ...>
972  // %BinOp = fadd %NextLevelOpL, %R
973  if (NextLevelOpL && NextLevelOpL != RD->RHS)
974  return RK_None;
975  else if (NextLevelOpR && NextLevelOpR != RD->LHS)
976  return RK_None;
977 
978  NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS;
979  } else
980  return RK_None;
981 
982  // Check that the next levels binary operation exists and matches with the
983  // current one.
984  if (Level + 1 != NumLevels) {
985  Optional<ReductionData> NextLevelRD =
986  getReductionData(cast<Instruction>(NextLevelOp));
987  if (!NextLevelRD || !RD->hasSameData(*NextLevelRD))
988  return RK_None;
989  }
990 
991  // Shuffle mask for pairwise operation must match.
992  if (matchPairwiseShuffleMask(LS, /*IsLeft=*/true, Level)) {
993  if (!matchPairwiseShuffleMask(RS, /*IsLeft=*/false, Level))
994  return RK_None;
995  } else if (matchPairwiseShuffleMask(RS, /*IsLeft=*/true, Level)) {
996  if (!matchPairwiseShuffleMask(LS, /*IsLeft=*/false, Level))
997  return RK_None;
998  } else {
999  return RK_None;
1000  }
1001 
1002  if (++Level == NumLevels)
1003  return RD->Kind;
1004 
1005  // Match next level.
1006  return matchPairwiseReductionAtLevel(cast<Instruction>(NextLevelOp), Level,
1007  NumLevels);
1008 }
1009 
1011  unsigned &Opcode, Type *&Ty) {
1012  if (!EnableReduxCost)
1013  return RK_None;
1014 
1015  // Need to extract the first element.
1016  ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
1017  unsigned Idx = ~0u;
1018  if (CI)
1019  Idx = CI->getZExtValue();
1020  if (Idx != 0)
1021  return RK_None;
1022 
1023  auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
1024  if (!RdxStart)
1025  return RK_None;
1027  if (!RD)
1028  return RK_None;
1029 
1030  Type *VecTy = RdxStart->getType();
1031  unsigned NumVecElems = VecTy->getVectorNumElements();
1032  if (!isPowerOf2_32(NumVecElems))
1033  return RK_None;
1034 
1035  // We look for a sequence of shuffle,shuffle,add triples like the following
1036  // that builds a pairwise reduction tree.
1037  //
1038  // (X0, X1, X2, X3)
1039  // (X0 + X1, X2 + X3, undef, undef)
1040  // ((X0 + X1) + (X2 + X3), undef, undef, undef)
1041  //
1042  // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
1043  // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
1044  // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
1045  // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
1046  // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
1047  // %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
1048  // <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1049  // %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
1050  // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
1051  // %bin.rdx8 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
1052  // %r = extractelement <4 x float> %bin.rdx8, i32 0
1053  if (matchPairwiseReductionAtLevel(RdxStart, 0, Log2_32(NumVecElems)) ==
1054  RK_None)
1055  return RK_None;
1056 
1057  Opcode = RD->Opcode;
1058  Ty = VecTy;
1059 
1060  return RD->Kind;
1061 }
1062 
1063 static std::pair<Value *, ShuffleVectorInst *>
1065  ShuffleVectorInst *S = nullptr;
1066 
1067  if ((S = dyn_cast<ShuffleVectorInst>(L)))
1068  return std::make_pair(R, S);
1069 
1070  S = dyn_cast<ShuffleVectorInst>(R);
1071  return std::make_pair(L, S);
1072 }
1073 
1074 static ReductionKind
1076  unsigned &Opcode, Type *&Ty) {
1077  if (!EnableReduxCost)
1078  return RK_None;
1079 
1080  // Need to extract the first element.
1081  ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
1082  unsigned Idx = ~0u;
1083  if (CI)
1084  Idx = CI->getZExtValue();
1085  if (Idx != 0)
1086  return RK_None;
1087 
1088  auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
1089  if (!RdxStart)
1090  return RK_None;
1092  if (!RD)
1093  return RK_None;
1094 
1095  Type *VecTy = ReduxRoot->getOperand(0)->getType();
1096  unsigned NumVecElems = VecTy->getVectorNumElements();
1097  if (!isPowerOf2_32(NumVecElems))
1098  return RK_None;
1099 
1100  // We look for a sequence of shuffles and adds like the following matching one
1101  // fadd, shuffle vector pair at a time.
1102  //
1103  // %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef,
1104  // <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
1105  // %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
1106  // %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef,
1107  // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
1108  // %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
1109  // %r = extractelement <4 x float> %bin.rdx8, i32 0
1110 
1111  unsigned MaskStart = 1;
1112  Instruction *RdxOp = RdxStart;
1113  SmallVector<int, 32> ShuffleMask(NumVecElems, 0);
1114  unsigned NumVecElemsRemain = NumVecElems;
1115  while (NumVecElemsRemain - 1) {
1116  // Check for the right reduction operation.
1117  if (!RdxOp)
1118  return RK_None;
1119  Optional<ReductionData> RDLevel = getReductionData(RdxOp);
1120  if (!RDLevel || !RDLevel->hasSameData(*RD))
1121  return RK_None;
1122 
1123  Value *NextRdxOp;
1124  ShuffleVectorInst *Shuffle;
1125  std::tie(NextRdxOp, Shuffle) =
1126  getShuffleAndOtherOprd(RDLevel->LHS, RDLevel->RHS);
1127 
1128  // Check the current reduction operation and the shuffle use the same value.
1129  if (Shuffle == nullptr)
1130  return RK_None;
1131  if (Shuffle->getOperand(0) != NextRdxOp)
1132  return RK_None;
1133 
1134  // Check that shuffle masks matches.
1135  for (unsigned j = 0; j != MaskStart; ++j)
1136  ShuffleMask[j] = MaskStart + j;
1137  // Fill the rest of the mask with -1 for undef.
1138  std::fill(&ShuffleMask[MaskStart], ShuffleMask.end(), -1);
1139 
1141  if (ShuffleMask != Mask)
1142  return RK_None;
1143 
1144  RdxOp = dyn_cast<Instruction>(NextRdxOp);
1145  NumVecElemsRemain /= 2;
1146  MaskStart *= 2;
1147  }
1148 
1149  Opcode = RD->Opcode;
1150  Ty = VecTy;
1151  return RD->Kind;
1152 }
1153 
1154 int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
1155  switch (I->getOpcode()) {
1156  case Instruction::GetElementPtr:
1157  return getUserCost(I);
1158 
1159  case Instruction::Ret:
1160  case Instruction::PHI:
1161  case Instruction::Br: {
1162  return getCFInstrCost(I->getOpcode());
1163  }
1164  case Instruction::Add:
1165  case Instruction::FAdd:
1166  case Instruction::Sub:
1167  case Instruction::FSub:
1168  case Instruction::Mul:
1169  case Instruction::FMul:
1170  case Instruction::UDiv:
1171  case Instruction::SDiv:
1172  case Instruction::FDiv:
1173  case Instruction::URem:
1174  case Instruction::SRem:
1175  case Instruction::FRem:
1176  case Instruction::Shl:
1177  case Instruction::LShr:
1178  case Instruction::AShr:
1179  case Instruction::And:
1180  case Instruction::Or:
1181  case Instruction::Xor: {
1184  Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1185  Op2VK = getOperandInfo(I->getOperand(1), Op2VP);
1187  return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1188  Op1VP, Op2VP, Operands, I);
1189  }
1190  case Instruction::FNeg: {
1193  Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1194  Op2VK = OK_AnyValue;
1195  Op2VP = OP_None;
1197  return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1198  Op1VP, Op2VP, Operands, I);
1199  }
1200  case Instruction::Select: {
1201  const SelectInst *SI = cast<SelectInst>(I);
1202  Type *CondTy = SI->getCondition()->getType();
1203  return getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, I);
1204  }
1205  case Instruction::ICmp:
1206  case Instruction::FCmp: {
1207  Type *ValTy = I->getOperand(0)->getType();
1208  return getCmpSelInstrCost(I->getOpcode(), ValTy, I->getType(), I);
1209  }
1210  case Instruction::Store: {
1211  const StoreInst *SI = cast<StoreInst>(I);
1212  Type *ValTy = SI->getValueOperand()->getType();
1213  return getMemoryOpCost(I->getOpcode(), ValTy,
1214  MaybeAlign(SI->getAlignment()),
1215  SI->getPointerAddressSpace(), I);
1216  }
1217  case Instruction::Load: {
1218  const LoadInst *LI = cast<LoadInst>(I);
1219  return getMemoryOpCost(I->getOpcode(), I->getType(),
1220  MaybeAlign(LI->getAlignment()),
1221  LI->getPointerAddressSpace(), I);
1222  }
1223  case Instruction::ZExt:
1224  case Instruction::SExt:
1225  case Instruction::FPToUI:
1226  case Instruction::FPToSI:
1227  case Instruction::FPExt:
1228  case Instruction::PtrToInt:
1229  case Instruction::IntToPtr:
1230  case Instruction::SIToFP:
1231  case Instruction::UIToFP:
1232  case Instruction::Trunc:
1233  case Instruction::FPTrunc:
1234  case Instruction::BitCast:
1235  case Instruction::AddrSpaceCast: {
1236  Type *SrcTy = I->getOperand(0)->getType();
1237  return getCastInstrCost(I->getOpcode(), I->getType(), SrcTy, I);
1238  }
1239  case Instruction::ExtractElement: {
1240  const ExtractElementInst * EEI = cast<ExtractElementInst>(I);
1242  unsigned Idx = -1;
1243  if (CI)
1244  Idx = CI->getZExtValue();
1245 
1246  // Try to match a reduction sequence (series of shufflevector and vector
1247  // adds followed by a extractelement).
1248  unsigned ReduxOpCode;
1249  Type *ReduxType;
1250 
1251  switch (matchVectorSplittingReduction(EEI, ReduxOpCode, ReduxType)) {
1252  case RK_Arithmetic:
1253  return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1254  /*IsPairwiseForm=*/false);
1255  case RK_MinMax:
1256  return getMinMaxReductionCost(
1257  ReduxType, CmpInst::makeCmpResultType(ReduxType),
1258  /*IsPairwiseForm=*/false, /*IsUnsigned=*/false);
1259  case RK_UnsignedMinMax:
1260  return getMinMaxReductionCost(
1261  ReduxType, CmpInst::makeCmpResultType(ReduxType),
1262  /*IsPairwiseForm=*/false, /*IsUnsigned=*/true);
1263  case RK_None:
1264  break;
1265  }
1266 
1267  switch (matchPairwiseReduction(EEI, ReduxOpCode, ReduxType)) {
1268  case RK_Arithmetic:
1269  return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1270  /*IsPairwiseForm=*/true);
1271  case RK_MinMax:
1272  return getMinMaxReductionCost(
1273  ReduxType, CmpInst::makeCmpResultType(ReduxType),
1274  /*IsPairwiseForm=*/true, /*IsUnsigned=*/false);
1275  case RK_UnsignedMinMax:
1276  return getMinMaxReductionCost(
1277  ReduxType, CmpInst::makeCmpResultType(ReduxType),
1278  /*IsPairwiseForm=*/true, /*IsUnsigned=*/true);
1279  case RK_None:
1280  break;
1281  }
1282 
1283  return getVectorInstrCost(I->getOpcode(),
1284  EEI->getOperand(0)->getType(), Idx);
1285  }
1286  case Instruction::InsertElement: {
1287  const InsertElementInst * IE = cast<InsertElementInst>(I);
1288  ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
1289  unsigned Idx = -1;
1290  if (CI)
1291  Idx = CI->getZExtValue();
1292  return getVectorInstrCost(I->getOpcode(),
1293  IE->getType(), Idx);
1294  }
1295  case Instruction::ExtractValue:
1296  return 0; // Model all ExtractValue nodes as free.
1297  case Instruction::ShuffleVector: {
1298  const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
1299  Type *Ty = Shuffle->getType();
1300  Type *SrcTy = Shuffle->getOperand(0)->getType();
1301 
1302  // TODO: Identify and add costs for insert subvector, etc.
1303  int SubIndex;
1304  if (Shuffle->isExtractSubvectorMask(SubIndex))
1305  return TTIImpl->getShuffleCost(SK_ExtractSubvector, SrcTy, SubIndex, Ty);
1306 
1307  if (Shuffle->changesLength())
1308  return -1;
1309 
1310  if (Shuffle->isIdentity())
1311  return 0;
1312 
1313  if (Shuffle->isReverse())
1314  return TTIImpl->getShuffleCost(SK_Reverse, Ty, 0, nullptr);
1315 
1316  if (Shuffle->isSelect())
1317  return TTIImpl->getShuffleCost(SK_Select, Ty, 0, nullptr);
1318 
1319  if (Shuffle->isTranspose())
1320  return TTIImpl->getShuffleCost(SK_Transpose, Ty, 0, nullptr);
1321 
1322  if (Shuffle->isZeroEltSplat())
1323  return TTIImpl->getShuffleCost(SK_Broadcast, Ty, 0, nullptr);
1324 
1325  if (Shuffle->isSingleSource())
1326  return TTIImpl->getShuffleCost(SK_PermuteSingleSrc, Ty, 0, nullptr);
1327 
1328  return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr);
1329  }
1330  case Instruction::Call:
1331  if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
1332  SmallVector<Value *, 4> Args(II->arg_operands());
1333 
1334  FastMathFlags FMF;
1335  if (auto *FPMO = dyn_cast<FPMathOperator>(II))
1336  FMF = FPMO->getFastMathFlags();
1337 
1338  return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(),
1339  Args, FMF);
1340  }
1341  return -1;
1342  default:
1343  // We don't have any information on this instruction.
1344  return -1;
1345  }
1346 }
1347 
1349 
1350 TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
1351 
1353  std::function<Result(const Function &)> TTICallback)
1354  : TTICallback(std::move(TTICallback)) {}
1355 
1358  return TTICallback(F);
1359 }
1360 
1361 AnalysisKey TargetIRAnalysis::Key;
1362 
1363 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
1364  return Result(F.getParent()->getDataLayout());
1365 }
1366 
1367 // Register the basic pass.
1369  "Target Transform Information", false, true)
1371 
1372 void TargetTransformInfoWrapperPass::anchor() {}
1373 
1375  : ImmutablePass(ID) {
1378 }
1379 
1381  TargetIRAnalysis TIRA)
1382  : ImmutablePass(ID), TIRA(std::move(TIRA)) {
1385 }
1386 
1388  FunctionAnalysisManager DummyFAM;
1389  TTI = TIRA.run(F, DummyFAM);
1390  return *TTI;
1391 }
1392 
1393 ImmutablePass *
1395  return new TargetTransformInfoWrapperPass(std::move(TIRA));
1396 }
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
uint64_t CallInst * C
Value * getValueOperand()
Definition: Instructions.h:426
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
Return any intrinsic address operand indexes which may be rewritten if they use a flat address space ...
bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:71
static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft, unsigned Level)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & Context
static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot, unsigned &Opcode, Type *&Ty)
TargetTransformInfo & operator=(TargetTransformInfo &&RHS)
SI Whole Quad Mode
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Definition: InstrTypes.h:975
This class represents lattice values for constants.
Definition: AllocatorList.h:23
int getCallCost(FunctionType *FTy, int NumArgs=-1, const User *U=nullptr) const
Estimate the cost of a function call when lowered.
bool isLegalAddImmediate(int64_t Imm) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
bool isFPVectorizationPotentiallyUnsafe() const
Indicate that it is potentially unsafe to automatically vectorize floating-point operations because t...
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
bool supportsEfficientVectorElementLoadStore() const
If target has efficient vector element load/store instructions, it can return true here so that inser...
static ReductionKind matchPairwiseReductionAtLevel(Instruction *I, unsigned Level, unsigned NumLevels)
bool useColdCCForColdCall(Function &F) const
Return true if the input function which is cold at all call sites, should use coldcc calling conventi...
Analysis providing profile information.
The main scalar evolution driver.
TargetTransformInfoWrapperPass()
We must provide a default constructor for the pass but it should never be used.
int getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value *> Operands) const
Estimate the cost of a GEP operation when lowered.
MemIndexedMode
The type of load/store indexing.
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.
A cache of @llvm.assume calls within a function.
Analysis pass providing the TargetTransformInfo.
Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAlign, unsigned DestAlign) const
This instruction constructs a fixed permutation of two input vectors.
uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
int getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type *> Tys) const
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false) const
F(f)
An instruction for reading from memory.
Definition: Instructions.h:169
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an &#39;unordered&#39; floating point maximum function.
bool canMacroFuseCmp() const
Return true if the target can fuse a compare and branch.
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:230
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool enableAggressiveInterleaving(bool LoopHasReductions) const
Don&#39;t restrict interleaved unrolling to small loops.
llvm::Optional< unsigned > getCacheAssociativity(CacheLevel Level) const
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
This file provides helpers for the implementation of a TargetTransformInfo-conforming class...
PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
Return hardware support for population count.
unsigned getMaxInterleaveFactor(unsigned VF) const
CRTP base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class...
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:48
bool enableMaskedInterleavedAccessVectorization() const
Enable matching of interleaved access groups that contain predicated accesses or gaps and therefore v...
bool isLegalICmpImmediate(int64_t Imm) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
Definition: BitVector.h:937
int getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy=nullptr) const
Estimate the cost of a specific operation when lowered.
bool hasBranchDivergence() const
Return true if branch divergence exists.
This class represents the LLVM &#39;select&#39; instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Definition: LoopInfo.h:939
bool shouldBuildLookupTablesForConstant(Constant *C) const
Return true if switches should be turned into lookup tables containing this constant value for the ta...
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0, Instruction *I=nullptr) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty) const
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr) const
bool isLegalNTLoad(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal load.
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
Definition: PassManager.h:406
bool shouldBuildLookupTables() const
Return true if switches should be turned into lookup tables for the target.
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an &#39;unordered&#39; floating point minimum function.
mir Rename Register Operands
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:435
Class to represent function types.
Definition: DerivedTypes.h:108
unsigned getMinVectorRegisterBitWidth() const
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const
bool isTruncateFree(Type *Ty1, Type *Ty2) const
Return true if it&#39;s free to truncate a value of type Ty1 to type Ty2.
MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
PopcntSupportKind
Flags indicating the kind of support for population count.
bool hasDivRemOp(Type *DataType, bool IsSigned) const
Return true if the target has a unified operation to calculate division and remainder.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an &#39;ordered&#39; 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)...
Definition: APInt.h:32
Selects elements from the corresponding lane of either source operand.
const SCEV * getExitCount(const Loop *L, BasicBlock *ExitingBlock, ExitCountKind Kind=Exact)
Return the number of times the backedge executes before the given exit would be taken; if not exactly...
int getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Value *> Args, FastMathFlags FMF, unsigned VF=1) const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:125
An instruction for storing to memory.
Definition: Instructions.h:331
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const
Return true if the given instruction (assumed to be a memory access instruction) has a volatile varia...
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index=-1) const
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
bool isLegalToVectorizeLoad(LoadInst *LI) const
Reverse the order of the vector.
VectorType * getType() const
Overload to return most specific vector type.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
int getAddressComputationCost(Type *Ty, ScalarEvolution *SE=nullptr, const SCEV *Ptr=nullptr) const
Value * getOperand(unsigned i) const
Definition: User.h:169
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
int getExtCost(const Instruction *I, const Value *Src) const
Estimate the cost of a EXT operation when lowered.
static bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
bool isTypeLegal(Type *Ty) const
Return true if this type is legal.
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
Rewrite intrinsic call II such that OldV will be replaced with NewV, which has a different address sp...
ExtractSubvector Index indicates start offset.
static cl::opt< bool > EnableReduxCost("costmodel-reduxcost", cl::init(false), cl::Hidden, cl::desc("Recognize reduction patterns."))
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
unsigned getMaxPrefetchIterationsAhead() const
bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
This instruction inserts a single (scalar) element into a VectorType value.
int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, bool VariableMask, unsigned Alignment) const
Returns options for expansion of memcmp. IsZeroCmp is.
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:148
Wrapper pass for TargetTransformInfo.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr) const
bool isLegalToVectorizeStore(StoreInst *SI) const
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:465
unsigned getRegisterBitWidth(bool Vector) const
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
Flags describing the kind of vector reduction.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool isAlwaysUniform(const Value *V) const
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
Conditional or Unconditional Branch instruction.
unsigned getNumberOfParts(Type *Tp) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
bool isLegalMaskedScatter(Type *DataType, MaybeAlign Alignment) const
Return true if the target supports masked scatter.
bool isIdentity() const
Return true if this shuffle chooses elements from exactly one source vector without lane crossings an...
static cl::opt< bool > ForceNestedLoop("force-nested-hardware-loop", cl::Hidden, cl::init(false), cl::desc("Force allowance of nested hardware loops"))
AMDGPU Lower Kernel Arguments
int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0) const
Return the cost of the scaling factor used in the addressing mode represented by AM for this target...
TargetIRAnalysis()
Default construct a target IR analysis.
bool isLegalMaskedLoad(Type *DataType, MaybeAlign Alignment) const
Return true if the target supports masked load.
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy=nullptr, const Instruction *I=nullptr) const
int getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) const
Return the expected cost of materialization for the given integer immediate of the specified type for...
constexpr double e
Definition: MathExtras.h:57
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Merge elements from two source vectors into one with any shuffle mask.
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Definition: PatternMatch.h:74
static cl::opt< bool > ForceHardwareLoopPHI("force-hardware-loop-phi", cl::Hidden, cl::init(false), cl::desc("Force hardware loop counter to be updated through a phi"))
Attributes of a target dependent hardware loop.
const Value * getCondition() const
bool haveFastSqrt(Type *Ty) const
Return true if the hardware has a fast square-root instruction.
bool areFunctionArgsABICompatible(const Function *Caller, const Function *Callee, SmallPtrSetImpl< Argument *> &Args) const
static std::pair< Value *, ShuffleVectorInst * > getShuffleAndOtherOprd(Value *L, Value *R)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
bool isLegalMaskedCompressStore(Type *DataType) const
Return true if the target supports masked compress store.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:33
unsigned getNumberOfRegisters(unsigned ClassID) const
OperandValueProperties
Additional properties of an operand&#39;s values.
bool isProfitableToHoist(Instruction *I) const
Return true if it is profitable to hoist instruction in the then/else to before if.
ReductionKind
Kind of the reduction data.
int getFPOpCost(Type *Ty) const
Return the expected cost of supporting the floating point operation of the specified type...
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:253
Type * getType() const
Return the LLVM type of this SCEV expression.
bool isLSRCostLess(TargetTransformInfo::LSRCost &C1, TargetTransformInfo::LSRCost &C2) const
Return true if LSR cost of C1 is lower than C1.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
int getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwiseForm) const
Calculate the cost of performing a vector reduction.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:117
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Definition: Dominators.cpp:249
Module.h This file contains the declarations for the Module class.
unsigned getCostOfKeepingLiveOverCall(ArrayRef< Type *> Tys) const
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
int getIntImmCost(const APInt &Imm, Type *Ty) const
Return the expected cost of materializing for the given integer immediate of the specified type...
Provides information about what library functions are available for the current target.
AddressSpace
Definition: NVPTXBaseInfo.h:21
int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace) const
Drive the analysis of memory accesses in the loop.
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
pred_range predecessors(BasicBlock *BB)
Definition: CFG.h:124
bool isSourceOfDivergence(const Value *V) const
Returns whether V is a source of divergence.
bool LSRWithInstrQueries() const
Return true if the loop strength reduce pass should make Instruction* based TTI queries to isLegalAdd...
static ReductionKind matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot, unsigned &Opcode, Type *&Ty)
bool canAnalyze(LoopInfo &LI)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:585
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:566
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.
Definition: DerivedTypes.h:432
Class for arbitrary precision integers.
Definition: APInt.h:69
int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index=-1) const
TargetTransformInfo(T Impl)
Construct a TTI object using a type implementing the Concept API below.
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const
Query the target whether it would be profitable to convert the given loop into a hardware loop...
Result run(const Function &F, FunctionAnalysisManager &)
bool shouldExpandReduction(const IntrinsicInst *II) const
int getIntImmCodeSizeCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) const
Return the expected cost for the given integer when optimising for size.
int getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type *> ParamTys, const User *U=nullptr) const
Estimate the cost of an intrinsic when lowered.
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace=0, unsigned Alignment=1, bool *Fast=nullptr) const
Determine if the target supports unaligned memory accesses.
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
int getMemcpyCost(const Instruction *I) const
unsigned getGISelRematGlobalCost() const
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
unsigned getAtomicMemIntrinsicMaxElementSize() const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:244
This class represents an analyzed expression in the program.
bool preferPredicateOverEpilogue(Loop *L, LoopInfo *LI, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *TLI, DominatorTree *DT, const LoopAccessInfo *LAI) const
Query the target whether it would be prefered to create a predicated vector loop, which can avoid the...
int getUserCost(const User *U, ArrayRef< const Value *> Operands) const
Estimate the cost of a given IR user when lowered.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
Parameters that control the generic loop unrolling transformation.
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType) const
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
#define I(x, y, z)
Definition: MD5.cpp:58
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
iterator_range< value_op_iterator > operand_values()
Definition: User.h:261
const char * getRegisterClassName(unsigned ClassID) const
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:332
This instruction extracts a single (scalar) element from a VectorType value.
int getShuffleCost(ShuffleKind Kind, Type *Tp, int Index=0, Type *SubTp=nullptr) const
bool isLegalMaskedStore(Type *DataType, MaybeAlign Alignment) const
Return true if the target supports masked store.
unsigned getAlignment() const
Return the alignment of the access that is being performed FIXME: Remove this function once transitio...
Definition: Instructions.h:376
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
Definition: LoopIterator.h:172
bool isLegalMaskedExpandLoad(Type *DataType) const
Return true if the target supports masked expand load.
bool shouldMaximizeVectorBandwidth(bool OptSize) const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Definition: Instructions.h:301
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
Multiway switch.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isLegalNTStore(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal store.
TargetTransformInfo Result
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info=OK_AnyValue, OperandValueKind Opd2Info=OK_AnyValue, OperandValueProperties Opd1PropInfo=OP_None, OperandValueProperties Opd2PropInfo=OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr) const
This is an approximation of reciprocal throughput of a math/logic op.
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an &#39;ordered&#39; floating point maximum function.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
unsigned getInliningThresholdMultiplier() const
bool useReductionIntrinsic(unsigned Opcode, Type *Ty, ReductionFlags Flags) const
bool isLoweredToCall(const Function *F) const
Test whether calls to a function lower to actual program function calls.
bool enableInterleavedAccessVectorization() const
Enable matching of interleaved access groups.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
Broadcast element 0 to all other elements.
static Optional< ReductionData > getReductionData(Instruction *I)
void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type *> &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const
int getCFInstrCost(unsigned Opcode) const
bool shouldFavorBackedgeIndex(const Loop *L) const
Return true if LSR should make efforts to generate indexed addressing modes that operate across loop ...
bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const
Return true if the target can save a compare for loop count, for example hardware loop saves a compar...
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const
Return true if it is faster to check if a floating-point value is NaN (or not-NaN) versus a compariso...
bool prefersVectorizedAddressing() const
Return true if target doesn&#39;t mind addresses in vectors.
unsigned getOperandsScalarizationOverhead(ArrayRef< const Value *> Args, unsigned VF) const
print Print MemDeps of function
void getUnrollingPreferences(Loop *L, ScalarEvolution &, UnrollingPreferences &UP) const
Get target-customized preferences for the generic loop unrolling transformation.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
OperandValueKind
Additional information about an operand&#39;s possible values.
bool isLegalMaskedGather(Type *DataType, MaybeAlign Alignment) const
Return true if the target supports masked gather.
A container for analyses that lazily runs them and caches their results.
unsigned getMinimumVF(unsigned ElemWidth) const
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
This pass exposes codegen information to IR-level passes.
TargetTransformInfo & getTTI(const Function &F)
CacheLevel
The possible cache levels.
void perform(LoopInfo *LI)
Traverse the loop blocks and store the DFS result.
Definition: LoopIterator.h:180
bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
VectorType * getType() const
Overload to return most specific vector type.
unsigned getFlatAddressSpace() const
Returns the address space ID for a target&#39;s &#39;flat&#39; address space.
Information about a load/store intrinsic defined by the target.
static OperandValueKind getOperandInfo(Value *V, OperandValueProperties &OpProps)
Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm, bool IsUnsigned) const
llvm::Optional< unsigned > getCacheSize(CacheLevel Level) const
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.
Shuffle elements of single source vector with any shuffle mask.