blob: 48e441bac695bf960a01809a0d2a8b643a339e16 [file] [log] [blame]
Chandler Carruthd3e73552013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotem5dc203e2012-10-18 23:22:48 +00002//
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
Chandler Carruthd3e73552013-01-07 03:08:10 +000010#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth705b1852015-01-31 03:43:40 +000011#include "llvm/Analysis/TargetTransformInfoImpl.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000012#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000015#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "llvm/IR/IntrinsicInst.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000017#include "llvm/IR/Module.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000018#include "llvm/IR/Operator.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000019#include "llvm/Support/ErrorHandling.h"
20
21using namespace llvm;
22
Chandler Carruthf1221bd2014-04-22 02:48:03 +000023#define DEBUG_TYPE "tti"
24
Chandler Carruth93dcdc42015-01-31 11:17:59 +000025namespace {
26/// \brief No-op implementation of the TTI interface using the utility base
27/// classes.
28///
29/// This is used when no target specific information is available.
30struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000031 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000032 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
33};
34}
35
Mehdi Amini5010ebf2015-07-09 02:08:42 +000036TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000037 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
38
Chandler Carruth705b1852015-01-31 03:43:40 +000039TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000040
Chandler Carruth705b1852015-01-31 03:43:40 +000041TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
42 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000043
Chandler Carruth705b1852015-01-31 03:43:40 +000044TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
45 TTIImpl = std::move(RHS.TTIImpl);
46 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000047}
48
Chandler Carruth93205eb2015-08-05 18:08:10 +000049int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
50 Type *OpTy) const {
51 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
52 assert(Cost >= 0 && "TTI should not produce negative costs!");
53 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000054}
55
Chandler Carruth93205eb2015-08-05 18:08:10 +000056int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
57 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
58 assert(Cost >= 0 && "TTI should not produce negative costs!");
59 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000060}
61
Chandler Carruth93205eb2015-08-05 18:08:10 +000062int TargetTransformInfo::getCallCost(const Function *F,
63 ArrayRef<const Value *> Arguments) const {
64 int Cost = TTIImpl->getCallCost(F, Arguments);
65 assert(Cost >= 0 && "TTI should not produce negative costs!");
66 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000067}
68
Chandler Carruth93205eb2015-08-05 18:08:10 +000069int TargetTransformInfo::getIntrinsicCost(
70 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
71 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
72 assert(Cost >= 0 && "TTI should not produce negative costs!");
73 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000074}
75
Chandler Carruth93205eb2015-08-05 18:08:10 +000076int TargetTransformInfo::getUserCost(const User *U) const {
77 int Cost = TTIImpl->getUserCost(U);
78 assert(Cost >= 0 && "TTI should not produce negative costs!");
79 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000080}
81
Tom Stellard8b1e0212013-07-27 00:01:07 +000082bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000083 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000084}
85
Jingyue Wu5da831c2015-04-10 05:03:50 +000086bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
87 return TTIImpl->isSourceOfDivergence(V);
88}
89
Chandler Carruth0ba8db42013-01-22 11:26:02 +000090bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +000091 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +000092}
93
Chandler Carruth705b1852015-01-31 03:43:40 +000094void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +000095 Loop *L, UnrollingPreferences &UP) const {
96 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +000097}
98
Chandler Carruth539edf42013-01-05 11:43:11 +000099bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000100 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000101}
102
103bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000104 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000105}
106
107bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
108 int64_t BaseOffset,
109 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000110 int64_t Scale,
111 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000112 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000113 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000114}
115
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000116bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
117 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000118}
119
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000120bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
121 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000122}
123
Elena Demikhovsky09285852015-10-25 15:37:55 +0000124bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
125 return TTIImpl->isLegalMaskedGather(DataType);
126}
127
128bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
129 return TTIImpl->isLegalMaskedGather(DataType);
130}
131
Quentin Colombetbf490d42013-05-31 21:29:03 +0000132int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
133 int64_t BaseOffset,
134 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000135 int64_t Scale,
136 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000137 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
138 Scale, AddrSpace);
139 assert(Cost >= 0 && "TTI should not produce negative costs!");
140 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000141}
142
Chandler Carruth539edf42013-01-05 11:43:11 +0000143bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000144 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000145}
146
Chad Rosier54390052015-02-23 19:15:16 +0000147bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
148 return TTIImpl->isProfitableToHoist(I);
149}
150
Chandler Carruth539edf42013-01-05 11:43:11 +0000151bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000152 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000153}
154
155unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000156 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000157}
158
159unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000160 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000161}
162
163bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000164 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000165}
166
Olivier Sallenave049d8032015-03-06 23:12:04 +0000167bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
168 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
169}
170
Silviu Baranga61bdc512015-08-10 14:50:54 +0000171bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
172 return TTIImpl->enableInterleavedAccessVectorization();
173}
174
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000175TargetTransformInfo::PopcntSupportKind
176TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000177 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000178}
179
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000180bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000181 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000182}
183
Chandler Carruth93205eb2015-08-05 18:08:10 +0000184int TargetTransformInfo::getFPOpCost(Type *Ty) const {
185 int Cost = TTIImpl->getFPOpCost(Ty);
186 assert(Cost >= 0 && "TTI should not produce negative costs!");
187 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000188}
189
Chandler Carruth93205eb2015-08-05 18:08:10 +0000190int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
191 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
192 assert(Cost >= 0 && "TTI should not produce negative costs!");
193 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000194}
195
Chandler Carruth93205eb2015-08-05 18:08:10 +0000196int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
197 const APInt &Imm, Type *Ty) const {
198 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
199 assert(Cost >= 0 && "TTI should not produce negative costs!");
200 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000201}
202
Chandler Carruth93205eb2015-08-05 18:08:10 +0000203int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
204 const APInt &Imm, Type *Ty) const {
205 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
206 assert(Cost >= 0 && "TTI should not produce negative costs!");
207 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000208}
209
Chandler Carruth539edf42013-01-05 11:43:11 +0000210unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000211 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000212}
213
Nadav Rotemb1791a72013-01-09 22:29:00 +0000214unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000215 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000216}
217
Adam Nemetaf761102016-01-21 18:28:36 +0000218unsigned TargetTransformInfo::getCacheLineSize() const {
219 return TTIImpl->getCacheLineSize();
220}
221
Adam Nemetdadfbb52016-01-27 22:21:25 +0000222unsigned TargetTransformInfo::getPrefetchDistance() const {
223 return TTIImpl->getPrefetchDistance();
224}
225
Adam Nemet6d8beec2016-03-18 00:27:38 +0000226unsigned TargetTransformInfo::getMinPrefetchStride() const {
227 return TTIImpl->getMinPrefetchStride();
228}
229
Adam Nemet709e3042016-03-18 00:27:43 +0000230unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
231 return TTIImpl->getMaxPrefetchIterationsAhead();
232}
233
Wei Mi062c7442015-05-06 17:12:25 +0000234unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
235 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000236}
237
Chandler Carruth93205eb2015-08-05 18:08:10 +0000238int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000239 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
240 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000241 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000242 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
243 Opd1PropInfo, Opd2PropInfo);
244 assert(Cost >= 0 && "TTI should not produce negative costs!");
245 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000246}
247
Chandler Carruth93205eb2015-08-05 18:08:10 +0000248int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
249 Type *SubTp) const {
250 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
251 assert(Cost >= 0 && "TTI should not produce negative costs!");
252 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000253}
254
Chandler Carruth93205eb2015-08-05 18:08:10 +0000255int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
256 Type *Src) const {
257 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
258 assert(Cost >= 0 && "TTI should not produce negative costs!");
259 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000260}
261
Chandler Carruth93205eb2015-08-05 18:08:10 +0000262int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
263 int Cost = TTIImpl->getCFInstrCost(Opcode);
264 assert(Cost >= 0 && "TTI should not produce negative costs!");
265 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000266}
267
Chandler Carruth93205eb2015-08-05 18:08:10 +0000268int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
269 Type *CondTy) const {
270 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
271 assert(Cost >= 0 && "TTI should not produce negative costs!");
272 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000273}
274
Chandler Carruth93205eb2015-08-05 18:08:10 +0000275int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
276 unsigned Index) const {
277 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
278 assert(Cost >= 0 && "TTI should not produce negative costs!");
279 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000280}
281
Chandler Carruth93205eb2015-08-05 18:08:10 +0000282int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
283 unsigned Alignment,
284 unsigned AddressSpace) const {
285 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
286 assert(Cost >= 0 && "TTI should not produce negative costs!");
287 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000288}
289
Chandler Carruth93205eb2015-08-05 18:08:10 +0000290int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
291 unsigned Alignment,
292 unsigned AddressSpace) const {
293 int Cost =
294 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
295 assert(Cost >= 0 && "TTI should not produce negative costs!");
296 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000297}
298
Elena Demikhovsky54946982015-12-28 20:10:59 +0000299int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
300 Value *Ptr, bool VariableMask,
301 unsigned Alignment) const {
302 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
303 Alignment);
304 assert(Cost >= 0 && "TTI should not produce negative costs!");
305 return Cost;
306}
307
Chandler Carruth93205eb2015-08-05 18:08:10 +0000308int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000309 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
310 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000311 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
312 Alignment, AddressSpace);
313 assert(Cost >= 0 && "TTI should not produce negative costs!");
314 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000315}
316
Chandler Carruth93205eb2015-08-05 18:08:10 +0000317int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000318 ArrayRef<Type *> Tys,
319 FastMathFlags FMF) const {
320 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000321 assert(Cost >= 0 && "TTI should not produce negative costs!");
322 return Cost;
323}
324
Elena Demikhovsky54946982015-12-28 20:10:59 +0000325int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000326 ArrayRef<Value *> Args,
327 FastMathFlags FMF) const {
328 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000329 assert(Cost >= 0 && "TTI should not produce negative costs!");
330 return Cost;
331}
332
Chandler Carruth93205eb2015-08-05 18:08:10 +0000333int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
334 ArrayRef<Type *> Tys) const {
335 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
336 assert(Cost >= 0 && "TTI should not produce negative costs!");
337 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000338}
339
Chandler Carruth539edf42013-01-05 11:43:11 +0000340unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000341 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000342}
343
Chandler Carruth93205eb2015-08-05 18:08:10 +0000344int TargetTransformInfo::getAddressComputationCost(Type *Tp,
345 bool IsComplex) const {
346 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000349}
Chandler Carruth539edf42013-01-05 11:43:11 +0000350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
352 bool IsPairwiseForm) const {
353 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
354 assert(Cost >= 0 && "TTI should not produce negative costs!");
355 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000356}
357
Chandler Carruth705b1852015-01-31 03:43:40 +0000358unsigned
359TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
360 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000361}
362
363bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
364 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000365 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000366}
367
Chandler Carruth705b1852015-01-31 03:43:40 +0000368Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
369 IntrinsicInst *Inst, Type *ExpectedType) const {
370 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
371}
372
Eric Christopherd566fb12015-07-29 22:09:48 +0000373bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
374 const Function *Callee) const {
375 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000376}
377
Chandler Carruth705b1852015-01-31 03:43:40 +0000378TargetTransformInfo::Concept::~Concept() {}
379
Chandler Carruthe0385522015-02-01 10:11:22 +0000380TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
381
382TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000383 std::function<Result(const Function &)> TTICallback)
Chandler Carruthe0385522015-02-01 10:11:22 +0000384 : TTICallback(TTICallback) {}
385
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000386TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000387 return TTICallback(F);
388}
389
Chandler Carruthb4faf132016-03-11 10:22:49 +0000390char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000391
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000392TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000393 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000394}
395
Chandler Carruth705b1852015-01-31 03:43:40 +0000396// Register the basic pass.
397INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
398 "Target Transform Information", false, true)
399char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000400
Chandler Carruth705b1852015-01-31 03:43:40 +0000401void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000402
Chandler Carruth705b1852015-01-31 03:43:40 +0000403TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000404 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000405 initializeTargetTransformInfoWrapperPassPass(
406 *PassRegistry::getPassRegistry());
407}
408
409TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000410 TargetIRAnalysis TIRA)
411 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000412 initializeTargetTransformInfoWrapperPassPass(
413 *PassRegistry::getPassRegistry());
414}
415
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000416TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000417 TTI = TIRA.run(F);
418 return *TTI;
419}
420
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000421ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000422llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
423 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000424}