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