1 //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
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 
10 #include "llvm/Analysis/TargetTransformInfo.h"
11 #include "llvm/Analysis/TargetTransformInfoImpl.h"
12 #include "llvm/IR/CallSite.h"
13 #include "llvm/IR/DataLayout.h"
14 #include "llvm/IR/Instruction.h"
15 #include "llvm/IR/Instructions.h"
16 #include "llvm/IR/IntrinsicInst.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/IR/Operator.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include <utility>
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "tti"
26 
27 static cl::opt<bool> UseWideMemcpyLoopLowering(
28     "use-wide-memcpy-loop-lowering", cl::init(false),
29     cl::desc("Enables the new wide memcpy loop lowering in Transforms/Utils."),
30     cl::Hidden);
31 
32 namespace {
33 /// \brief No-op implementation of the TTI interface using the utility base
34 /// classes.
35 ///
36 /// This is used when no target specific information is available.
37 struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
38   explicit NoTTIImpl(const DataLayout &DL)
39       : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
40 };
41 }
42 
43 TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
44     : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
45 
46 TargetTransformInfo::~TargetTransformInfo() {}
47 
48 TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
49     : TTIImpl(std::move(Arg.TTIImpl)) {}
50 
51 TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
52   TTIImpl = std::move(RHS.TTIImpl);
53   return *this;
54 }
55 
56 int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
57                                           Type *OpTy) const {
58   int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
59   assert(Cost >= 0 && "TTI should not produce negative costs!");
60   return Cost;
61 }
62 
63 int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
64   int Cost = TTIImpl->getCallCost(FTy, NumArgs);
65   assert(Cost >= 0 && "TTI should not produce negative costs!");
66   return Cost;
67 }
68 
69 int TargetTransformInfo::getCallCost(const Function *F,
70                                      ArrayRef<const Value *> Arguments) const {
71   int Cost = TTIImpl->getCallCost(F, Arguments);
72   assert(Cost >= 0 && "TTI should not produce negative costs!");
73   return Cost;
74 }
75 
76 unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
77   return TTIImpl->getInliningThresholdMultiplier();
78 }
79 
80 int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
81                                     ArrayRef<const Value *> Operands) const {
82   return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
83 }
84 
85 int TargetTransformInfo::getIntrinsicCost(
86     Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
87   int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
88   assert(Cost >= 0 && "TTI should not produce negative costs!");
89   return Cost;
90 }
91 
92 unsigned
93 TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
94                                                       unsigned &JTSize) const {
95   return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
96 }
97 
98 int TargetTransformInfo::getUserCost(const User *U,
99     ArrayRef<const Value *> Operands) const {
100   int Cost = TTIImpl->getUserCost(U, Operands);
101   assert(Cost >= 0 && "TTI should not produce negative costs!");
102   return Cost;
103 }
104 
105 bool TargetTransformInfo::hasBranchDivergence() const {
106   return TTIImpl->hasBranchDivergence();
107 }
108 
109 bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
110   return TTIImpl->isSourceOfDivergence(V);
111 }
112 
113 bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
114   return TTIImpl->isAlwaysUniform(V);
115 }
116 
117 unsigned TargetTransformInfo::getFlatAddressSpace() const {
118   return TTIImpl->getFlatAddressSpace();
119 }
120 
121 bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
122   return TTIImpl->isLoweredToCall(F);
123 }
124 
125 void TargetTransformInfo::getUnrollingPreferences(
126     Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
127   return TTIImpl->getUnrollingPreferences(L, SE, UP);
128 }
129 
130 bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
131   return TTIImpl->isLegalAddImmediate(Imm);
132 }
133 
134 bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
135   return TTIImpl->isLegalICmpImmediate(Imm);
136 }
137 
138 bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
139                                                 int64_t BaseOffset,
140                                                 bool HasBaseReg,
141                                                 int64_t Scale,
142                                                 unsigned AddrSpace) const {
143   return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
144                                         Scale, AddrSpace);
145 }
146 
147 bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
148   return TTIImpl->isLSRCostLess(C1, C2);
149 }
150 
151 bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
152   return TTIImpl->isLegalMaskedStore(DataType);
153 }
154 
155 bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
156   return TTIImpl->isLegalMaskedLoad(DataType);
157 }
158 
159 bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
160   return TTIImpl->isLegalMaskedGather(DataType);
161 }
162 
163 bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
164   return TTIImpl->isLegalMaskedGather(DataType);
165 }
166 
167 bool TargetTransformInfo::prefersVectorizedAddressing() const {
168   return TTIImpl->prefersVectorizedAddressing();
169 }
170 
171 int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
172                                               int64_t BaseOffset,
173                                               bool HasBaseReg,
174                                               int64_t Scale,
175                                               unsigned AddrSpace) const {
176   int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
177                                            Scale, AddrSpace);
178   assert(Cost >= 0 && "TTI should not produce negative costs!");
179   return Cost;
180 }
181 
182 bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
183                                                     int64_t Offset) const {
184   return TTIImpl->isFoldableMemAccessOffset(I, Offset);
185 }
186 
187 bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
188   return TTIImpl->isTruncateFree(Ty1, Ty2);
189 }
190 
191 bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
192   return TTIImpl->isProfitableToHoist(I);
193 }
194 
195 bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
196   return TTIImpl->isTypeLegal(Ty);
197 }
198 
199 unsigned TargetTransformInfo::getJumpBufAlignment() const {
200   return TTIImpl->getJumpBufAlignment();
201 }
202 
203 unsigned TargetTransformInfo::getJumpBufSize() const {
204   return TTIImpl->getJumpBufSize();
205 }
206 
207 bool TargetTransformInfo::shouldBuildLookupTables() const {
208   return TTIImpl->shouldBuildLookupTables();
209 }
210 bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
211   return TTIImpl->shouldBuildLookupTablesForConstant(C);
212 }
213 
214 unsigned TargetTransformInfo::
215 getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
216   return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
217 }
218 
219 unsigned TargetTransformInfo::
220 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
221                                  unsigned VF) const {
222   return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
223 }
224 
225 bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
226   return TTIImpl->supportsEfficientVectorElementLoadStore();
227 }
228 
229 bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
230   return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
231 }
232 
233 bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const {
234   return TTIImpl->expandMemCmp(I, MaxLoadSize);
235 }
236 
237 bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
238   return TTIImpl->enableInterleavedAccessVectorization();
239 }
240 
241 bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
242   return TTIImpl->isFPVectorizationPotentiallyUnsafe();
243 }
244 
245 bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
246                                                          unsigned BitWidth,
247                                                          unsigned AddressSpace,
248                                                          unsigned Alignment,
249                                                          bool *Fast) const {
250   return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
251                                                  Alignment, Fast);
252 }
253 
254 TargetTransformInfo::PopcntSupportKind
255 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
256   return TTIImpl->getPopcntSupport(IntTyWidthInBit);
257 }
258 
259 bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
260   return TTIImpl->haveFastSqrt(Ty);
261 }
262 
263 int TargetTransformInfo::getFPOpCost(Type *Ty) const {
264   int Cost = TTIImpl->getFPOpCost(Ty);
265   assert(Cost >= 0 && "TTI should not produce negative costs!");
266   return Cost;
267 }
268 
269 int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
270                                                const APInt &Imm,
271                                                Type *Ty) const {
272   int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
273   assert(Cost >= 0 && "TTI should not produce negative costs!");
274   return Cost;
275 }
276 
277 int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
278   int Cost = TTIImpl->getIntImmCost(Imm, Ty);
279   assert(Cost >= 0 && "TTI should not produce negative costs!");
280   return Cost;
281 }
282 
283 int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
284                                        const APInt &Imm, Type *Ty) const {
285   int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
286   assert(Cost >= 0 && "TTI should not produce negative costs!");
287   return Cost;
288 }
289 
290 int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
291                                        const APInt &Imm, Type *Ty) const {
292   int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
293   assert(Cost >= 0 && "TTI should not produce negative costs!");
294   return Cost;
295 }
296 
297 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
298   return TTIImpl->getNumberOfRegisters(Vector);
299 }
300 
301 unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
302   return TTIImpl->getRegisterBitWidth(Vector);
303 }
304 
305 unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
306   return TTIImpl->getMinVectorRegisterBitWidth();
307 }
308 
309 bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
310     const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
311   return TTIImpl->shouldConsiderAddressTypePromotion(
312       I, AllowPromotionWithoutCommonHeader);
313 }
314 
315 unsigned TargetTransformInfo::getCacheLineSize() const {
316   return TTIImpl->getCacheLineSize();
317 }
318 
319 unsigned TargetTransformInfo::getPrefetchDistance() const {
320   return TTIImpl->getPrefetchDistance();
321 }
322 
323 unsigned TargetTransformInfo::getMinPrefetchStride() const {
324   return TTIImpl->getMinPrefetchStride();
325 }
326 
327 unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
328   return TTIImpl->getMaxPrefetchIterationsAhead();
329 }
330 
331 unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
332   return TTIImpl->getMaxInterleaveFactor(VF);
333 }
334 
335 int TargetTransformInfo::getArithmeticInstrCost(
336     unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
337     OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
338     OperandValueProperties Opd2PropInfo,
339     ArrayRef<const Value *> Args) const {
340   int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
341                                              Opd1PropInfo, Opd2PropInfo, Args);
342   assert(Cost >= 0 && "TTI should not produce negative costs!");
343   return Cost;
344 }
345 
346 int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
347                                         Type *SubTp) const {
348   int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
349   assert(Cost >= 0 && "TTI should not produce negative costs!");
350   return Cost;
351 }
352 
353 int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
354                                  Type *Src, const Instruction *I) const {
355   assert ((I == nullptr || I->getOpcode() == Opcode) &&
356           "Opcode should reflect passed instruction.");
357   int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
358   assert(Cost >= 0 && "TTI should not produce negative costs!");
359   return Cost;
360 }
361 
362 int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
363                                                   VectorType *VecTy,
364                                                   unsigned Index) const {
365   int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
366   assert(Cost >= 0 && "TTI should not produce negative costs!");
367   return Cost;
368 }
369 
370 int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
371   int Cost = TTIImpl->getCFInstrCost(Opcode);
372   assert(Cost >= 0 && "TTI should not produce negative costs!");
373   return Cost;
374 }
375 
376 int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
377                                  Type *CondTy, const Instruction *I) const {
378   assert ((I == nullptr || I->getOpcode() == Opcode) &&
379           "Opcode should reflect passed instruction.");
380   int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
381   assert(Cost >= 0 && "TTI should not produce negative costs!");
382   return Cost;
383 }
384 
385 int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
386                                             unsigned Index) const {
387   int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
388   assert(Cost >= 0 && "TTI should not produce negative costs!");
389   return Cost;
390 }
391 
392 int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
393                                          unsigned Alignment,
394                                          unsigned AddressSpace,
395                                          const Instruction *I) const {
396   assert ((I == nullptr || I->getOpcode() == Opcode) &&
397           "Opcode should reflect passed instruction.");
398   int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
399   assert(Cost >= 0 && "TTI should not produce negative costs!");
400   return Cost;
401 }
402 
403 int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
404                                                unsigned Alignment,
405                                                unsigned AddressSpace) const {
406   int Cost =
407       TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
408   assert(Cost >= 0 && "TTI should not produce negative costs!");
409   return Cost;
410 }
411 
412 int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
413                                                 Value *Ptr, bool VariableMask,
414                                                 unsigned Alignment) const {
415   int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
416                                              Alignment);
417   assert(Cost >= 0 && "TTI should not produce negative costs!");
418   return Cost;
419 }
420 
421 int TargetTransformInfo::getInterleavedMemoryOpCost(
422     unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
423     unsigned Alignment, unsigned AddressSpace) const {
424   int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
425                                                  Alignment, AddressSpace);
426   assert(Cost >= 0 && "TTI should not produce negative costs!");
427   return Cost;
428 }
429 
430 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
431                                     ArrayRef<Type *> Tys, FastMathFlags FMF,
432                                     unsigned ScalarizationCostPassed) const {
433   int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
434                                             ScalarizationCostPassed);
435   assert(Cost >= 0 && "TTI should not produce negative costs!");
436   return Cost;
437 }
438 
439 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
440            ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
441   int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
442   assert(Cost >= 0 && "TTI should not produce negative costs!");
443   return Cost;
444 }
445 
446 int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
447                                           ArrayRef<Type *> Tys) const {
448   int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
449   assert(Cost >= 0 && "TTI should not produce negative costs!");
450   return Cost;
451 }
452 
453 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
454   return TTIImpl->getNumberOfParts(Tp);
455 }
456 
457 int TargetTransformInfo::getAddressComputationCost(Type *Tp,
458                                                    ScalarEvolution *SE,
459                                                    const SCEV *Ptr) const {
460   int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
461   assert(Cost >= 0 && "TTI should not produce negative costs!");
462   return Cost;
463 }
464 
465 int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
466                                           bool IsPairwiseForm) const {
467   int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
468   assert(Cost >= 0 && "TTI should not produce negative costs!");
469   return Cost;
470 }
471 
472 unsigned
473 TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
474   return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
475 }
476 
477 bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
478                                              MemIntrinsicInfo &Info) const {
479   return TTIImpl->getTgtMemIntrinsic(Inst, Info);
480 }
481 
482 unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
483   return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
484 }
485 
486 Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
487     IntrinsicInst *Inst, Type *ExpectedType) const {
488   return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
489 }
490 
491 Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
492                                                      Value *Length,
493                                                      unsigned SrcAlign,
494                                                      unsigned DestAlign) const {
495   return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
496                                             DestAlign);
497 }
498 
499 void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
500     SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
501     unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
502   TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
503                                              SrcAlign, DestAlign);
504 }
505 
506 bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const {
507   return UseWideMemcpyLoopLowering;
508 }
509 
510 bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
511                                               const Function *Callee) const {
512   return TTIImpl->areInlineCompatible(Caller, Callee);
513 }
514 
515 unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
516   return TTIImpl->getLoadStoreVecRegBitWidth(AS);
517 }
518 
519 bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
520   return TTIImpl->isLegalToVectorizeLoad(LI);
521 }
522 
523 bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
524   return TTIImpl->isLegalToVectorizeStore(SI);
525 }
526 
527 bool TargetTransformInfo::isLegalToVectorizeLoadChain(
528     unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
529   return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
530                                               AddrSpace);
531 }
532 
533 bool TargetTransformInfo::isLegalToVectorizeStoreChain(
534     unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
535   return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
536                                                AddrSpace);
537 }
538 
539 unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
540                                                   unsigned LoadSize,
541                                                   unsigned ChainSizeInBytes,
542                                                   VectorType *VecTy) const {
543   return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
544 }
545 
546 unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
547                                                    unsigned StoreSize,
548                                                    unsigned ChainSizeInBytes,
549                                                    VectorType *VecTy) const {
550   return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
551 }
552 
553 bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
554                                                 Type *Ty, ReductionFlags Flags) const {
555   return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
556 }
557 
558 bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
559   return TTIImpl->shouldExpandReduction(II);
560 }
561 
562 TargetTransformInfo::Concept::~Concept() {}
563 
564 TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
565 
566 TargetIRAnalysis::TargetIRAnalysis(
567     std::function<Result(const Function &)> TTICallback)
568     : TTICallback(std::move(TTICallback)) {}
569 
570 TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
571                                                FunctionAnalysisManager &) {
572   return TTICallback(F);
573 }
574 
575 AnalysisKey TargetIRAnalysis::Key;
576 
577 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
578   return Result(F.getParent()->getDataLayout());
579 }
580 
581 // Register the basic pass.
582 INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
583                 "Target Transform Information", false, true)
584 char TargetTransformInfoWrapperPass::ID = 0;
585 
586 void TargetTransformInfoWrapperPass::anchor() {}
587 
588 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
589     : ImmutablePass(ID) {
590   initializeTargetTransformInfoWrapperPassPass(
591       *PassRegistry::getPassRegistry());
592 }
593 
594 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
595     TargetIRAnalysis TIRA)
596     : ImmutablePass(ID), TIRA(std::move(TIRA)) {
597   initializeTargetTransformInfoWrapperPassPass(
598       *PassRegistry::getPassRegistry());
599 }
600 
601 TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
602   FunctionAnalysisManager DummyFAM;
603   TTI = TIRA.run(F, DummyFAM);
604   return *TTI;
605 }
606 
607 ImmutablePass *
608 llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
609   return new TargetTransformInfoWrapperPass(std::move(TIRA));
610 }
611