blob: 155a698c3998145824d9bac9b04e65f324b3debc [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"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000020#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000021
22using namespace llvm;
23
Chandler Carruthf1221bd2014-04-22 02:48:03 +000024#define DEBUG_TYPE "tti"
25
Chandler Carruth93dcdc42015-01-31 11:17:59 +000026namespace {
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.
31struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000032 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000033 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
34};
35}
36
Mehdi Amini5010ebf2015-07-09 02:08:42 +000037TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000038 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
39
Chandler Carruth705b1852015-01-31 03:43:40 +000040TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000041
Chandler Carruth705b1852015-01-31 03:43:40 +000042TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
43 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000044
Chandler Carruth705b1852015-01-31 03:43:40 +000045TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
46 TTIImpl = std::move(RHS.TTIImpl);
47 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000048}
49
Chandler Carruth93205eb2015-08-05 18:08:10 +000050int 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;
Chandler Carruth511aa762013-01-21 01:27:39 +000055}
56
Chandler Carruth93205eb2015-08-05 18:08:10 +000057int 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;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000061}
62
Chandler Carruth93205eb2015-08-05 18:08:10 +000063int 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;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000068}
69
Justin Lebar8650a4d2016-04-15 01:38:48 +000070unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
71 return TTIImpl->getInliningThresholdMultiplier();
72}
73
Chandler Carruth93205eb2015-08-05 18:08:10 +000074int TargetTransformInfo::getIntrinsicCost(
75 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
76 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
77 assert(Cost >= 0 && "TTI should not produce negative costs!");
78 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000079}
80
Chandler Carruth93205eb2015-08-05 18:08:10 +000081int TargetTransformInfo::getUserCost(const User *U) const {
82 int Cost = TTIImpl->getUserCost(U);
83 assert(Cost >= 0 && "TTI should not produce negative costs!");
84 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000085}
86
Tom Stellard8b1e0212013-07-27 00:01:07 +000087bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000088 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000089}
90
Jingyue Wu5da831c2015-04-10 05:03:50 +000091bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
92 return TTIImpl->isSourceOfDivergence(V);
93}
94
Chandler Carruth0ba8db42013-01-22 11:26:02 +000095bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +000096 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +000097}
98
Chandler Carruth705b1852015-01-31 03:43:40 +000099void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +0000100 Loop *L, UnrollingPreferences &UP) const {
101 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000102}
103
Chandler Carruth539edf42013-01-05 11:43:11 +0000104bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000105 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000106}
107
108bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000109 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000110}
111
112bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
113 int64_t BaseOffset,
114 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000115 int64_t Scale,
116 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000117 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000118 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000119}
120
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000121bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
122 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000123}
124
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000125bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
126 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000127}
128
Elena Demikhovsky09285852015-10-25 15:37:55 +0000129bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
130 return TTIImpl->isLegalMaskedGather(DataType);
131}
132
133bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
134 return TTIImpl->isLegalMaskedGather(DataType);
135}
136
Quentin Colombetbf490d42013-05-31 21:29:03 +0000137int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
138 int64_t BaseOffset,
139 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000140 int64_t Scale,
141 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000142 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
143 Scale, AddrSpace);
144 assert(Cost >= 0 && "TTI should not produce negative costs!");
145 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000146}
147
Chandler Carruth539edf42013-01-05 11:43:11 +0000148bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000149 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000150}
151
Chad Rosier54390052015-02-23 19:15:16 +0000152bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
153 return TTIImpl->isProfitableToHoist(I);
154}
155
Chandler Carruth539edf42013-01-05 11:43:11 +0000156bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000157 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000158}
159
160unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000161 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000162}
163
164unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000165 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000166}
167
168bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000169 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000170}
171
Olivier Sallenave049d8032015-03-06 23:12:04 +0000172bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
173 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
174}
175
Silviu Baranga61bdc512015-08-10 14:50:54 +0000176bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
177 return TTIImpl->enableInterleavedAccessVectorization();
178}
179
Renato Golin5cb666a2016-04-14 20:42:18 +0000180bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
181 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
182}
183
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000184TargetTransformInfo::PopcntSupportKind
185TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000186 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000187}
188
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000189bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000190 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000191}
192
Chandler Carruth93205eb2015-08-05 18:08:10 +0000193int TargetTransformInfo::getFPOpCost(Type *Ty) const {
194 int Cost = TTIImpl->getFPOpCost(Ty);
195 assert(Cost >= 0 && "TTI should not produce negative costs!");
196 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000197}
198
Chandler Carruth93205eb2015-08-05 18:08:10 +0000199int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
200 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
201 assert(Cost >= 0 && "TTI should not produce negative costs!");
202 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000203}
204
Chandler Carruth93205eb2015-08-05 18:08:10 +0000205int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
206 const APInt &Imm, Type *Ty) const {
207 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
208 assert(Cost >= 0 && "TTI should not produce negative costs!");
209 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000210}
211
Chandler Carruth93205eb2015-08-05 18:08:10 +0000212int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
213 const APInt &Imm, Type *Ty) const {
214 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
215 assert(Cost >= 0 && "TTI should not produce negative costs!");
216 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000217}
218
Chandler Carruth539edf42013-01-05 11:43:11 +0000219unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000220 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000221}
222
Nadav Rotemb1791a72013-01-09 22:29:00 +0000223unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000224 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000225}
226
Matt Arsenault8dad57c2016-06-16 21:43:12 +0000227unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
228 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
229}
230
Adam Nemetaf761102016-01-21 18:28:36 +0000231unsigned TargetTransformInfo::getCacheLineSize() const {
232 return TTIImpl->getCacheLineSize();
233}
234
Adam Nemetdadfbb52016-01-27 22:21:25 +0000235unsigned TargetTransformInfo::getPrefetchDistance() const {
236 return TTIImpl->getPrefetchDistance();
237}
238
Adam Nemet6d8beec2016-03-18 00:27:38 +0000239unsigned TargetTransformInfo::getMinPrefetchStride() const {
240 return TTIImpl->getMinPrefetchStride();
241}
242
Adam Nemet709e3042016-03-18 00:27:43 +0000243unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
244 return TTIImpl->getMaxPrefetchIterationsAhead();
245}
246
Wei Mi062c7442015-05-06 17:12:25 +0000247unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
248 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000249}
250
Chandler Carruth93205eb2015-08-05 18:08:10 +0000251int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000252 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
253 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000254 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000255 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
256 Opd1PropInfo, Opd2PropInfo);
257 assert(Cost >= 0 && "TTI should not produce negative costs!");
258 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000259}
260
Chandler Carruth93205eb2015-08-05 18:08:10 +0000261int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
262 Type *SubTp) const {
263 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
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::getCastInstrCost(unsigned Opcode, Type *Dst,
269 Type *Src) const {
270 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
271 assert(Cost >= 0 && "TTI should not produce negative costs!");
272 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000273}
274
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000275int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
276 VectorType *VecTy,
277 unsigned Index) const {
278 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
279 assert(Cost >= 0 && "TTI should not produce negative costs!");
280 return Cost;
281}
282
Chandler Carruth93205eb2015-08-05 18:08:10 +0000283int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
284 int Cost = TTIImpl->getCFInstrCost(Opcode);
285 assert(Cost >= 0 && "TTI should not produce negative costs!");
286 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000287}
288
Chandler Carruth93205eb2015-08-05 18:08:10 +0000289int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
290 Type *CondTy) const {
291 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
292 assert(Cost >= 0 && "TTI should not produce negative costs!");
293 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000294}
295
Chandler Carruth93205eb2015-08-05 18:08:10 +0000296int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
297 unsigned Index) const {
298 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
299 assert(Cost >= 0 && "TTI should not produce negative costs!");
300 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000301}
302
Chandler Carruth93205eb2015-08-05 18:08:10 +0000303int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
304 unsigned Alignment,
305 unsigned AddressSpace) const {
306 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
307 assert(Cost >= 0 && "TTI should not produce negative costs!");
308 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000309}
310
Chandler Carruth93205eb2015-08-05 18:08:10 +0000311int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
312 unsigned Alignment,
313 unsigned AddressSpace) const {
314 int Cost =
315 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
316 assert(Cost >= 0 && "TTI should not produce negative costs!");
317 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000318}
319
Elena Demikhovsky54946982015-12-28 20:10:59 +0000320int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
321 Value *Ptr, bool VariableMask,
322 unsigned Alignment) const {
323 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
324 Alignment);
325 assert(Cost >= 0 && "TTI should not produce negative costs!");
326 return Cost;
327}
328
Chandler Carruth93205eb2015-08-05 18:08:10 +0000329int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000330 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
331 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000332 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
333 Alignment, AddressSpace);
334 assert(Cost >= 0 && "TTI should not produce negative costs!");
335 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000336}
337
Chandler Carruth93205eb2015-08-05 18:08:10 +0000338int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000339 ArrayRef<Type *> Tys,
340 FastMathFlags FMF) const {
341 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000342 assert(Cost >= 0 && "TTI should not produce negative costs!");
343 return Cost;
344}
345
Elena Demikhovsky54946982015-12-28 20:10:59 +0000346int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000347 ArrayRef<Value *> Args,
348 FastMathFlags FMF) const {
349 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000350 assert(Cost >= 0 && "TTI should not produce negative costs!");
351 return Cost;
352}
353
Chandler Carruth93205eb2015-08-05 18:08:10 +0000354int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
355 ArrayRef<Type *> Tys) const {
356 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
357 assert(Cost >= 0 && "TTI should not produce negative costs!");
358 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000359}
360
Chandler Carruth539edf42013-01-05 11:43:11 +0000361unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000362 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000363}
364
Chandler Carruth93205eb2015-08-05 18:08:10 +0000365int TargetTransformInfo::getAddressComputationCost(Type *Tp,
366 bool IsComplex) const {
367 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
368 assert(Cost >= 0 && "TTI should not produce negative costs!");
369 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000370}
Chandler Carruth539edf42013-01-05 11:43:11 +0000371
Chandler Carruth93205eb2015-08-05 18:08:10 +0000372int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
373 bool IsPairwiseForm) const {
374 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
375 assert(Cost >= 0 && "TTI should not produce negative costs!");
376 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000377}
378
Chandler Carruth705b1852015-01-31 03:43:40 +0000379unsigned
380TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
381 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000382}
383
384bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
385 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000386 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000387}
388
Chandler Carruth705b1852015-01-31 03:43:40 +0000389Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
390 IntrinsicInst *Inst, Type *ExpectedType) const {
391 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
392}
393
Eric Christopherd566fb12015-07-29 22:09:48 +0000394bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
395 const Function *Callee) const {
396 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000397}
398
Chandler Carruth705b1852015-01-31 03:43:40 +0000399TargetTransformInfo::Concept::~Concept() {}
400
Chandler Carruthe0385522015-02-01 10:11:22 +0000401TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
402
403TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000404 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000405 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000406
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000407TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000408 return TTICallback(F);
409}
410
Chandler Carruthb4faf132016-03-11 10:22:49 +0000411char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000412
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000413TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000414 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000415}
416
Chandler Carruth705b1852015-01-31 03:43:40 +0000417// Register the basic pass.
418INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
419 "Target Transform Information", false, true)
420char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000421
Chandler Carruth705b1852015-01-31 03:43:40 +0000422void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000423
Chandler Carruth705b1852015-01-31 03:43:40 +0000424TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000425 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000426 initializeTargetTransformInfoWrapperPassPass(
427 *PassRegistry::getPassRegistry());
428}
429
430TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000431 TargetIRAnalysis TIRA)
432 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000433 initializeTargetTransformInfoWrapperPassPass(
434 *PassRegistry::getPassRegistry());
435}
436
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000437TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000438 TTI = TIRA.run(F);
439 return *TTI;
440}
441
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000442ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000443llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
444 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000445}